form1.vb
来自「visual basic 实现简单的drawing example例子」· VB 代码 · 共 69 行
VB
69 行
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.BackColor = Color.LightGray
cboShape.SelectedIndex = 0
cboShape.DropDownStyle = ComboBoxStyle.DropDownList
End Sub
Dim insetX, insetY, shapeWidth, shapeHeight As Integer
Dim shape As String
Dim pen As New Pen(System.Drawing.Color.Black)
Dim brush As New SolidBrush(System.Drawing.Color.Blue)
Dim polyPoints(4) As Point
Private Sub setVars()
shape = cboShape.Text
shapeWidth = nupWidth.Value
shapeHeight = nupHeight.Value
insetX = nupX.Value
insetY = nupy.Value
End Sub
'Private Sub drawPolygonExample(ByVal e As PaintEventArgs)
' Dim bluePen As New Pen(Color.Blue)
' e.Graphics.DrawPolygon(bluePen, polyPoints)
'End Sub
Private Sub pbDrawingSurface_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pbDrawingSurface.Paint
If (shape = "Line Rectangle") Then
e.Graphics.Clear(Color.LightBlue)
e.Graphics.DrawRectangle(pen, insetX, insetY, shapeWidth, shapeHeight)
ElseIf (shape = "Solid Rectangle") Then
e.Graphics.FillRectangle(brush, insetX, insetY, shapeWidth, shapeHeight)
ElseIf (shape = "Line Ellipse") Then
e.Graphics.DrawEllipse(pen, insetX, insetY, shapeWidth, shapeHeight)
ElseIf (shape = "Solid Ellipse") Then
e.Graphics.FillEllipse(brush, insetX, insetY, shapeWidth, shapeHeight)
ElseIf (shape = "Polygon") Then
polyPoints(0).X = 1
polyPoints(0).Y = 1
polyPoints(1).X = 1
polyPoints(1).Y = 25
polyPoints(3).X = 25
polyPoints(3).Y = 25
polyPoints(2).X = 75
polyPoints(2).Y = 75
polyPoints(4).X = 1
polyPoints(4).Y = 75
e.Graphics.DrawPolygon(pen, polyPoints)
ElseIf (shape = "String") Then
Dim exampleString As String = "Here is an example String!"
'Dim blackBrush As New SolidBrush(Color.Black)
Dim drawFont As New Font("Arial", 18)
e.Graphics.DrawString(exampleString, drawFont, brush, insetX, insetY)
End If
End Sub
Private Sub cmbDraw_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbDraw.Click
setVars()
pbDrawingSurface.Refresh()
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?