???? ID: 314945 - ????? ???????: 04 ?????? 2010 - ??????: 2.0

??? ???? ??? ?? ???? ??? ?????? ???? ??? ????? C# ???? ????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

A??? ??????,??????? ?? ?? ???? ???? ?? ????? ??? ??? ?? ???? ?? ???? ???? ?? ????? ??? ??? ?? ????? ????????? ?????????? ????-???? ????? ?? ??????????? ??? ??? ??? delimit ???? ?? ??? ????? ???? ???? ??? ????????? ?????? ??????? (GDI), ??? ?? ??? ??? ??????? ??? ?? ???? raster ?????? (ROPs) ?? ????? ????? ???????,System.Drawing?????? ?? GDI + (?????????? GDI ???? ?? ???), ROPs ?? ??? ??? ?????? ?? ??? ?? ?????? ??? ?? ???? ????? ???? ?? ?? .NET Framework ??? ???? ??? ?? ??????????? ?? ??? ???? ???? approach ?????

GDI ??? ???? ??? ??? ??????? ??? ?? ?????? ROP ??? ?? ????? ????? Particular ??? ROP2 ????? R2_XORPEN ?? R2_NOT ????? ????? ??? ?? ?? ?? ?? ?? ROP2 ??? ?? ????? ????, ?? ??? ?????? ??? ???: ???? ????? ?????? ???? ????? ?????? ???? ???? ???? ?? ???-??? ?? ?????-?? (XOR) ?????? ?? ??? ??? ????? ???

????? ???

??????? ROPs GDI + ??? ?????? ???? ??? ??System.Drawing, ???? approach ?? ??????? ?? ??? ?????????? ????????? ?????? ???? ?? ??? ?????? ??? ?????? ?? ???, GDI ?? ??? interoperate ???? ?? ??? ??????????? Invocation (PInvoke) ?????? ?? ????? ?? ???? ???? ???????, ???? ??? ???????? ???? ?? ????? ???? ?? ?? ???? ?????? ????? ????? ?? ????? ?? ?????? ?? ?????? ??ControlPaint::DrawReversibleFrame(). ????? ????? ???, C# ??? ?? ??????? ???? ??? ?? ??????? Microsoft Visual C# ?????????, ??? ??????? ?? ??? ????? ???? ????????? ???? ?? ?? ?? approach ????:
Boolean bHaveMouse;
Point	ptOriginal = new Point();
Point	ptLast = new Point();

// Called when the left mouse button is pressed. 
public void MyMouseDown( Object sender, MouseEventArgs e )
{
	// Make a note that we "have the mouse".
	bHaveMouse = true;
	// Store the "starting point" for this rubber-band rectangle.
	ptOriginal.X = e.X;
	ptOriginal.Y = e.Y;
	// Special value lets us know that no previous
	// rectangle needs to be erased.
	ptLast.X = -1;
	ptLast.Y = -1;
}
// Convert and normalize the points and draw the reversible frame.
private void MyDrawReversibleRectangle( Point p1, Point p2 )
{
	Rectangle rc = new Rectangle();

	// Convert the points to screen coordinates.
	p1 = PointToScreen( p1 );
	p2 = PointToScreen( p2 );
	// Normalize the rectangle.
	if( p1.X < p2.X )
	{
		rc.X = p1.X;
		rc.Width = p2.X - p1.X;
	}
	else
	{
		rc.X = p2.X;
		rc.Width = p1.X - p2.X;
	}
	if( p1.Y < p2.Y )
	{
		rc.Y = p1.Y;
		rc.Height = p2.Y - p1.Y;
	}
	else
	{
		rc.Y = p2.Y;
		rc.Height = p1.Y - p2.Y;
	}
	// Draw the reversible frame.
	ControlPaint.DrawReversibleFrame( rc, 
					Color.Red, FrameStyle.Dashed );
}
// Called when the left mouse button is released.
public void MyMouseUp( Object sender, MouseEventArgs e )
{
	// Set internal flag to know we no longer "have the mouse".
	bHaveMouse = false;
	// If we have drawn previously, draw again in that spot
	// to remove the lines.
	if( ptLast.X != -1 )
	{
		Point ptCurrent = new Point( e.X, e.Y );
		MyDrawReversibleRectangle( ptOriginal, ptLast );
	}
	// Set flags to know that there is no "previous" line to reverse.
	ptLast.X = -1;
	ptLast.Y = -1;
	ptOriginal.X = -1;
	ptOriginal.Y = -1;
}
// Called when the mouse is moved.
public void MyMouseMove( Object sender, MouseEventArgs e )
{
	Point ptCurrent = new Point( e.X, e.Y );
	// If we "have the mouse", then we draw our lines.
	if( bHaveMouse )
	{
		// If we have drawn previously, draw again in
		// that spot to remove the lines.
		if( ptLast.X != -1 )
		{
			MyDrawReversibleRectangle( ptOriginal, ptLast );
		}
		// Update last point.
		ptLast = ptCurrent;
		// Draw new lines.
		MyDrawReversibleRectangle( ptOriginal, ptCurrent );
	}
}
// Set up delegates for mouse events.
protected override void OnLoad(System.EventArgs e)
{
	MouseDown += new MouseEventHandler( MyMouseDown );
	MouseUp += new MouseEventHandler( MyMouseUp );
	MouseMove += new MouseEventHandler( MyMouseMove );
	bHaveMouse = false;
}
				
???:??? Visual Studio 2005 ??? ????????? ???? ?? ???? ???? ?????? ?? ?? ?? Windows ??????? ????????? ????? ???, ????? C# ????? ??????? ?? ?? ????????? ?? ??? ???????? ??? ??? ?? ?????? ?? Form1 ??? ???? ??? ??.. ??????? ?? ???????????? ???? ???? ?? ??????? ??? Form1.cs ?? Form1.designer.cs ??? ???? Form1.cs ??? ???? ??? ?????? Designer.cs ????? ????? ???? Windows ??????? ??????? ?? ??? ?? ??? ???????? ???? ???? ?? ?? ?? ?????? ?? ????? ????? ?? ???????? ?? ??? ?? ?? ??? ????? C# 2005 ??? Windows ??????? ??????? ?? ???? ??? ???? ??????? ?? ??? ????? Microsoft ??? ???? ?? ????:
HTTP://msdn2.Microsoft.com/en-us/library/ms173077.aspx (http://msdn2.microsoft.com/en-us/library/ms173077.aspx)
????? ??? ?? ?? ?????? ???? ??????? ?? ?????? ?? ??? ?????? ??? ???? ??????? ???????? ?? ?????????? ?????? ?????, ?? ??? ???? ?? ?? interoperate GDI ?? ??? ???? ?? ???Bitmap::LockBits()?? ???? ??? ????? ??????? ?????


???? ???? ???? ??:
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Windows XP Professional
??????: 
kbdswgdi2003swept kbgdi kbhowtomaster kbmt KB314945 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:314945  (http://support.microsoft.com/kb/314945/en-us/ )