Condividi tramite


ActivityDesignerPaint.DrawText Metodo

Definizione

Disegna un testo nell'area dell'ActivityDesigner.

public:
 static void DrawText(System::Drawing::Graphics ^ graphics, System::Drawing::Font ^ font, System::String ^ text, System::Drawing::Rectangle boundingRect, System::Drawing::StringAlignment alignment, System::Workflow::ComponentModel::Design::TextQuality textQuality, System::Drawing::Brush ^ textBrush);
public static void DrawText (System.Drawing.Graphics graphics, System.Drawing.Font font, string text, System.Drawing.Rectangle boundingRect, System.Drawing.StringAlignment alignment, System.Workflow.ComponentModel.Design.TextQuality textQuality, System.Drawing.Brush textBrush);
static member DrawText : System.Drawing.Graphics * System.Drawing.Font * string * System.Drawing.Rectangle * System.Drawing.StringAlignment * System.Workflow.ComponentModel.Design.TextQuality * System.Drawing.Brush -> unit
Public Shared Sub DrawText (graphics As Graphics, font As Font, text As String, boundingRect As Rectangle, alignment As StringAlignment, textQuality As TextQuality, textBrush As Brush)

Parametri

graphics
Graphics

Classe Graphics sulla quale disegnare il testo.

font
Font

Oggetto Font utilizzato per disegnare il testo.

text
String

Testo da disegnare.

boundingRect
Rectangle

Struttura Rectangle di delimitazione in cui disegnare il testo.

alignment
StringAlignment

Enumerazione StringAlignment che specifica la posizione di allineamento del testo nel rettangolo di delimitazione.

textQuality
TextQuality

TextQuality che specifica il livello di qualità con cui disegnare il testo.

textBrush
Brush

Classe Brush utilizzata per disegnare il testo.

Eccezioni

graphics, font, text o textBrush contiene un riferimento null (Nothing in Visual Basic).

Esempio

Nell'esempio seguente viene illustrato un modo per utilizzare la classe ActivityDesignerPaint per creare un'attività personalizzata nell'area di progettazione del flusso di lavoro. Per prima cosa viene tracciato un rettangolo arrotondato utilizzando il metodo DrawRoundedRectangle. Il testo viene quindi tracciato mediante DrawText e posizionato nel percorso dell'elemento TextRectangle della classe ActivityDesigner. Inoltre, la proprietà Image associata all'elemento ActivityDesigner viene tracciata utilizzando il metodo DrawImage della classe ActivityDesignerPaint. Infine, tramite il metodo CompositeActivity, viene disegnato un pulsante Espandi utilizzato da un oggetto della classe 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

Si applica a