Tom Knowlton
asked on
PictureBox MouseHover
When I hover over a Picture Box control.....I want to change the border or something.....to indicate visually to the end-user that they are "selecting" the item if they click on it.
Suggestions?
Suggestions?
ASKER
Okay.....I've refined it a little bit.......but it is slow.....and seems to not always fire correctly......meaning.... I'll leave a picturebox control and the MouseLeave event does not fire and leaves the border style as FixedSingle instead of changing back to None:
public void InitPictureBoxArray()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
pBoxArray[i,j] = new System.Windows.Forms.Pictu reBox();
pBoxArray[i,j].Image = gw.gamePieceArray[i,j].pic _box.Image ;
pBoxArray[i,j].Location=ne w Point(i*33,j*33);
pBoxArray[i,j].Size=new Size(32,32);
pBoxArray[i,j].Tag=new Point(i,j);
pBoxArray[i,j].Click += new System.EventHandler(pictur eClick);
pBoxArray[i,j].MouseEnter += new System.EventHandler(pictur eMouseEnte r);
pBoxArray[i,j].MouseLeave += new System.EventHandler(pictur eMouseLeav e);
this.Controls.Add(pBoxArra y[i,j]);
}
}
}
private void pictureClick(object sender, System.EventArgs e)
{
Point PointClicked;
PictureBox PicClicked;
PicClicked=(PictureBox)sen der;
PointClicked=(Point)PicCli cked.Tag;
}
private void pictureMouseEnter(object sender, System.EventArgs e)
{
System.Windows.Forms.Pictu reBox pBox = new System.Windows.Forms.Pictu reBox();
pBox = (PictureBox)sender;
pBox.BorderStyle = BorderStyle.FixedSingle;
}
private void pictureMouseLeave(object sender, System.EventArgs e)
{
System.Windows.Forms.Pictu reBox pBox = new System.Windows.Forms.Pictu reBox();
pBox = (PictureBox)sender;
pBox.BorderStyle = BorderStyle.None;
}
public void InitPictureBoxArray()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
pBoxArray[i,j] = new System.Windows.Forms.Pictu
pBoxArray[i,j].Image = gw.gamePieceArray[i,j].pic
pBoxArray[i,j].Location=ne
pBoxArray[i,j].Size=new Size(32,32);
pBoxArray[i,j].Tag=new Point(i,j);
pBoxArray[i,j].Click += new System.EventHandler(pictur
pBoxArray[i,j].MouseEnter += new System.EventHandler(pictur
pBoxArray[i,j].MouseLeave += new System.EventHandler(pictur
this.Controls.Add(pBoxArra
}
}
}
private void pictureClick(object sender, System.EventArgs e)
{
Point PointClicked;
PictureBox PicClicked;
PicClicked=(PictureBox)sen
PointClicked=(Point)PicCli
}
private void pictureMouseEnter(object sender, System.EventArgs e)
{
System.Windows.Forms.Pictu
pBox = (PictureBox)sender;
pBox.BorderStyle = BorderStyle.FixedSingle;
}
private void pictureMouseLeave(object sender, System.EventArgs e)
{
System.Windows.Forms.Pictu
pBox = (PictureBox)sender;
pBox.BorderStyle = BorderStyle.None;
}
>>Suggestions?
why not use a tooltip instead....
ToolTip t = new ToolTip();
t.SetToolTip(this.pBox, "This is a picture box that you can click");
why not use a tooltip instead....
ToolTip t = new ToolTip();
t.SetToolTip(this.pBox, "This is a picture box that you can click");
ASKER
I do not want to use a tooltip in this particular case.
The images are 32 x 32 squares. I want to highlight the squares with a box when the mouse enters the PictureBox control...and remove the box when the mouse leaves the PictureBox control.
The images are 32 x 32 squares. I want to highlight the squares with a box when the mouse enters the PictureBox control...and remove the box when the mouse leaves the PictureBox control.
ASKER
The code in my third posting above would be fine..........the only problem it has is it leaves the box there when I leave the PictureBox control instead of removing it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This helped....but still having trouble.
ASKER
private void pictureMouseHover(object sender, System.EventArgs e)
below....how do I cast sender to a PictureBox control and set the .BorderStyle to Fixed Single or None?
public void InitPictureBoxArray()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
pBoxArray[i,j] = new System.Windows.Forms.Pictu
pBoxArray[i,j].Image = gw.gamePieceArray[i,j].pic
pBoxArray[i,j].Location=ne
pBoxArray[i,j].Size=new Size(32,32);
pBoxArray[i,j].Tag=new Point(i,j);
pBoxArray[i,j].Click += new System.EventHandler(pictur
pBoxArray[i,j].MouseHover += new System.EventHandler(pictur
this.Controls.Add(pBoxArra
}
}
}
private void pictureClick(object sender, System.EventArgs e)
{
Point PointClicked;
PictureBox PicClicked;
PicClicked=(PictureBox)sen
PointClicked=(Point)PicCli
// gw.gamePieceArray[PointCli
//MessageBox.Show(PointCli
}
private void pictureMouseHover(object sender, System.EventArgs e)
{
}