0

When I created new project I went to Solution Explorer and in Properties I double clicked on Resources.resx. Here I clicked on Add Resource and Add Existing File. Selected images been added and I can use them for darg&drop on form.
My problem is I need to create sort of rollover effect on pictureBox. PictureBox image property is set to none for start. When I go with mouse over pictureBox I want to upload image from resources. How do I do it?

pictureBox.Image = ? ? ? ? ?

PS: Any good place with C# tutorials?

4
Contributors
7
Replies
19
Views
9 Years
Discussion Span
Last Post by kkais
0

OK no error after that, but once I get mouse over pictureBox image is not uploaded. Did I forgot somethink like Paint? I wish they library system was more like Java API...

1

In pictureBox event handler (MouseOver) assign the picturebox.image to the image which in resources. It works!

Votes + Comments
Thank you for help
0

You have to be a little slow when moving your mouse over the picturebox. If you want precision movement try considering writing code in the MouseEnter, MouseLeave event handlers.

Thanks,
Peter Pollen <advertising url snipped>

0

I forgot to attach silly event handler :$

For anybody who wish to generate 2D array of pictureBoxes on runtime here is code snipped for it

for (int x = 0; x < stonePlaced.GetUpperBound(0); x++)
{
	for (int y = 0; y < stonePlaced.GetUpperBound(1); y++)
		{
			stonePlaced[x, y] = new PictureBox();
			stonePlaced[x, y].Size = new Size(80, 80);
			stonePlaced[x, y].Location = new Point((80 * x),(80 * y));
			stonePlaced[x, y].BackColor = 
                                   System.Drawing.Color.Transparent;
			stonePlaced[x, y].MouseHover += 
                                   new System.EventHandler(this.stonePlaced_MouseHover);
			stonePlaced[x, y].MouseLeave += 
                                  new System.EventHandler(this.stonePlaced_MouseLeave);
			boardPanel.Controls.Add(stonePlaced[x, y]);
		}
}

And event listeners

private void stonePlaced_MouseHover(object sender, EventArgs e)
{
	PictureBox pb;
	pb = (PictureBox)sender;
        pb.Image = Properties.Resources.purple;
}

private void stonePlaced_MouseLeave(object sender, EventArgs e)
{
	PictureBox pb;
	pb = (PictureBox)sender;
	pb.Image = null;
}
0

When I created new project I went to Solution Explorer and in Properties I double clicked on Resources.resx. Here I clicked on Add Resource and Add Existing File. Selected images been added and I can use them for darg&drop on form.
My problem is I need to create sort of rollover effect on pictureBox. PictureBox image property is set to none for start. When I go with mouse over pictureBox I want to upload image from resources. How do I do it?

pictureBox.Image = RiskIT.Properties.Resources._1

PS: Any good place with C# tutorials?

pictureBox.Image = RiskIT.Properties.Resources._1
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.