次の方法で共有


Shape.Paint イベント

形状が再描画されるときに発生します。

名前空間:  Microsoft.VisualBasic.PowerPacks
アセンブリ:  Microsoft.VisualBasic.PowerPacks.Vs (Microsoft.VisualBasic.PowerPacks.Vs.dll 内)

構文

'宣言
<BrowsableAttribute(True)> _
Public Event Paint As PaintEventHandler
[BrowsableAttribute(true)]
public event PaintEventHandler Paint
[BrowsableAttribute(true)]
public:
 event PaintEventHandler^ Paint {
    void add (PaintEventHandler^ value);
    void remove (PaintEventHandler^ value);
}
[<BrowsableAttribute(true)>]
member Paint : IEvent<PaintEventHandler,
    PaintEventArgs>
JScript では、イベントは使用できません。

解説

Paintは、通常、図形が再描画されるときに、カスタムの描画を実行するイベント ハンドラーを使用します。

イベントを処理する方法の詳細については、次を参照してください。イベントの処理と発生です。

次の例を使用する方法を示しています。、Paint線を描画するイベント、RectangleShapeコントロールです。 この例では、 RectangleShape RectangleShape1 という名前のフォームにコントロールです。

Private mousePath = New System.Drawing.Drawing2D.GraphicsPath()

Private Sub RectangleShape2_MouseDown(
    ByVal sender As Object, 
     ByVal e As System.Windows.Forms.MouseEventArgs
  ) Handles RectangleShape2.MouseDown

    Dim mouseDownLocation As New Point(e.X + RectangleShape2.Left, 
      e.Y + RectangleShape2.Top)
    ' Clear the previous line.
    mousePath.Dispose()
    mousePath = New System.Drawing.Drawing2D.GraphicsPath()
    RectangleShape2.Invalidate()
    ' Add a line to the graphics path.
    mousePath.AddLine(mouseDownLocation, mouseDownLocation)
End Sub 

Private Sub RectangleShape2_MouseMove(
    ByVal sender As Object, 
    ByVal e As System.Windows.Forms.MouseEventArgs
  ) Handles RectangleShape2.MouseMove

    Dim mouseX As Integer = e.X + RectangleShape2.Left
    Dim mouseY As Integer = e.Y + RectangleShape2.Top
    ' Add a line to the graphics path.
    mousePath.AddLine(mouseX, mouseY, mouseX, mouseY)
End Sub 

Private Sub RectangleShape2_MouseUp(
    ByVal sender As Object, 
    ByVal e As System.Windows.Forms.MouseEventArgs
  ) Handles RectangleShape2.MouseUp

    Dim mouseUpLocation = New System.Drawing.Point(e.X + 
      RectangleShape2.Left, e.Y + RectangleShape2.Top)
    ' Add a line to the graphics path.
    mousePath.Addline(mouseUpLocation, mouseUpLocation)
    ' Force the shape to redraw.
    RectangleShape2.Invalidate()
End Sub 

Private Sub RectangleShape2_Paint(
    ByVal sender As Object, 
    ByVal e As System.Windows.Forms.PaintEventArgs
  ) Handles RectangleShape2.Paint

    ' Draw the line.
    e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath)
End Sub
private System.Drawing.Drawing2D.GraphicsPath mousePath = 
    new System.Drawing.Drawing2D.GraphicsPath();

private void rectangleShape2_MouseDown(object sender, 
    System.Windows.Forms.MouseEventArgs e)
{
    Point mouseDownLocation = new Point(e.X + rectangleShape2.Left, 
        e.Y + rectangleShape2.Top);
    // Clear the previous line.
    mousePath.Dispose();
    mousePath = new System.Drawing.Drawing2D.GraphicsPath();
    rectangleShape2.Invalidate();
    // Add a line to the graphics path.
    mousePath.AddLine(mouseDownLocation, mouseDownLocation);
}

private void rectangleShape2_MouseMove(object sender, 
    System.Windows.Forms.MouseEventArgs e)
{
    int mouseX = e.X + rectangleShape2.Left;
    int mouseY = e.Y + rectangleShape2.Top;
    // Add a line to the graphics path.
    mousePath.AddLine(mouseX, mouseY, mouseX, mouseY);
}

private void rectangleShape2_MouseUp(object sender, 
    System.Windows.Forms.MouseEventArgs e)
{
    System.Drawing.Point mouseUpLocation = 
        new System.Drawing.Point(e.X + rectangleShape2.Left, 
            e.Y + rectangleShape2.Top);
    // Add a line to the graphics path.
    mousePath.AddLine(mouseUpLocation, mouseUpLocation);
    // Force the shape to redraw.
    rectangleShape2.Invalidate();
}

private void rectangleShape2_Paint(object sender, 
    System.Windows.Forms.PaintEventArgs e)
{
    // Draw the line.
    e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath);
}

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

Shape クラス

Microsoft.VisualBasic.PowerPacks 名前空間

その他の技術情報

方法 : LineShape コントロールを使用して線を描画する (Visual Studio)

方法 : OvalShape コントロールおよび RectangleShape コントロールを使用して図形を描画する (Visual Studio)

ライン コントロールとシェイプ コントロールの概要 (Visual Studio)