我在Windows窗体上创建了一些省略号
我希望鼠标悬停时可以选择,如果我选择任何椭圆,它将从Window中删除
这里有一些用于在c#
中创建椭圆的代码public void DrawCircle_Paint(object sender, PaintEventArgs e)
{
Pen pen = new Pen(Color.Black, 3); Graphics gr = this.CreateGraphics(); gr.DrawEllipse(pen, 40, 45, 20, 20);
Pen pen2 = new Pen(Color.Black, 3); Graphics gr1 = this.CreateGraphics(); gr.DrawEllipse(pen2, 30, 25, 38, 20);
Pen pen3 = new Pen(Color.Black, 3); Graphics gr2 = this.CreateGraphics(); gr.DrawEllipse(pen3, 35, 36, 68, 15);
Pen pen4 = new Pen(Color.Black, 3); Graphics gr3 = this.CreateGraphics(); gr.DrawEllipse(pen4, 50, 60, 67, 35);
}
答案 0 :(得分:0)
您可以使用
this.Invalidate();
那应该清除它们......
要么是,要么
Graphics.Clear();
编辑:
实际上,另一种方法是在鼠标悬停时使用布尔值,并使用它来决定何时绘制elipse / not。作为一般说明,您应该将elipse绘图重写为onpaint。目前,如果您要使屏幕无效(由您或Windows),您的形状将消失。一个使用油漆的例子。
bool paint = false;
protected override void OnPaint(object sender, PaintEventArgs e)
{
if (paint)
{
Pen pen = new Pen(Color.Black, 3); Graphics gr = this.CreateGraphics(); gr.DrawEllipse(pen, 40, 45, 20, 20);
Pen pen2 = new Pen(Color.Black, 3); Graphics gr1 = this.CreateGraphics(); gr.DrawEllipse(pen2, 30, 25, 38, 20);
Pen pen3 = new Pen(Color.Black, 3); Graphics gr2 = this.CreateGraphics(); gr.DrawEllipse(pen3, 35, 36, 68, 15);
Pen pen4 = new Pen(Color.Black, 3); Graphics gr3 = this.CreateGraphics(); gr.DrawEllipse(pen4, 50, 60, 67, 35);
}
}
我不记得它的具体参数,但在你的OnMouseHover中(你要关掉你的椭圆)
OnMouseHover(){
...
paint = false;
this.Invalidate();
}