📄 form1.vb
字号:
'Author: Nicholas Afxentiou
Imports System.Drawing.Drawing2D
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents PaletteBox As System.Windows.Forms.PictureBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button7 As System.Windows.Forms.Button
Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Panel2 As System.Windows.Forms.Panel
Friend WithEvents Panel3 As System.Windows.Forms.Panel
Friend WithEvents Label2 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.PaletteBox = New System.Windows.Forms.PictureBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.Button7 = New System.Windows.Forms.Button
Me.TrackBar1 = New System.Windows.Forms.TrackBar
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Panel3 = New System.Windows.Forms.Panel
Me.Panel2 = New System.Windows.Forms.Panel
Me.Panel1 = New System.Windows.Forms.Panel
Me.Label2 = New System.Windows.Forms.Label
CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'PaletteBox
'
Me.PaletteBox.BackColor = System.Drawing.Color.White
Me.PaletteBox.Location = New System.Drawing.Point(2, 304)
Me.PaletteBox.Name = "PaletteBox"
Me.PaletteBox.Size = New System.Drawing.Size(238, 22)
Me.PaletteBox.TabIndex = 0
Me.PaletteBox.TabStop = False
'
'Button1
'
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button1.Location = New System.Drawing.Point(0, 0)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 23)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Ellipse"
'
'Button2
'
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button2.Location = New System.Drawing.Point(0, 24)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(64, 23)
Me.Button2.TabIndex = 3
Me.Button2.Text = "Line"
'
'Button3
'
Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button3.Location = New System.Drawing.Point(0, 48)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(64, 23)
Me.Button3.TabIndex = 4
Me.Button3.Text = "Brush"
'
'Button4
'
Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button4.Location = New System.Drawing.Point(0, 72)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(64, 23)
Me.Button4.TabIndex = 5
Me.Button4.Text = "Rectangle"
'
'Button5
'
Me.Button5.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button5.Location = New System.Drawing.Point(0, 96)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(64, 23)
Me.Button5.TabIndex = 6
Me.Button5.Text = "Path"
'
'Button6
'
Me.Button6.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button6.Location = New System.Drawing.Point(0, 152)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(64, 23)
Me.Button6.TabIndex = 7
Me.Button6.Text = "Eraser"
'
'Button7
'
Me.Button7.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button7.Location = New System.Drawing.Point(0, 120)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(64, 23)
Me.Button7.TabIndex = 8
Me.Button7.Text = "Text"
'
'TrackBar1
'
Me.TrackBar1.LargeChange = 1
Me.TrackBar1.Location = New System.Drawing.Point(320, 304)
Me.TrackBar1.Maximum = 20
Me.TrackBar1.Minimum = 1
Me.TrackBar1.Name = "TrackBar1"
Me.TrackBar1.Size = New System.Drawing.Size(64, 42)
Me.TrackBar1.TabIndex = 0
Me.TrackBar1.TickStyle = System.Windows.Forms.TickStyle.None
Me.TrackBar1.Value = 1
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(384, 304)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(24, 20)
Me.TextBox2.TabIndex = 10
Me.TextBox2.Text = "1"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(288, 308)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(37, 16)
Me.Label1.TabIndex = 11
Me.Label1.Text = "Brush:"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Panel3)
Me.GroupBox1.Controls.Add(Me.Panel2)
Me.GroupBox1.Controls.Add(Me.Panel1)
Me.GroupBox1.Location = New System.Drawing.Point(0, 184)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(64, 120)
Me.GroupBox1.TabIndex = 12
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Style"
'
'Panel3
'
Me.Panel3.BackColor = System.Drawing.Color.AliceBlue
Me.Panel3.Location = New System.Drawing.Point(16, 84)
Me.Panel3.Name = "Panel3"
Me.Panel3.Size = New System.Drawing.Size(32, 24)
Me.Panel3.TabIndex = 15
'
'Panel2
'
Me.Panel2.BackColor = System.Drawing.Color.AliceBlue
Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Panel2.Location = New System.Drawing.Point(16, 52)
Me.Panel2.Name = "Panel2"
Me.Panel2.Size = New System.Drawing.Size(32, 24)
Me.Panel2.TabIndex = 14
'
'Panel1
'
Me.Panel1.BackColor = System.Drawing.SystemColors.Control
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Panel1.Location = New System.Drawing.Point(16, 20)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(32, 24)
Me.Panel1.TabIndex = 13
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(432, 306)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 13
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(496, 325)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button7)
Me.Controls.Add(Me.Button6)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.PaletteBox)
Me.Controls.Add(Me.TrackBar1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "Form1"
Me.Text = "WhiteBoard"
CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private ColorMap As Bitmap
#Region "enumerations"
Public Enum dModes
Line
Rectangle
Ellipse
Brush
Path
Text
Eraser
End Enum
Public Enum dStyles
Outline
OutlineFilled
Filled
End Enum
#End Region
#Region "declarations"
Dim bmp As Bitmap
Dim bmp2 As Bitmap
Dim g2 As Graphics
Dim clr As Color = Color.Red
Dim clr2 As Color = Color.blue
Private StartX, StartY, EndX, EndY, BoxWidth, BoxHeight As Integer
Dim mpath As New Drawing2D.GraphicsPath
Dim dmode As dModes
Dim xLoc, yLoc As Integer
Dim dstyle As dStyles = dStyles.Outline
Dim pWidth As Int16 = 1
Dim c As New Cursor(GetEmbeddedFile("Whiteboard.ColorPicker.ico"))
Dim er As New Cursor(GetEmbeddedFile("Whiteboard.Eraser.ico"))
Dim isDraw As Boolean
Dim pF, pFOld As PointF
Dim nPen As New Pen(clr)
Declare Function HideCaret Lib "user32.dll" (ByVal hwnd As Int32) As Int32
Dim allow As Boolean
Declare Function ShowCaret Lib "user32.dll" (ByVal hwnd As Int32) As Int32
Declare Function CreateCaret Lib "user32.dll" (ByVal hwnd As Int32, ByVal hBitmap As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32) As Int32
Declare Function SetCaretPos Lib "user32.dll" (ByVal x As Int32, ByVal y As Int32) As Int32
WithEvents pbox As New pBoxControl
Dim txt As String
#End Region
#Region "properties"
Public ReadOnly Property Color() As Color
Get
Return clr
End Get
End Property
Property penWidth() As Int16
Get
Return pWidth
End Get
Set(ByVal Value As Int16)
pWidth = Value
nPen.Width = pWidth
End Set
End Property
Property DrawStyles() As dStyles
Get
Return dstyle
End Get
Set(ByVal Value As dStyles)
dstyle = Value
End Set
End Property
#End Region
'creates the color palette
Sub CreatePalette()
bmp = New Bitmap(PaletteBox.Width, PaletteBox.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim rect1 As New Rectangle(0, 0, PaletteBox.Width, PaletteBox.Height)
Dim lbrush As New LinearGradientBrush(rect1, Color.FromArgb(255, 255, 255, 255), Color.FromArgb(255, 0, 0, 0), LinearGradientMode.Vertical)
g.FillRectangle(lbrush, rect1)
Dim rect As New Rectangle(0, 1, 20, 20)
g.CompositingMode = CompositingMode.SourceOver
lbrush = New LinearGradientBrush(rect, Color.FromArgb(255, 0, 0, 0), Color.FromArgb(0, 0, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(10, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(0, 0, 0, 0), Color.FromArgb(255, 255, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(20, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(255, 255, 0, 0), Color.FromArgb(0, 0, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(10, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(0, 0, 0, 0), Color.FromArgb(255, 255, 255, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(20, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(255, 255, 255, 0), Color.FromArgb(0, 0, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(10, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(0, 0, 0, 0), Color.FromArgb(255, 0, 255, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(20, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(255, 0, 255, 0), Color.FromArgb(0, 0, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(10, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(0, 0, 0, 0), Color.FromArgb(255, 0, 255, 255), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(20, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(255, 0, 255, 255), Color.FromArgb(0, 0, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(10, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(0, 0, 0, 0), Color.FromArgb(255, 0, 0, 255), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(20, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(255, 0, 0, 255), Color.FromArgb(0, 0, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(10, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(0, 0, 0, 0), Color.FromArgb(255, 255, 0, 255), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(20, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(255, 255, 0, 255), Color.FromArgb(0, 0, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
rect.Offset(10, 0)
lbrush = New LinearGradientBrush(rect, Color.FromArgb(0, 0, 0, 0), Color.FromArgb(255, 255, 0, 0), LinearGradientMode.Horizontal)
g.FillRectangle(lbrush, rect)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -