ActivityDesignerPaint.DrawImage 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在活動設計工具介面上繪製影像。
多載
DrawImage(Graphics, Image, Rectangle, DesignerContentAlignment) |
使用 Graphics、Image、Rectangle 和 DesignerContentAlignment,在活動設計工具介面上繪製影像。 |
DrawImage(Graphics, Image, Rectangle, Rectangle, DesignerContentAlignment, Single, Boolean) |
使用 Graphics、Image、一個來源和目的 Rectangle、DesignerContentAlignment、單精確度浮點數和布林值,在活動設計工具介面上繪製影像。 |
DrawImage(Graphics, Image, Rectangle, DesignerContentAlignment)
使用 Graphics、Image、Rectangle 和 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)
參數
- alignment
- DesignerContentAlignment
DesignerContentAlignment,指定影像在週框中對齊的方式。
例外狀況
graphics
、image
或 destination
包含 null 參考 (Visual Basic 中為 Nothing
)。
範例
下列範例將示範使用 ActivityDesignerPaint 類別在工作流程設計介面上繪製自訂活動。 先使用 DrawRoundedRectangle 方法來繪製圓角矩形。 然後,使用 DrawText 繪製文字,並放置在 TextRectangle 的 ActivityDesigner 位置。 此外,與 Image 相關聯的 ActivityDesigner 是使用 DrawImage 類別的 ActivityDesignerPaint 方法進行繪製的。 最後,CompositeActivity 所使用的展開按鈕是使用 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,且不允許繪製灰階。
適用於
DrawImage(Graphics, Image, Rectangle, Rectangle, DesignerContentAlignment, Single, Boolean)
使用 Graphics、Image、一個來源和目的 Rectangle、DesignerContentAlignment、單精確度浮點數和布林值,在活動設計工具介面上繪製影像。
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,指定影像在週框中對齊的方式。
- transparency
- Single
定義影像透明度設定的單精確度浮點數。
- grayscale
- Boolean
true
表示以灰階繪製影像,否則為 false
。
例外狀況
graphics
、image
、destination
或 source
包含 null 參考 (在 Visual Basic 中為 Nothing
)。
-或-
transparency
小於 0 或大於 1.0f。