How to make an advanced paint program! *UPDATED!*

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
7 posts Page 1 of 1
Was this post usefull?

No votes
Oh Yea!
20%
Yes
1
20%
Kinda
1
60%
Not Really
3
No votes
No
No votes
Not even close!!!

Total votes: 5

Contributors
User avatar
dradra43
New Member
New Member
Posts: 13
Joined: Sat Nov 06, 2010 9:56 pm

Level = ★★★☆☆

Hello, and welcome to my FIRST tutorial! I hope you find this usefull!

Ok, today we will learn how to make a simple paint program! This program will have 15 color's to choose from. You can add more if you would like.

Ok, lets begin! First you'll need two forms!

On form1 it will be JUST a picture box. make it to your fittings(Sizable, maximizable, etc...)

On form2 it there should be no controlbox, and the text is: Options

Form2 will contain:

16 labels, all the text blank and do the following:

Label1 - change the back-color to red, then change the name to Red
Label2 - change the back-color to blue, then change the name to Blue
Label3 - change the back-color to yellow, then change the name to Yellow
Label4 - change the back-color to lime, then change the name to Lime
Label5 - change the back-color to purple, then the name to Purple
Label6 - change the back-color to silver, then the name to Silver
label7 - change the back-color to gray, then the name to Gray
label8 - change the back-color to green, then the name to Green
label9 - change the back-color to maroon, then the name to Maroon
Label10 - change the back-color to black, then the name to Black
Label11 - change the back-color to fuchsia, then the name to Fuchsia
label12 - change the back-color to cyan, then the name to Cyan
Label13 - change the back-color to teal, then the name to Teal
Label14 - change the back-color to navy, then the name to Navy
label15 - change the back-color to white, then the name to White
Label16 - change the back-color to white, then the name to MainColor
FOR ALL LABELS DELETE ALL TEXTS!!!!


1 textbox (out of view of everyone) - Text should be - "b"

4 buttons
  • button1.text = "Clear"
    button2.text = "SunRays"
    button3.text = "Brush"
    button4.text = "Pencil"
(I would add a picture but i do not know how with HTML :cry: )

ok, now for Form2's coding:
Code: Select all
Public Class Form2

    Private Sub White_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles White.Click
        MainColor.BackColor = Color.White
    End Sub

    Private Sub Lime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Lime.Click
        MainColor.BackColor = Color.Lime
    End Sub

    Private Sub Red_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Red.Click
        MainColor.BackColor = Color.Red
    End Sub

    Private Sub Yellow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Yellow.Click
        MainColor.BackColor = Color.Yellow
    End Sub

    Private Sub Cyan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cyan.Click
        MainColor.BackColor = Color.Cyan
    End Sub

    Private Sub Blue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Blue.Click
        MainColor.BackColor = Color.Blue
    End Sub

    Private Sub Fuchsia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fuchsia.Click
        MainColor.BackColor = Color.Fuchsia
    End Sub

    Private Sub Teal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Teal.Click
        MainColor.BackColor = Color.Teal
    End Sub

    Private Sub Navy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Navy.Click
        MainColor.BackColor = Color.Navy
    End Sub

    Private Sub Purple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Purple.Click
        MainColor.BackColor = Color.Purple
    End Sub

    Private Sub Green_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Green.Click
        MainColor.BackColor = Color.Green
    End Sub

    Private Sub Maroon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Maroon.Click
        MainColor.BackColor = Color.Maroon
    End Sub

    Private Sub Silver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Silver.Click
        MainColor.BackColor = Color.Silver
    End Sub

    Private Sub Gray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Gray.Click
        MainColor.BackColor = Color.Gray
    End Sub

    Private Sub Black_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Black.Click
        MainColor.BackColor = Color.Black
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.PictureBox1.Image = Nothing
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Form1.PictureBox1.CreateGraphics.RotateTransform(10)
    End Sub

    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = "l"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = "b"
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Text = "p"
    End Sub

End Class
Form1 coding time!
Code: Select all
Public Class Form1
    Dim down = False

    Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
        If down = True Then
            If Form2.TextBox1.Text = "b" Then
                If Form2.MainColor.BackColor = Color.Black Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Black, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.White Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.White, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Red Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Red, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Green Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Green, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Yellow Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Yellow, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Purple Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Purple, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Gray Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Gray, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Silver Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Silver, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Maroon Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Maroon, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Fuchsia Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Fuchsia, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Cyan Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Cyan, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Teal Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Teal, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Navy Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Navy, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Lime Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Lime, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Blue Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Blue, e.X, e.Y, 15, 15)
                End If
            End If
            If Form2.TextBox1.Text = "p" Then
                If Form2.MainColor.BackColor = Color.Black Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Black, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.White Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.White, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Red Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Red, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Green Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Green, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Yellow Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Yellow, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Purple Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Purple, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Gray Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Gray, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Silver Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Silver, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Maroon Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Maroon, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Fuchsia Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Fuchsia, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Cyan Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Cyan, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Teal Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Teal, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Navy Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Navy, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Lime Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Lime, e.X, e.Y, 3, 1)
                End If
                If Form2.MainColor.BackColor = Color.Blue Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Blue, e.X, e.Y, 3, 1)
                End If
            End If
            If Form2.TextBox1.Text = "l" Then
                If Form2.MainColor.BackColor = Color.Black Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Black, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.White Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.White, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Red Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Red, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Green Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Green, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Yellow Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Yellow, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Purple Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Purple, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Gray Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Gray, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Silver Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Silver, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Maroon Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Maroon, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Fuchsia Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Fuchsia, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Cyan Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Cyan, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Teal Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Teal, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Navy Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Navy, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Lime Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Lime, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Blue Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Blue, e.X, e.Y, 15, 15)
                End If
            End If
        End If
    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        down = True
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If down = True Then
            If Form2.TextBox1.Text = "b" Then
                If Form2.MainColor.BackColor = Color.Black Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Black, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.White Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.White, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Red Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Red, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Green Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Green, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Yellow Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Yellow, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Purple Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Purple, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Gray Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Gray, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Silver Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Silver, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Maroon Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Maroon, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Fuchsia Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Fuchsia, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Cyan Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Cyan, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Teal Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Teal, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Navy Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Navy, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Lime Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Lime, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Blue Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Blue, e.X, e.Y, 15, 15)
                End If
            End If
            If Form2.TextBox1.Text = "p" Then
                If Form2.MainColor.BackColor = Color.Black Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Black, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.White Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.White, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Red Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Red, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Green Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Green, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Yellow Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Yellow, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Purple Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Purple, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Gray Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Gray, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Silver Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Silver, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Maroon Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Maroon, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Fuchsia Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Fuchsia, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Cyan Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Cyan, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Teal Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Teal, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Navy Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Navy, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Lime Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Lime, e.X, e.Y, 5, 5)
                End If
                If Form2.MainColor.BackColor = Color.Blue Then
                    PictureBox1.CreateGraphics.FillEllipse(Brushes.Blue, e.X, e.Y, 5, 5)
                End If
            End If
            If Form2.TextBox1.Text = "l" Then
                If Form2.MainColor.BackColor = Color.Black Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Black, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.White Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.White, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Red Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Red, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Green Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Green, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Yellow Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Yellow, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Purple Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Purple, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Gray Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Gray, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Silver Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Silver, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Maroon Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Maroon, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Fuchsia Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Fuchsia, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Cyan Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Cyan, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Teal Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Teal, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Navy Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Navy, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Lime Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Lime, e.X, e.Y, 15, 15)
                End If
                If Form2.MainColor.BackColor = Color.Blue Then
                    PictureBox1.CreateGraphics.DrawLine(Pens.Blue, e.X, e.Y, 15, 15)
                End If
            End If
        End If
    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        down = False
    End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Form2.Close()
        End
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form2.Show()
    End Sub
End Class

Hope I helped!
Have fun with visual basic!


Image
You do not have the required permissions to view the files attached to this post.
Last edited by dradra43 on Mon Dec 06, 2010 1:32 am, edited 14 times in total.
Image
Image
Image
~VB CODER~
User avatar
TheSecretBoy
Top Poster
Top Poster
Posts: 195
Joined: Wed Jun 09, 2010 9:39 am

Hello dradra43
Nice tutorial and i hope you make it more professional
but nice for the first tut..

Keep it up > ( its basic :lol: )
Code'N'Stuff
TheSecretBoY
Dont forget to give thanks for those helpful posts cooll;
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Hello dradra43,

Pretty good for your first tutorial the instructions are clear and it works well. You forgot to include code to access form2 though but I just added a button "Form2.Show()"
sshot-25.png
Keep it up cooll;
You do not have the required permissions to view the files attached to this post.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
dradra43
New Member
New Member
Posts: 13
Joined: Sat Nov 06, 2010 9:56 pm

CodenStuff wrote:
Hello dradra43,

Pretty good for your first tutorial the instructions are clear and it works well. You forgot to include code to access form2 though but I just added a button "Form2.Show()"
sshot-25.png
Keep it up cooll;
I just updated it, its a lot more advanced! Please check it out and see if you like it, and see if I am on the right track on the coding spree. =D Have a good-night codenstuff!
Image
Image
Image
~VB CODER~
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

There are a few ways you could shorten your code by sharing events between controls:
Code: Select all
       MainColor.BackColor = Color.FromName(sender.Text) 'For the label parts
You can also set the pens and brushes with 1 line of code each:
Code: Select all
'examples
        Dim p As Pen = New Pen(Form2.MainColor.BackColor)

        Dim br As Brush = New SolidBrush(Form2.MainColor.BackColor)
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

i think it would be alot easyer if you did select case instead of all those if statements :P

Select case Form2.Maincolor.Backcolor
case cyan
'command
case black
'command
case red
'command
exit select
http://vagex.com/?ref=25000
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

I'd do it this way:
Code: Select all
    Private Sub labels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles White.Click, Lime.Click, Red.Click, Yellow.Click, Cyan.Click, Blue.Click, Fuchsia.Click, Teal.Click, Navy.Click, Purple.Click, Green.Click, Maroon.Click, Silver.Click, Gray.Click, Black.Click
        MainColor.BackColor = Color.FromName(sender.Text)
    End Sub

    Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
        If down Then
            Dim width, height As Integer

            If Form2.TextBox1.Text = "b" Or Form2.TextBox1.Text = "l" Then
                width = 15
                height = 15
            Else 'p
                width = 3
                height = 1
            End If

            If Form2.TextBox1.Text = "b" Or Form2.TextBox1.Text = "p" Then
                Dim br As Brush = New SolidBrush(Form2.MainColor.BackColor)
                PictureBox1.CreateGraphics.FillEllipse(br, e.X, e.Y, width, height)
            Else 'l
                Dim p As Pen = New Pen(Form2.MainColor.BackColor)
                PictureBox1.CreateGraphics.DrawLine(p, e.X, e.Y, width, height)
            End If


        End If

    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If down Then
            Dim height, width As Integer

            If Form2.TextBox1.Text = "b" Or Form2.TextBox1.Text = "l" Then
                height = 15
                width = 15
            Else 'p
                width = 5
                height = 5
            End If

            If Form2.TextBox1.Text = "b" Or Form2.TextBox1.Text = "p" Then
                Dim br As Brush = New SolidBrush(Form2.MainColor.BackColor)
                PictureBox1.CreateGraphics.FillEllipse(br, e.X, e.Y, width, height)
            Else 'l
                Dim p As Pen = New Pen(Form2.MainColor.BackColor)
                PictureBox1.CreateGraphics.DrawLine(p, e.X, e.Y, width, height)
            End If

        End If
    End Sub
7 posts Page 1 of 1
Return to “Tutorials”