, Visual C#

         


6.1. .

private void Form1_Paint(object sender, PaintEventArgs e)

{

// :

Pen myPen1 = new Pen(Color.Black, 3);

// myRectangle :

Rectangle myRectangle = new Rectangle(10, 15, 150, 200);

// :

e.Graphics.DrawRectangle(myPen1, myRectangle);

// , myPen1:

myPen1.Dispose();

}

6.2. .

private void Form1_Paint(object sender, PaintEventArgs e)

{

// :



Pen myPen1 = new Pen(Color.Black, 3);

Pen myPen2 = new Pen(Color.Black, 1);

// :

Point myPoint1 = new Point(50, 50);

Point myPoint2 = new Point(100, 25);

Point myPoint3 = new Point(200, 5);

Point myPoint4 = new Point(275, 50);

Point myPoint5 = new Point(300, 150);

Point myPoint6 = new Point(350, 200);

Point myPoint7 = new Point(250, 250);

Point[] myCurvePoints =

{

myPoint1,

myPoint2,

myPoint3,

myPoint4,

myPoint5,

myPoint6,

myPoint7

};

// :

e.Graphics.DrawLines(myPen1, myCurvePoints);

e.Graphics.DrawClosedCurve(myPen2, myCurvePoints);

// myPen1, myPen2:

myPen1.Dispose();

myPen2.Dispose();

}

6.3. .

[System.Runtime.InteropServices.DllImport("gdi32.dll")]

public static extern long BitBlt(IntPtr hdcDest,

int nXDest, int nYDest, int nWidth, int nHeight,

IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);

private Bitmap myMemoryImage;

private void myCaptureScreen()

{

Graphics myGraphics = this.CreateGraphics();

Size s = this.Size;

myMemoryImage = new Bitmap(s.Width, s.Height,

myGraphics);


Graphics myMemoryGraphics =
Graphics.FromImage(myMemoryImage);
IntPtr dc0 = myGraphics.GetHdc();
IntPtr dc1 = myMemoryGraphics.GetHdc();
BitBlt(dc1, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height,
dc0, 0, 0, 13369376);
myGraphics.ReleaseHdc(dc0);
myMemoryGraphics.ReleaseHdc(dc1);
}
6.4. .
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(myMemoryImage, 0, 0);
}
Print (. 6.1) . Form1.cs , :
myCaptureScreen();
.
6.5. PictureBox.
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest,
int nXDest, int nYDest, int nWidth, int nHeight,
IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap myMemoryImage;
private void myCaptureScreen()
{
Graphics myGraphics = pictureBox1.CreateGraphics();
myMemoryImage = new Bitmap(
pictureBox1.Width,
pictureBox1.Height, myGraphics);
Graphics myMemoryGraphics =
Graphics.FromImage(myMemoryImage);
IntPtr dc0 = myGraphics.GetHdc();
IntPtr dc1 = myMemoryGraphics.GetHdc();
BitBlt(dc1, 0, 0, pictureBox1.ClientRectangle.Width,
pictureBox1.ClientRectangle.Height,
dc0, 0, 0, 13369376);
myGraphics.ReleaseHdc(dc0);
myMemoryGraphics.ReleaseHdc(dc1);
}