各位大哥们,我做了一个鼠标移动就画线的程序
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
Graphics g;
g = this.CreateGraphics() ;
g.DrawLine (new Pen (Color.Black ,1),oldPoint,new Point (e.X ,e.Y ));
移动的过程中,不断的画线,我只需要一条线,所以画新线之前,把旧线先用白线从新画了一遍
g.DrawLine (new Pen (Color.White ,1),oldPoint,tempPoint);
但是这样效果也不好,请问C#里怎么画异或线啊,就是一条线画两遍就自动消失的,这种模式怎么设呢?急
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
Graphics g;
g = this.CreateGraphics() ;
g.DrawLine (new Pen (Color.Black ,1),oldPoint,new Point (e.X ,e.Y ));
移动的过程中,不断的画线,我只需要一条线,所以画新线之前,把旧线先用白线从新画了一遍
g.DrawLine (new Pen (Color.White ,1),oldPoint,tempPoint);
但是这样效果也不好,请问C#里怎么画异或线啊,就是一条线画两遍就自动消失的,这种模式怎么设呢?急
但是在GDI+中,如上的方法就不行了,你可以用底色去重画,
或者用
Graphics.Clear( Color.Black );
来擦掉用黑色所画的图形。
Graphics.Clear( Color.Black )
是可以擦去的,但是屏幕老闪动,这样也不好啊。
用底色去重画,也可以擦去,但是这搞的像橡皮擦一样了,鼠标不断移动,就把一些画好的线也擦了。
哪位教教异或怎么画啊
VB,C++里都有的
Point lastPoint = new Point();
bool mouseIsDown; private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mouseIsDown = true;
originalPoint.X = e.X;
originalPoint.Y = e.Y;
lastPoint.X = -1;
lastPoint.Y = -1;
} private void MyDrawReversibleLine(Point point1, Point point2)
{
point1 = PointToScreen(point1);
point2 = PointToScreen(point2);
ControlPaint.DrawReversibleLine(point1, point2, Color.Yellow);
} private void Form1_MouseUp(object sender, MouseEventArgs e)
{
mouseIsDown = false;
if (lastPoint.X != -1)
{
Point currentPoint = new Point(e.X, e.Y);
MyDrawReversibleLine(originalPoint, lastPoint);
}
lastPoint.X = -1;
lastPoint.Y = -1;
originalPoint.X = -1;
originalPoint.Y = -1;
} private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Point currentPoint = new Point(e.X, e.Y);
if (mouseIsDown)
{
if (lastPoint.X != -1)
{
MyDrawReversibleLine(originalPoint, lastPoint);
}
lastPoint = currentPoint;
MyDrawReversibleLine(originalPoint, currentPoint);
}
}
[DllImport("gdi32.dll")]
static extern int SetROP2(IntPtr hdc, int fnDrawMode);
C# Signature:
[DllImport("gdi32.dll")]public static extern int SetROP2(IntPtr hdc, BinaryRasterOperations ops);User-Defined Types:public enum BinaryRasterOperations { R2_BLACK = 1,
R2_NOTMERGEPEN = 2,
R2_MASKNOTPEN = 3,
R2_NOTCOPYPEN = 4,
R2_MASKPENNOT = 5,
R2_NOT = 6,
R2_XORPEN = 7,
R2_NOTMASKPEN = 8,
R2_MASKPEN = 9,
R2_NOTXORPEN = 10,
R2_NOP = 11,
R2_MERGENOTPEN = 12,
R2_COPYPEN = 13,
R2_MERGEPENNOT = 14,
R2_MERGEPEN = 15,
R2_WHITE = 16
}
个人认为最好的办法就是引用API了,我以前也是这么做的,不过使用SetROP2就只能使用GDI而不能使用GDI+了