I'm trying to create a media player that can load MULTIPLE CLIPS at a time.
Just load. Not play.
When you load the program, I was hoping that the user can click "load" and select different files for each of the buttons.
Once the clips have all been loaded, the user can go through and click a "play" button that corresponds with the Load Button.
I also hoped that beside each "play" button, there be a Loop Checkbox (if ticked, it loops the video)
The Program so far:
Current Source:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MediaPlayer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
MediaPly _mp = null;
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
_mp = new MediaPly();
}
}
private void button2_Click(object sender, EventArgs e)
{
_mp.LoadFile(openFileDialog1.FileName, this.panel1);
}
private void button3_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
_mp = new MediaPly();
}
}
private void button4_Click(object sender, EventArgs e)
{
_mp.LoadFile(openFileDialog1.FileName, this.panel1);
}
private void button5_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
_mp = new MediaPly();
}
}
private void button6_Click(object sender, EventArgs e)
{
_mp.LoadFile(openFileDialog1.FileName, this.panel1);
}
}
}
You are saving all clips to the same variable (_mp).
Try to save each in a different variable:
MediaPly _mp = null;
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
_mp = new MediaPly();
}
}
private void button2_Click(object sender, EventArgs e)
{
_mp.LoadFile(openFileDialog1.FileName, this.panel1);
}
MediaPly _mp2 = null;
private void button3_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
_mp2 = new MediaPly();
}
}
private void button4_Click(object sender, EventArgs e)
{
_mp2.LoadFile(openFileDialog1.FileName, this.panel1);
}
MediaPly _mp3 = null;
private void button5_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
_mp3 = new MediaPly();
}
}
private void button6_Click(object sender, EventArgs e)
{
_mp3.LoadFile(openFileDialog1.FileName, this.panel1);
}
Related
So, i try to learn how to Drag and Drop an Image from one PictureBox to another and that works well. But how can i drag and drop the Image TAG from pictureox1 to picturebox2?
i currently have 3 source images and 3 drop boxes.
the dropbox6 is locked with a countdown after a buttonclick (see button2)
(later i will lock all dropboxes)
after i hit this button a countdown starts and if the countdown is 0 (ZERO) only then i can drag one of the 3 images to this box.
however, i have given each of these 3 images in the souceboxes a TAG name.
how can i drop this tagname also to the dropbox?
here is what i have so far:
(the Label labeled "Counter" is actually Label4 in the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Game
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
// pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
((PictureBox)sender).DoDragDrop(((PictureBox)sender).Image, DragDropEffects.Copy);
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox4.AllowDrop = true;
pictureBox5.AllowDrop = true;
pictureBox6.AllowDrop = true;
pictureBox6.Enabled = false;
}
private void pictureBox4_DragEnter(object sender, DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;
}
}
private void pictureBox4_DragLeave(object sender, EventArgs e)
{
}
private void pictureBox4_DragDrop(object sender, DragEventArgs e)
{
Image getPicture = (Bitmap) e.Data.GetData(DataFormats.Bitmap);
pictureBox4.Image = getPicture;
}
private void pictureBox5_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;
}
}
private void pictureBox5_DragLeave(object sender, EventArgs e)
{
}
private void pictureBox5_DragDrop(object sender, DragEventArgs e)
{
Image getPicture = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
pictureBox5.Image = getPicture;
}
private void pictureBox6_DragDrop(object sender, DragEventArgs e)
{
Image getPicture = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
pictureBox6.Image = getPicture;
timer1.Enabled = false;
}
private void pictureBox6_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;
timer1.Enabled = false;
}
}
private void pictureBox6_DragLeave(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void pictureBox4_Click(object sender, EventArgs e)
{
MessageBox.Show("test");
}
private void timer1_Tick(object sender, EventArgs e)
{
counter--;
if (counter == 0)
timer1.Stop();
label4.Text = counter.ToString();
if(counter == 0)
{
pictureBox6.Enabled = true;
label4.Enabled = false;
timer1.Stop();
}
}
private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}
private void pictureBox6_Click(object sender, EventArgs e)
{
MessageBox.Show(pictureBox6.Tag.ToString());
}
private int counter = 3;
private void button2_Click(object sender, EventArgs e)
{
int counter = 3;
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000; // 1 second
timer1.Start();
label4.Text = counter.ToString();
if(label4.Text == "0")
{
timer1.Stop();
}
pictureBox6.Image = Properties.Resources.shoreSite_d_1_l_x_x;
button2.Visible=false;
}
}
internal class bild1
{
private Bitmap shoreSite_d_1_l_x_x;
public bild1(Bitmap shoreSite_d_1_l_x_x)
{
this.shoreSite_d_1_l_x_x = shoreSite_d_1_l_x_x;
}
}
}
In MouseDown you are saying what you want to transmit in the DoDragDrop call. In your current case you are transmitting the image ((PictureBox)sender).Image but you can chose to transmit the tag as well...
private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
((PictureBox)sender).DoDragDrop(((PictureBox)sender).Image, DragDropEffects.Copy);
((PictureBox)sender).DoDragDrop(((PictureBox)sender).Tag, DragDropEffects.Copy);
}
...Then make sure to parse for each possible input type in DragDrop
private void pictureBox6_DragDrop(object sender, DragEventArgs e)
{
var image = e.Data.GetData(DataFormats.Bitmap) as Bitmap;
var tag = e.Data.GetData(DataFormats.Text) as string;
if (image != null)
{
pictureBox4.Image = image;
}
if (tag != null)
{
pictureBox4.Tag = tag;
}
timer1.Enabled = false;
}
Beware, that you will need to update all the code that checks that the data is Bitmap before it arrives at DragDrop ie in DragEnter and write code that handles both Bitmap and Text, otherwise the Drag functionality will break.
AWESOME!!
It works now. I will continue this Project.
I am trying to make a small program to duplicate one file "X" (user input) times. So i created this windows forms app
I am not sure how to write the code for the Start button where I can say File.Copy the specific file 1000 times let's say and save them in the desired folder.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
tbAlegefisierul.Text = openFileDialog1.FileName;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void lbAlegeFisierul_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnSalveaza_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{tbSalveaza.Text = Path.Combine(folderBrowserDialog1.SelectedPath); }
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{
}
private void btnStart_Click(object sender, EventArgs e)
{
File.Copy(tbAlegefisierul.Text, tbSalveaza.Text, true);
MessageBox.Show("Ai copiat cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void tbnrori_TextChanged(object sender, EventArgs e)
{
}
}
You probably need something like this:
private string _fileName = null;
private string _selectedPath = null;
private int? _nrori = null;
private void UpdateStartButton()
{
btnStart.Enabled =
File.Exists(_fileName)
&& Directory.Exists(_selectedPath)
&& _nrori.HasValue
&& _nrori.Value > 0;
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
tbAlegefisierul.Text = openFileDialog1.FileName;
_fileName = openFileDialog1.FileName;
this.UpdateStartButton();
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.UpdateStartButton();
}
private void btnSalveaza_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
tbSalveaza.Text = folderBrowserDialog1.SelectedPath;
_selectedPath = folderBrowserDialog1.SelectedPath;
this.UpdateStartButton();
}
}
private void btnStart_Click(object sender, EventArgs e)
{
for (int i = 0; i < _nrori.Value; i++)
{
var destinationFileName = Path.Combine(_selectedPath, $"{Path.GetFileNameWithoutExtension(_fileName)} ({i + 1}){Path.GetExtension(_fileName)}");
File.Copy(_fileName, destinationFileName, true);
}
MessageBox.Show("Ai copiat cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void tbnrori_TextChanged(object sender, EventArgs e)
{
_nrori = int.TryParse(tbnrori.Text, out int n) ? (int?)n : null;
this.UpdateStartButton();
}
I build a project in C# with which one can control a RGB led. My goal is to build a function in which one can upload code that controls the LED. Therefore I need help with the following proble :
There is a button and a rich text box on the form. The text of the rich text box contains source code, which should get uploaded to the arduino if you press the button. I know how to open the port but i dont know how to upload the source code.
My code :
namespace RGBLedColorPicker
{
public partial class Form1 : Form
{
SerialPort port = new SerialPort("COM3", 9600);
private Color defaultColor = Color.FromArgb(0, 0, 0);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
port.Open();
this.SetColor(defaultColor);
}
catch
{
MessageBox.Show("Cant find Arduino.Closing programm");
Application.Exit();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.SetColor(defaultColor);
port.Close();
}
private void panel1_Click(object sender, EventArgs e)
{
}
private void SetColor(Color color)
{
port.Write(new[] { color.R, color.G, color.B }, 0, 3);
}
private void button1_Click(object sender, EventArgs e)
{
this.SetColor(Color.Red);
}
private void button2_Click(object sender, EventArgs e)
{
this.SetColor(Color.Green);
}
private void button3_Click(object sender, EventArgs e)
{
this.SetColor(Color.Blue);
}
private void button4_Click(object sender, EventArgs e)
{
this.SetColor(Color.Red);
Thread.Sleep(2000);
this.SetColor(Color.Green);
Thread.Sleep(2000);
this.SetColor(Color.Blue);
Thread.Sleep(2000);
MessageBox.Show("Show beendet","beendet",MessageBoxButtons.OK);
this.SetColor(defaultColor);
}
private void button5_Click(object sender, EventArgs e)
{
using (Create f2 = new Create())
{
f2.ShowDialog(this);
}
}
private void button6_Click(object sender, EventArgs e)
{
this.SetColor(defaultColor);
}
private void button7_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
SetColor(colorDialog1.Color);
}
}
}
}
I am creating a To Do List using Windows Forms.
This is what I have so far.
The code for this form is as follows
namespace To_Do_List
{
public partial class To_Do_List : Form
{
public To_Do_List()
{
InitializeComponent();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) //this is the exit button on the toolstrip
{
Application.Exit(); //exits the program when the Exit button is clicked in dropdown menu
}
private void button4_Click(object sender, EventArgs e)//This creates the button to open the about form
{
AboutMyProgram aboutForm = new AboutMyProgram();
aboutForm.ShowDialog(); //opens about form
}
private void button3_Click(object sender, EventArgs e) //This creates the button to open the form which ammends tasks
{
AmmendItem CreateForm = new AmmendItem(this);
CreateForm.Show();
}
private void button1_Click(object sender, EventArgs e) // This creates the button to open the form which creates new tasks
{
AddItem CreateForm = new AddItem(this);
CreateForm.Show();
}
public void listView1_SelectedIndexChanged_1(object sender, EventArgs e) // This creates the table
{
}
private void button2_Click(object sender, EventArgs e) //This Allows the user to delete entries
{
if (listView1.SelectedItems != null)
{
var confirmation = MessageBox.Show(
"Are you sure you want to delete this?",
"WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Question
);
if (confirmation == DialogResult.Yes)
{
for (int i = listView1.Items.Count - 1; i >= 0; i--)
{
if (listView1.Items[i].Selected)
{
listView1.Items[i].Remove();
i--;
}
}
}
}
}
}
}
To add a task, the form looks like this
And again, the code is as follows
namespace To_Do_List
{
public partial class AddItem : Form
{
To_Do_List home;
public AddItem(To_Do_List parent)
{
InitializeComponent();
home = parent;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label1_Click_1(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void openListToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void sortByDateToolStripMenuItem_Click(object sender, EventArgs e)
{
}
public void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
public void textBox1_TextChanged(object sender, EventArgs e)//Title Box
{
}
public void /*Description of Task*/richTextBox1_TextChanged(object sender, EventArgs e)
{
}
public void /*Priority Box*/comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close(); //causes the window to close but keeps the application running
}
private void aboutToDoListToolStripMenuItem_Click(object sender, EventArgs e)
{
AboutMyProgram aboutForm = new AboutMyProgram();
aboutForm.ShowDialog(); //opens about form displaying copyright information
}
public void button1_Click(object sender, EventArgs e) //create task button
{
ListViewItem item1 = new ListViewItem(Title.Text);
item1.SubItems.Add(Description.Text);
item1.SubItems.Add(Priority.Text);
item1.SubItems.Add(Date.Text);
string value = "";
bool isChecked = Completed.Checked;
if (isChecked)
item1.SubItems.Add(Completed.Text);
else
value = null;
home.listView1.Items.Add(item1);
this.Close();
}
private void Date_ValueChanged(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e) //Closes the window
{
this.Close();
}
}
}
The Amend form is exactly the same as the New Task form. How would I go about being able to select a record, pressing the amend button and actually changing?
I'm pretty stumped.
Also, this isn't really part of this question but I'll ask it just in case someone knows.
How would I go about being able to actually save these records so that they are there when I open the application back up again?
Thank you very much for reading, I know that I have just dumped everything but I'm really new to Windows Forms so I didn't want to accidentally miss something important out.
Edit
Am I on the right road with something like this?
public void button1_Click(object sender, EventArgs e)
{
To_Do_List editform = new To_Do_List(Title.Text);
editform.Description.Text = listView1.SelectedItems[0].SubItems[0].Text;
Still can't get it to work :/
This code for popup window.
public partial class frmToDoDetails : Form
{
public string TaskTitle { get; set; }
public string Description { get; set; }
public bool EditMode { get; set; }
public frmToDoDetails()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
TaskTitle = txtTitle.Text;
Description = txtDesc.Text;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
private void frmToDoDetails_Load(object sender, EventArgs e)
{
if (EditMode)
{
txtTitle.Text = TaskTitle;
txtDesc.Text = Description;
}
else {
txtTitle.Text = string.Empty;
txtDesc.Text = string.Empty;
}
txtTitle.Focus();
}
}
And this for list
public partial class frmToDo : Form
{
public frmToDo()
{
InitializeComponent();
}
private void btnNew_Click(object sender, EventArgs e)
{
frmToDoDetails frm = new frmToDoDetails();
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] arr = new string[2];
ListViewItem itm;
arr[0] = frm.TaskTitle;
arr[1] = frm.Description;
itm = new ListViewItem(arr);
listView1.Items.Add(itm);
}
}
private void frmToDo_Load(object sender, EventArgs e)
{
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
//Add column header
listView1.Columns.Add("Title", 100);
listView1.Columns.Add("Desc", 70);
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
ListViewItem currentItem= listView1.SelectedItems[0];
frmToDoDetails frm = new frmToDoDetails();
frm.TaskTitle = currentItem.SubItems[0].Text;
frm.Description = currentItem.SubItems[1].Text;
frm.EditMode = true;
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
currentItem.SubItems[0].Text=frm.TaskTitle;
currentItem.SubItems[1].Text=frm.Description;
}
}
}
I am not added your complete fields(priority, date,etc..).
I hope it will help you.
I greatly appreciate any help. I have 20+ buttons, each with a word, or a space or period. Each time I click on a button, the pre-existing word is wiped out and replaced with the new word. I need each word and/or space to remain in place until I click the "Clear" button.
Maybe this has been previously asked/answered under different search terms? I tend to believe I need to identify a string variable, but have no idea how to begin.
==============
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class frmSentenceBuilder : Form
{
public frmSentenceBuilder()
{
InitializeComponent();
}
private void frmSentenceBuilder_Load(object sender, EventArgs e)
{
}
private void btnA_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnA.Text;
}
private void btn_a_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btn_a.Text;
}
private void btnAn_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnAn.Text;
}
private void btn_an_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btn_an.Text;
}
private void btnThe_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnThe.Text;
}
private void btn_the_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btn_the.Text;
}
private void btnman_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnman.Text;
}
private void btnwoman_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnwoman.Text;
}
private void btndog_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btndog.Text;
}
private void btncat_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btncat.Text;
}
private void btncar_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btncar.Text;
}
private void btnbicycle_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnbicycle.Text;
}
private void btnbeautiful_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnbeautiful.Text;
}
private void btnbig_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnbig.Text;
}
private void btnsmall_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnsmall.Text;
}
private void btnstrange_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnstrange.Text;
}
private void btnlookedat_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnlookedat.Text;
}
private void btnrode_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnrode.Text;
}
private void btnspoketo_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnspoketo.Text;
}
private void btnlaughedat_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnlaughedat.Text;
}
private void btndrove_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btndrove.Text;
}
private void btnSpace_Click(object sender, EventArgs e)
{
lblSentenceText.Text = " ";
}
private void btnperiod_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnperiod.Text;
}
private void btnexclam_Click(object sender, EventArgs e)
{
lblSentenceText.Text = btnexclam.Text;
}
private void btnClear_Click(object sender, EventArgs e)
{
lblSentenceText.Text = "";
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Use lb1SentenceText.Text+=whatever.Text;.
+= is equivalent to lbSentence.Text = lblSentenceText.Text + whatever.Text.
Basically, it appends or concatenates the right hand side string to the string on the left hand side. Hope it makes sense?
So:
string rhs="Hello " ;
string lhs = "World";
string rhs = rhs + lhs;//Hello World
Please be inspired. You have a lot of redundant code.
btnA.Click += AppendButtonText;
btn_a.Click += AppendButtonText;
...
private void AppendButtonText(object sender, EventArgs e)
{
var button = sender as Button;
if (button != null)
{
lblSentenceText.Text += button.Text;
}
}
On the button click events, change it to += instead of = (except in the clear button). This is equivalent to writing something = something + newValue;.
Try:
lb1SentenceText.Text = lb1SentenceText.Text + *something*.text
The += operator means add to, and the variable modified is equal to the added (Int, String) appended to the original value (x = 1; x += 3; x is now 4)
Try this:
button.Click += new System.EventHandler(ButtonClick);
button1.Click += new System.EventHandler(ButtonClick);
// And for each button, one of those.
private void ButtonClick(object sender, System.EventArgs e)
{
// Do whatever you want to do here, you can place the TEXT to be appended on the button, if so:
lb1SentenceText.Text += sender.Text;
}
//Simple.Create a global variable and within each button click event do this;
string yourStrVar = ""; //Must be global
yourStrVar+= ((Button)sender).Text