Reputation: 41
I am trying to code a drag and drop system with pictureboxes. I did this earlier, except this time, I created the pictureboxes by code and not in the designer.
DASporter dasporter = new DASporter();
List<int> landids = dasporter.getLandenBySport(1);
DALand daland = new DALand();
Land land = null;
PictureBox[] landenfotos = new PictureBox[landids.Count];
int teller = 80;
for (int i = 0; i <= landids.Count - 1; i++)
{
land = daland.getLand(landids[i]);
landenfotos[i] = new PictureBox();
landenfotos[i].Name = "Picturebox" + land.Id.ToString();
landenfotos[i].Location = new Point(70, teller);
landenfotos[i].Tag = land.Naam;
landenfotos[i].Size = new Size(70, 70);
landenfotos[i].Image = Image.FromFile("images/" + land.Vlag);
landenfotos[i].SizeMode = PictureBoxSizeMode.Zoom;
this.Controls.Add(landenfotos[i]);
teller += 60;
}
If you create them in the designer, you can use the eventmanager to search the right event. Now, I can't use this so i need an alternative.
Anyone who had this problem too and got it solved? I can't find a solution anywhere.
Upvotes: 0
Views: 129
Reputation: 112352
You can add event handlers easily by typing
landenfotos[i].MouseMove +=<Tab><Tab>
Pressing <Tab>
twice after +=
will create an event handler automatically.
It will complete the line to
landenfotos[i].MouseMove += new MouseEventHandler(SomeMethodName_MouseMove);
and add the method
void SomeMethodName_MouseMove(object sender, MouseEventArgs e)
{
throw new NotImplementedException();
}
And of course Intellisense will show you all the available events to choose from :-)
Upvotes: 1