ActivityDesignerPaint.DrawRoundedRectangle(Graphics, Pen, Rectangle, Int32) 方法

定義

在活動設計工具介面上繪製圓角矩形。Draws a rounded rectangle on the activity designer surface.

public:
 static void DrawRoundedRectangle(System::Drawing::Graphics ^ graphics, System::Drawing::Pen ^ drawingPen, System::Drawing::Rectangle rectangle, int radius);
public static void DrawRoundedRectangle (System.Drawing.Graphics graphics, System.Drawing.Pen drawingPen, System.Drawing.Rectangle rectangle, int radius);
static member DrawRoundedRectangle : System.Drawing.Graphics * System.Drawing.Pen * System.Drawing.Rectangle * int -> unit

參數

graphics
Graphics

要在其上繪製矩形的 GraphicsThe Graphics on which to draw the rectangle.

drawingPen
Pen

要繪製矩形的 PenThe Pen to draw the rectangle.

rectangle
Rectangle

Rectangle,定義圓角矩形的界限。The Rectangle that defines the bounds of the rounded rectangle.

radius
Int32

用來做為圓角邊緣半徑的整數值。The integer value of the radius to use for the rounded edges.

例外狀況

graphicsdrawingPen 包含 null 參考 (在 Visual Basic 中為 Nothing)。graphics or drawingPen 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 繪製文字,並放置在 TextRectangleActivityDesigner 位置。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

備註

DrawRoundedRectangle 會使用 GetRoundedRectanglePath 方法來取得繪製的路徑。DrawRoundedRectangle uses the GetRoundedRectanglePath method to obtain the path to draw.

適用於