如何设置图片的选择框,有代码,请指正
private void picfortype_Click(object sender, EventArgs e)
{
Image imge = ((PictureBox)sender).Image;
Image imge = ((PictureBox)sender).Image;
int newheight = imge.Height;
int newwidth = imge.Width;
Pen myPen = new Pen(Brushes.Black, 2);
myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
Bitmap bmp = new Bitmap(newwidth, newheight);
Graphics g = Graphics.FromImage(bmp);
Rectangle rec = new Rectangle(0, 0, newwidth, newheight);
g.DrawImage(imge, rec, 0, 0, imge.Width, imge.Height, GraphicsUnit.Pixel);
g.DrawRectangle(myPen, 0, 0, newwidth, newheight);
((PictureBox)sender).Image = bmp;
//pictureBox1.Image = bmp;
//textBox1.Text = ((PictureBox)sender).Tag.ToString();
}
这个是picturebox的单击事件
我的目的:我已经在tabcontrol的tabpage里面动态生成了几个picturebox控件,也加载好了图片。
现在我点击每个图片,需要在当前点击的图片加一个边框,代表选中的意思。
以上代码已经实现了增加边框,但是我点每个图片都加了边框
我是想只让我当前点击的有边框,当我点击下一个图片的时候,点击的目标有边框,前面的有边框的取消。意思就是不论多少个图片,当前只能有一个有边框
------解决方案--------------------private PictureBox picPrev=null; //上一次加边框的图片控件
private Image imgPrev=null; //上一次图片控件的图片
private void picfortype_Click(object sender, EventArgs e)
{
Image imge = ((PictureBox)sender).Image;
Image imge = ((PictureBox)sender).Image;
int newheight = imge.Height;
int newwidth = imge.Width;
Pen myPen = new Pen(Brushes.Black, 2);
&n