ActivityDesignerPaint.DrawImage 方法
定义
在活动设计器图面上绘制图像。Draws an image on the activity designer surface.
重载
| DrawImage(Graphics, Image, Rectangle, DesignerContentAlignment) |
使用 Graphics、Image、Rectangle 和 DesignerContentAlignment 在活动设计器图面上绘制图像。Draws an image on the activity designer surface by using a Graphics, an Image, a Rectangle, and a DesignerContentAlignment. |
| DrawImage(Graphics, Image, Rectangle, Rectangle, DesignerContentAlignment, Single, Boolean) |
使用 Graphics、Image、源和目标 Rectangle、DesignerContentAlignment、单精度浮点型数字和布尔值在活动设计器图面上绘制图像。Draws an image on the activity designer surface by using a Graphics, an Image, a source and destination Rectangle, an DesignerContentAlignment, a single-precision floating-point number, and a Boolean value. |
DrawImage(Graphics, Image, Rectangle, DesignerContentAlignment)
使用 Graphics、Image、Rectangle 和 DesignerContentAlignment 在活动设计器图面上绘制图像。Draws an image on the activity designer surface by using a Graphics, an Image, a Rectangle, and a DesignerContentAlignment.
public:
static void DrawImage(System::Drawing::Graphics ^ graphics, System::Drawing::Image ^ image, System::Drawing::Rectangle destination, System::Workflow::ComponentModel::Design::DesignerContentAlignment alignment);
public static void DrawImage (System.Drawing.Graphics graphics, System.Drawing.Image image, System.Drawing.Rectangle destination, System.Workflow.ComponentModel.Design.DesignerContentAlignment alignment);
static member DrawImage : System.Drawing.Graphics * System.Drawing.Image * System.Drawing.Rectangle * System.Workflow.ComponentModel.Design.DesignerContentAlignment -> unit
Public Shared Sub DrawImage (graphics As Graphics, image As Image, destination As Rectangle, alignment As DesignerContentAlignment)
参数
- destination
- Rectangle
定义要绘制的图像边界的 Rectangle。The Rectangle that defines the bounds of the image to draw.
- alignment
- DesignerContentAlignment
指定图像在边框中的对齐方式的 DesignerContentAlignment。The DesignerContentAlignment that specifies how the image is aligned in the bounding rectangle.
例外
graphics、image 或 destination 包含空引用(在 Visual Basic 中为 Nothing)。graphics, image, or destination contains a null reference (Nothing in Visual Basic).
示例
下面的示例演示一种使用 ActivityDesignerPaint 类在工作流设计图面上绘制自定义活动的方式。The following example demonstrates a way to use the ActivityDesignerPaint class to draw a custom activity on the workflow design surface. 首先使用 DrawRoundedRectangle 方法绘制一个圆角矩形。A rounded rectangle is first drawn using the DrawRoundedRectangle method. 然后使用 DrawText 绘制文本并将其放在 TextRectangle 的 ActivityDesigner 位置。Text is then drawn using DrawText and is placed at the location of the TextRectangle of the ActivityDesigner. 此外,再使用 Image 类的 ActivityDesigner 方法绘制与 DrawImage 关联的 ActivityDesignerPaint。Additionally, the Image associated with the ActivityDesigner is drawn using the DrawImage method of the ActivityDesignerPaint class. 最后,使用 CompositeActivity 绘制由 DrawExpandButton 使用的展开按钮。Finally, an expand button used by a CompositeActivity is drawn using the DrawExpandButton.
private bool expanded = true;
private bool useBasePaint = false;
public bool UseBasePaint
{
get { return this.useBasePaint; }
set { this.useBasePaint = value; }
}
public bool Expanded
{
get { return this.expanded; }
set { this.expanded = value; }
}
protected override void OnPaint(ActivityDesignerPaintEventArgs e)
{
if (this.UseBasePaint == true)
{
base.OnPaint(e);
return;
}
DrawCustomActivity(e);
}
private void DrawCustomActivity(ActivityDesignerPaintEventArgs e)
{
Graphics graphics = e.Graphics;
CompositeDesignerTheme compositeDesignerTheme = (CompositeDesignerTheme)e.DesignerTheme;
ActivityDesignerPaint.DrawRoundedRectangle(graphics, compositeDesignerTheme.BorderPen, this.Bounds, compositeDesignerTheme.BorderWidth);
string text = this.Text;
Rectangle textRectangle = this.TextRectangle;
if (!String.IsNullOrEmpty(text) && !textRectangle.IsEmpty)
{
ActivityDesignerPaint.DrawText(graphics, compositeDesignerTheme.Font, text, textRectangle, StringAlignment.Center, e.AmbientTheme.TextQuality, compositeDesignerTheme.ForegroundBrush);
}
System.Drawing.Image image = this.Image;
Rectangle imageRectangle = this.ImageRectangle;
if (image != null && !imageRectangle.IsEmpty)
{
ActivityDesignerPaint.DrawImage(graphics, image, imageRectangle, DesignerContentAlignment.Fill);
}
ActivityDesignerPaint.DrawExpandButton(graphics,
new Rectangle(this.Location.X, this.Location.Y, 10, 10),
this.Expanded,
compositeDesignerTheme);
}
Private expandedValue As Boolean = True
Private useBasePaintValue As Boolean = False
Public Property UseBasePaint() As Boolean
Get
Return Me.useBasePaintValue
End Get
Set(ByVal value As Boolean)
Me.useBasePaintValue = value
End Set
End Property
Public Property Expanded() As Boolean
Get
Return Me.expandedValue
End Get
Set(ByVal value As Boolean)
Me.expandedValue = value
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As ActivityDesignerPaintEventArgs)
If Me.UseBasePaint = True Then
MyBase.OnPaint(e)
Return
End If
DrawCustomActivity(e)
End Sub
Private Sub DrawCustomActivity(ByVal e As ActivityDesignerPaintEventArgs)
Dim graphics As Graphics = e.Graphics
Dim compositeDesignerTheme As CompositeDesignerTheme = CType(e.DesignerTheme, CompositeDesignerTheme)
ActivityDesignerPaint.DrawRoundedRectangle(graphics, compositeDesignerTheme.BorderPen, Me.Bounds, compositeDesignerTheme.BorderWidth)
Dim text As String = Me.Text
Dim TextRectangle As Rectangle = Me.TextRectangle
If Not String.IsNullOrEmpty(text) And Not TextRectangle.IsEmpty Then
ActivityDesignerPaint.DrawText(graphics, compositeDesignerTheme.Font, text, TextRectangle, StringAlignment.Center, e.AmbientTheme.TextQuality, compositeDesignerTheme.ForegroundBrush)
End If
Dim Image As System.Drawing.Image = Me.Image
Dim ImageRectangle As Rectangle = Me.ImageRectangle
If Image IsNot Nothing And Not ImageRectangle.IsEmpty Then
ActivityDesignerPaint.DrawImage(graphics, Image, ImageRectangle, DesignerContentAlignment.Fill)
End If
ActivityDesignerPaint.DrawExpandButton(graphics, _
New Rectangle(Me.Location.X, Me.Location.Y, 10, 10), _
Me.Expanded, _
compositeDesignerTheme)
End Sub
注解
在使用此版本的 DrawImage 时,源矩形设置为图像的大小(用像素表示),透明度设置设为 1.0f 且不允许使用绘图灰度。When you use this version of DrawImage, the source rectangle is set to the size, in pixels, of the image, the transparency setting is set to 1.0f, and drawing grayscales is not allowed.
适用于
DrawImage(Graphics, Image, Rectangle, Rectangle, DesignerContentAlignment, Single, Boolean)
使用 Graphics、Image、源和目标 Rectangle、DesignerContentAlignment、单精度浮点型数字和布尔值在活动设计器图面上绘制图像。Draws an image on the activity designer surface by using a Graphics, an Image, a source and destination Rectangle, an DesignerContentAlignment, a single-precision floating-point number, and a Boolean value.
public:
static void DrawImage(System::Drawing::Graphics ^ graphics, System::Drawing::Image ^ image, System::Drawing::Rectangle destination, System::Drawing::Rectangle source, System::Workflow::ComponentModel::Design::DesignerContentAlignment alignment, float transparency, bool grayscale);
public static void DrawImage (System.Drawing.Graphics graphics, System.Drawing.Image image, System.Drawing.Rectangle destination, System.Drawing.Rectangle source, System.Workflow.ComponentModel.Design.DesignerContentAlignment alignment, float transparency, bool grayscale);
static member DrawImage : System.Drawing.Graphics * System.Drawing.Image * System.Drawing.Rectangle * System.Drawing.Rectangle * System.Workflow.ComponentModel.Design.DesignerContentAlignment * single * bool -> unit
Public Shared Sub DrawImage (graphics As Graphics, image As Image, destination As Rectangle, source As Rectangle, alignment As DesignerContentAlignment, transparency As Single, grayscale As Boolean)
参数
- alignment
- DesignerContentAlignment
指定图像在边框中的对齐方式的 DesignerContentAlignment。The DesignerContentAlignment that specifies how the image is aligned in the bounding rectangle.
- transparency
- Single
定义图像的透明度设置的单精度浮点型数字。A single-precision floating-point number that defines the transparency settings for the image.
- grayscale
- Boolean
为 true 则绘制灰度图像;否则为 false。true to draw the image in grayscales; otherwise, false.
例外
graphics、image、destination 或 source 包含空引用(在 Visual Basic 中为 Nothing)。graphics, image, destination, or source contains a null reference (Nothing in Visual Basic).
- 或 --or-
transparency 小于 0 或大于 1.0f。transparency is less than 0, or greater than 1.0f.