C# DrawToBitmap 方法

支持呈现到指定的位图。

命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)

语法

public void DrawToBitmap (  Bitmap bitmap,  Rectangle targetBounds ) 

参数

bitmap 要绘制到的位图。
targetBounds 呈现控件时的边界。
备注

ActiveX 控件不支持 DrawToBitmap 方法。如果需要,您可以重写 OnPrint 事件并提供自定义打印逻辑。

DrawToBitmap 方法具有下列局限性:

  • 可能会针对大位图引发 ArgumentException。允许使用的最大大小因计算机而异。

  • DrawToBitmap 不支持 Windows XP Tablet PC Edition 2005 操作系统的 Ink 控件。

  • 如果 TextBox 的 Visible 属性设置为 false,则 DrawToBitmap 不绘制子 TextBox

  • 容器内部的控件按相反的顺序呈现。

  • 对于 RichTextBox,DrawToBitmap 不能完全发挥作用;只绘制位图的边框。

    如果 xy 坐标或者 targetBoundswidthheight 参数小于 0,则引发 ArgumentException

    示例
    下面的示例演示如何使用 DrawToBitmap 方法和 ClientRectangle 属性在 PictureBox 控件上绘制一个 OvalShape
    private void form1_Load(System.Object sender, System.EventArgs e) { System.Drawing.Bitmap pic = new System.Drawing.Bitmap( this.pictureBox1.Image, pictureBox1.Width, pictureBox1.Height);
        System.Drawing.Rectangle rect = new System.Drawing.Rectangle();     // Assign the client rectangle.     rect = ovalShape1.ClientRectangle;     // Draw the oval on the bitmap.     ovalShape1.DrawToBitmap(pic, rect);     pictureBox2.Image = pic; }  

你可能感兴趣的:(C# DrawToBitmap 方法)