I'm a beginner in C# Windows Forms. I tried to google this but not sure I understand how this is possible. I want to create a Listbox under run time, and succed making one like this:
private void button3_Click(object sender, EventArgs e)
{
ListBox lb = new ListBox();
lb.AllowDrop = true;
lb.FormattingEnabled = true;
lb.Size = new System.Drawing.Size(200, 100);
lb.Location = new System.Drawing.Point(100, 250);
this.Controls.Add(lb);
}
But I also need conditions in a function for my listbox, I want to add code in designer to add these too to the listbox. I want to add a function like this for example:
lb.DragEnter += new System.Windows.Forms.DragEventHandler(this.lb_DragEnter);
and
private void lb_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(System.String)))
e.Effect = DragDropEffects.Move;
else
e.Effect = DragDropEffects.None;
}
I hope i explain my problem clear!