danielmalek
asked on
Creating a Drawing Panel in VB.NET
Hello All,
I am working on creating a mini-paint program written in VB.NET. The program is relatively simple in nature, my issue is this...
While I can get the program to paint fine, I now want to add functionality to select one of four different paint colors (Red, Blue, Green, or Black) and one of three bursh sizes (Small, Medium, or Large).
I am completely versed in the stance of homework in Experts-Exchange and am not seeking someone to give me the correct code, instead some clear explanations and guidance would be most appreciated. My code will be posted next...
========================== ========== ========== ========== ========== ========== ========== ========== ==
Public Class FrmPainter
Inherits System.Windows.Forms.Form
Dim shouldPaint As Boolean = False
#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.ICon tainer
'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 GroupBox1 As System.Windows.Forms.Group Box
Friend WithEvents GroupBox2 As System.Windows.Forms.Group Box
Friend WithEvents btnBlack As System.Windows.Forms.Radio Button
Friend WithEvents btnGreen As System.Windows.Forms.Radio Button
Friend WithEvents btnBlue As System.Windows.Forms.Radio Button
Friend WithEvents btnRed As System.Windows.Forms.Radio Button
Friend WithEvents btnLarge As System.Windows.Forms.Radio Button
Friend WithEvents btnMedium As System.Windows.Forms.Radio Button
Friend WithEvents btnSmall As System.Windows.Forms.Radio Button
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.Group Box
Me.btnBlack = New System.Windows.Forms.Radio Button
Me.btnGreen = New System.Windows.Forms.Radio Button
Me.btnBlue = New System.Windows.Forms.Radio Button
Me.btnRed = New System.Windows.Forms.Radio Button
Me.GroupBox2 = New System.Windows.Forms.Group Box
Me.btnLarge = New System.Windows.Forms.Radio Button
Me.btnMedium = New System.Windows.Forms.Radio Button
Me.btnSmall = New System.Windows.Forms.Radio Button
Me.GroupBox1.SuspendLayout ()
Me.GroupBox2.SuspendLayout ()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.BackColor = System.Drawing.SystemColor s.ScrollBa r
Me.GroupBox1.Controls.Add( Me.btnBlac k)
Me.GroupBox1.Controls.Add( Me.btnGree n)
Me.GroupBox1.Controls.Add( Me.btnBlue )
Me.GroupBox1.Controls.Add( Me.btnRed)
Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(112, 168)
Me.GroupBox1.TabIndex = 1
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Color"
'
'btnBlack
'
Me.btnBlack.Location = New System.Drawing.Point(24, 120)
Me.btnBlack.Name = "btnBlack"
Me.btnBlack.Size = New System.Drawing.Size(64, 24)
Me.btnBlack.TabIndex = 3
Me.btnBlack.Text = "Black"
'
'btnGreen
'
Me.btnGreen.Location = New System.Drawing.Point(24, 88)
Me.btnGreen.Name = "btnGreen"
Me.btnGreen.Size = New System.Drawing.Size(64, 24)
Me.btnGreen.TabIndex = 2
Me.btnGreen.Text = "Green"
'
'btnBlue
'
Me.btnBlue.Location = New System.Drawing.Point(24, 56)
Me.btnBlue.Name = "btnBlue"
Me.btnBlue.Size = New System.Drawing.Size(64, 24)
Me.btnBlue.TabIndex = 1
Me.btnBlue.Text = "Blue"
'
'btnRed
'
Me.btnRed.Location = New System.Drawing.Point(24, 24)
Me.btnRed.Name = "btnRed"
Me.btnRed.Size = New System.Drawing.Size(64, 24)
Me.btnRed.TabIndex = 0
Me.btnRed.Text = "Red"
'
'GroupBox2
'
Me.GroupBox2.BackColor = System.Drawing.SystemColor s.ScrollBa r
Me.GroupBox2.Controls.Add( Me.btnLarg e)
Me.GroupBox2.Controls.Add( Me.btnMedi um)
Me.GroupBox2.Controls.Add( Me.btnSmal l)
Me.GroupBox2.Location = New System.Drawing.Point(0, 168)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(112, 144)
Me.GroupBox2.TabIndex = 2
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "Size"
'
'btnLarge
'
Me.btnLarge.Location = New System.Drawing.Point(24, 88)
Me.btnLarge.Name = "btnLarge"
Me.btnLarge.Size = New System.Drawing.Size(64, 24)
Me.btnLarge.TabIndex = 6
Me.btnLarge.Text = "Large"
'
'btnMedium
'
Me.btnMedium.Location = New System.Drawing.Point(24, 56)
Me.btnMedium.Name = "btnMedium"
Me.btnMedium.Size = New System.Drawing.Size(64, 24)
Me.btnMedium.TabIndex = 5
Me.btnMedium.Text = "Medium"
'
'btnSmall
'
Me.btnSmall.Location = New System.Drawing.Point(24, 24)
Me.btnSmall.Name = "btnSmall"
Me.btnSmall.Size = New System.Drawing.Size(64, 24)
Me.btnSmall.TabIndex = 4
Me.btnSmall.Text = "Small"
'
'FrmPainter
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColor s.Window
Me.ClientSize = New System.Drawing.Size(536, 310)
Me.Controls.Add(Me.GroupBo x2)
Me.Controls.Add(Me.GroupBo x1)
Me.FormBorderStyle = System.Windows.Forms.FormB orderStyle .Fixed3D
Me.MaximizeBox = False
Me.Name = "FrmPainter"
Me.Text = "Drawing Panel"
Me.GroupBox1.ResumeLayout( False)
Me.GroupBox2.ResumeLayout( False)
Me.ResumeLayout(False)
End Sub
#End Region
' draw circle if shouldPaint is True
Private Sub FrmPainter_MouseMove( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.Mouse EventArgs) _
Handles MyBase.MouseMove
' paint circle if mouse pressed
If shouldPaint Then
Dim graphic As Graphics = CreateGraphics()
graphic.FillEllipse _
(New SolidBrush(Color.Red), e.X, e.Y, 4, 4)
End If
End Sub 'FrmPainter_MouseMove
' set shouldPaint to True
Private Sub FrmPainter_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.Mouse EventArgs) _
Handles MyBase.MouseDown
shouldPaint = True
End Sub ' FrmPainter_MouseDown
' set shouldPaint to False
Private Sub FrmPainter_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.Mouse EventArgs) _
Handles MyBase.MouseUp
shouldPaint = False
End Sub ' FrmPainter_MouseUp
End Class
========================== ========== ========== ========== ========== ========== ========== ========== ==
Any guidance is most appreciated. What I think the next step would be is to create some type of case control repitition, but I am having difficulty determining how this would operate.
Kind Regards,
Dan Malek
danielmalek@hotmail.com
I am working on creating a mini-paint program written in VB.NET. The program is relatively simple in nature, my issue is this...
While I can get the program to paint fine, I now want to add functionality to select one of four different paint colors (Red, Blue, Green, or Black) and one of three bursh sizes (Small, Medium, or Large).
I am completely versed in the stance of homework in Experts-Exchange and am not seeking someone to give me the correct code, instead some clear explanations and guidance would be most appreciated. My code will be posted next...
==========================
Public Class FrmPainter
Inherits System.Windows.Forms.Form
Dim shouldPaint As Boolean = False
#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.ICon
'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 GroupBox1 As System.Windows.Forms.Group
Friend WithEvents GroupBox2 As System.Windows.Forms.Group
Friend WithEvents btnBlack As System.Windows.Forms.Radio
Friend WithEvents btnGreen As System.Windows.Forms.Radio
Friend WithEvents btnBlue As System.Windows.Forms.Radio
Friend WithEvents btnRed As System.Windows.Forms.Radio
Friend WithEvents btnLarge As System.Windows.Forms.Radio
Friend WithEvents btnMedium As System.Windows.Forms.Radio
Friend WithEvents btnSmall As System.Windows.Forms.Radio
<System.Diagnostics.Debugg
Me.GroupBox1 = New System.Windows.Forms.Group
Me.btnBlack = New System.Windows.Forms.Radio
Me.btnGreen = New System.Windows.Forms.Radio
Me.btnBlue = New System.Windows.Forms.Radio
Me.btnRed = New System.Windows.Forms.Radio
Me.GroupBox2 = New System.Windows.Forms.Group
Me.btnLarge = New System.Windows.Forms.Radio
Me.btnMedium = New System.Windows.Forms.Radio
Me.btnSmall = New System.Windows.Forms.Radio
Me.GroupBox1.SuspendLayout
Me.GroupBox2.SuspendLayout
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.BackColor = System.Drawing.SystemColor
Me.GroupBox1.Controls.Add(
Me.GroupBox1.Controls.Add(
Me.GroupBox1.Controls.Add(
Me.GroupBox1.Controls.Add(
Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(112, 168)
Me.GroupBox1.TabIndex = 1
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Color"
'
'btnBlack
'
Me.btnBlack.Location = New System.Drawing.Point(24, 120)
Me.btnBlack.Name = "btnBlack"
Me.btnBlack.Size = New System.Drawing.Size(64, 24)
Me.btnBlack.TabIndex = 3
Me.btnBlack.Text = "Black"
'
'btnGreen
'
Me.btnGreen.Location = New System.Drawing.Point(24, 88)
Me.btnGreen.Name = "btnGreen"
Me.btnGreen.Size = New System.Drawing.Size(64, 24)
Me.btnGreen.TabIndex = 2
Me.btnGreen.Text = "Green"
'
'btnBlue
'
Me.btnBlue.Location = New System.Drawing.Point(24, 56)
Me.btnBlue.Name = "btnBlue"
Me.btnBlue.Size = New System.Drawing.Size(64, 24)
Me.btnBlue.TabIndex = 1
Me.btnBlue.Text = "Blue"
'
'btnRed
'
Me.btnRed.Location = New System.Drawing.Point(24, 24)
Me.btnRed.Name = "btnRed"
Me.btnRed.Size = New System.Drawing.Size(64, 24)
Me.btnRed.TabIndex = 0
Me.btnRed.Text = "Red"
'
'GroupBox2
'
Me.GroupBox2.BackColor = System.Drawing.SystemColor
Me.GroupBox2.Controls.Add(
Me.GroupBox2.Controls.Add(
Me.GroupBox2.Controls.Add(
Me.GroupBox2.Location = New System.Drawing.Point(0, 168)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(112, 144)
Me.GroupBox2.TabIndex = 2
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "Size"
'
'btnLarge
'
Me.btnLarge.Location = New System.Drawing.Point(24, 88)
Me.btnLarge.Name = "btnLarge"
Me.btnLarge.Size = New System.Drawing.Size(64, 24)
Me.btnLarge.TabIndex = 6
Me.btnLarge.Text = "Large"
'
'btnMedium
'
Me.btnMedium.Location = New System.Drawing.Point(24, 56)
Me.btnMedium.Name = "btnMedium"
Me.btnMedium.Size = New System.Drawing.Size(64, 24)
Me.btnMedium.TabIndex = 5
Me.btnMedium.Text = "Medium"
'
'btnSmall
'
Me.btnSmall.Location = New System.Drawing.Point(24, 24)
Me.btnSmall.Name = "btnSmall"
Me.btnSmall.Size = New System.Drawing.Size(64, 24)
Me.btnSmall.TabIndex = 4
Me.btnSmall.Text = "Small"
'
'FrmPainter
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColor
Me.ClientSize = New System.Drawing.Size(536, 310)
Me.Controls.Add(Me.GroupBo
Me.Controls.Add(Me.GroupBo
Me.FormBorderStyle = System.Windows.Forms.FormB
Me.MaximizeBox = False
Me.Name = "FrmPainter"
Me.Text = "Drawing Panel"
Me.GroupBox1.ResumeLayout(
Me.GroupBox2.ResumeLayout(
Me.ResumeLayout(False)
End Sub
#End Region
' draw circle if shouldPaint is True
Private Sub FrmPainter_MouseMove( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.Mouse
Handles MyBase.MouseMove
' paint circle if mouse pressed
If shouldPaint Then
Dim graphic As Graphics = CreateGraphics()
graphic.FillEllipse _
(New SolidBrush(Color.Red), e.X, e.Y, 4, 4)
End If
End Sub 'FrmPainter_MouseMove
' set shouldPaint to True
Private Sub FrmPainter_MouseDown(ByVal
ByVal e As System.Windows.Forms.Mouse
Handles MyBase.MouseDown
shouldPaint = True
End Sub ' FrmPainter_MouseDown
' set shouldPaint to False
Private Sub FrmPainter_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.Mouse
Handles MyBase.MouseUp
shouldPaint = False
End Sub ' FrmPainter_MouseUp
End Class
==========================
Any guidance is most appreciated. What I think the next step would be is to create some type of case control repitition, but I am having difficulty determining how this would operate.
Kind Regards,
Dan Malek
danielmalek@hotmail.com
I think you would start by adding in either a listbox, dropdownlist, or radio buttons that would allow the user to select which color and brush size they want to use. Then Once they select that value, store that value in some variables (ie. _selectedColor as Color and _selectedBrush as Brush) So when they set their change their settings, do a case statement to map your strings in the list to the actual color to store it. Then in your code change where you hard code the Color.red or any other reference to color to the new _selectedColor and the same with the Brush.
ASKER
If you look at the above code, I have used radio buttons but am having difficulties creating the logic...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.