Rectangle rect = new Rectangle(new Point(100, 100), new Size(100, 150));
GraphicsPath gp = new GraphicsPath();
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
X = e.X;
Y = e.Y;
Invalidate();
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = panel1.CreateGraphics();
g.SmoothingMode = SmoothingMode.HighQuality;
gp.AddLine(new Point(10, 10), new Point(100, 100)); gp.AddLine(new Point(100, 100),new Point(150, 90));
gp.AddLines(new Point[] { new Point(150, 70), new Point(100, 90), new Point(50, 160) });//(new Point(150, 90), new Size(120, 120), 0, 50);
gp.CloseAllFigures();
if (gp.IsVisible(X, Y))
{
g.FillPath(Brushes.Red, gp);
}
else
{
g.FillPath(Brushes.DeepSkyBlue, gp);
}
g.DrawPath(Pens.Blue, gp);
g.DrawRectangle(Pens.Blue,rect); if (rect.Contains(X, Y))
{
g.FillRectangle(Brushes.LavenderBlush, rect);
}
else
{
g.FillRectangle(Brushes.DarkCyan, rect);
}
}实在是闪得没办法了
this.SetStyle(ControlStyles.DoubleBuffer, true);
{ X = e.X;
Y = e.Y;
Graphics g = panel1.CreateGraphics();
g.SmoothingMode = SmoothingMode.HighQuality;
gp.AddLine(new Point(10, 10), new Point(100, 100)); gp.AddLine(new Point(100, 100),new Point(150, 90));
gp.AddLines(new Point[] { new Point(150, 70), new Point(100, 90), new Point(50, 160) });//(new Point(150, 90), new Size(120, 120), 0, 50);
gp.CloseAllFigures();
if (gp.IsVisible(X, Y))
{
g.FillPath(Brushes.Red, gp);
}
else
{
g.FillPath(Brushes.DeepSkyBlue, gp);
}
g.DrawPath(Pens.Blue, gp);
g.DrawRectangle(Pens.Blue,rect); if (rect.Contains(X, Y))
{
g.FillRectangle(Brushes.LavenderBlush, rect);
}
else
{
g.FillRectangle(Brushes.DarkCyan, rect);
}
}
2 通过API获得graphics不使用onpaint事件。
不要用involidate自己写函数在需要时调用
pribate Graphics g = panel1.CreateGraphics();
private void myPaint(){
g.SmoothingMode = SmoothingMode.HighQuality;
gp.AddLine(new Point(10, 10), new Point(100, 100)); gp.AddLine(new Point(100, 100),new Point(150, 90));
gp.AddLines(new Point[] { new Point(150, 70), new Point(100, 90), new Point(50, 160) });//(new Point(150, 90), new Size(120, 120), 0, 50);
gp.CloseAllFigures();
if (gp.IsVisible(X, Y))
{
g.FillPath(Brushes.Red, gp);
}
else
{
g.FillPath(Brushes.DeepSkyBlue, gp);
}
g.DrawPath(Pens.Blue, gp);
g.DrawRectangle(Pens.Blue,rect); if (rect.Contains(X, Y))
{
g.FillRectangle(Brushes.LavenderBlush, rect);
}
else
{
g.FillRectangle(Brushes.DarkCyan, rect);
}
}private void panel1_MouseMove(object sender, MouseEventArgs e)
{
X = e.X;
Y = e.Y;
myPaint();
}
protected override void OnPaint(PaintEventArgs e)
{
myPaint();
}
应该C#也可以解决.
你参考一下:http://blog.sina.com.cn/s/blog_59cea87f0100d7it.html
http://blog.joycode.com/5drush/archive/2004/01/06/10701.joy
dylike(专注GDI+) 等 级:
恭喜了哈哈。。