当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET PaintEventArgs.Graphics属性代码示例

本文整理汇总了VB.NET中System.Windows.Forms.PaintEventArgs.Graphics属性的典型用法代码示例。如果您正苦于以下问题:VB.NET PaintEventArgs.Graphics属性的具体用法?VB.NET PaintEventArgs.Graphics怎么用?VB.NET PaintEventArgs.Graphics使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Windows.Forms.PaintEventArgs的用法示例。


在下文中一共展示了PaintEventArgs.Graphics属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Pen

Dim RcDraw As Rectangle
Dim PenWidth As Integer = 5


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

    ' Determine the initial rectangle coordinates...

    RcDraw.X = e.X
    RcDraw.Y = e.Y

End Sub

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

    ' Determine the width and height of the rectangle...

    If e.X < RcDraw.X Then
        RcDraw.Width = RcDraw.X - e.X
        RcDraw.X = e.X
    Else
        RcDraw.Width = e.X - RcDraw.X
    End If

    If e.Y < RcDraw.Y Then
        RcDraw.Height = RcDraw.Y - e.Y
        RcDraw.Y = e.Y
    Else
        RcDraw.Height = e.Y - RcDraw.Y
    End If

    ' Force a repaint of the region occupied by the rectangle...

    Me.Invalidate(RcDraw)

End Sub

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

    ' Draw the rectangle...

    e.Graphics.DrawRectangle(New Pen(Color.Blue, PenWidth), RcDraw)

End Sub
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:44,代码来源:PaintEventArgs.Graphics

示例2: PictureBox

' This example creates a PictureBox control on the form and draws to it. 
' This example assumes that the Form_Load event handler method is connected 
' to the Load event of the form.
Private pictureBox1 As New PictureBox()
Private fnt as New Font("Arial", 10)

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' Dock the PictureBox to the form and set its background to white.
    pictureBox1.Dock = DockStyle.Fill
    pictureBox1.BackColor = Color.White
    ' Connect the Paint event of the PictureBox to the event handler method.
    AddHandler pictureBox1.Paint, AddressOf Me.pictureBox1_Paint

    ' Add the PictureBox control to the Form.
    Me.Controls.Add(pictureBox1)
End Sub


Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
    ' Create a local version of the graphics object for the PictureBox.
    Dim g As Graphics = e.Graphics

    ' Draw a string on the PictureBox.
    g.DrawString("This is a diagonal line drawn on the control", _
        fnt, Brushes.Red, New PointF(30.0F, 30.0F))
    ' Draw a line in the PictureBox.
    g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, _ 
        pictureBox1.Top, pictureBox1.Right, pictureBox1.Bottom)
End Sub
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:29,代码来源:PaintEventArgs.Graphics

示例3: MainClass

' 导入命名空间
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Text

Public Class MainClass

   Shared Sub Main()
        Dim myform As Form = New FrmDrawing()
        Application.Run(myform)
   End Sub ' Main

End Class

Public Class FrmDrawing
   Inherits System.Windows.Forms.Form

   Public Sub New()
      MyBase.New()

      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
      Me.BackColor = System.Drawing.SystemColors.AppWorkspace
      Me.ClientSize = New System.Drawing.Size(472, 157)
   End Sub

   Protected Overrides Sub OnPaint(ByVal paintEvent As PaintEventArgs)

      Dim graphicsObject As Graphics = paintEvent.Graphics
      Dim rectangle1 As Rectangle = New Rectangle(15, 35, 80, 80)
      Dim brush1 As SolidBrush = New SolidBrush(Color.Firebrick)
      Dim pen1 As Pen = New Pen(brush1, 1)
      Dim brush2 As SolidBrush = New SolidBrush(Color.DarkBlue)
      Dim pen2 As Pen = New Pen(brush2, 1)

      rectangle1.Location = New Point(100, 35)
      graphicsObject.DrawRectangle(pen1, rectangle1)
      graphicsObject.DrawArc(pen2, rectangle1, 0, 110)
   End Sub

End Class
开发者ID:VB程序员,项目名称:System.Windows.Forms,代码行数:41,代码来源:PaintEventArgs.Graphics


注:本文中的System.Windows.Forms.PaintEventArgs.Graphics属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。