VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply

Visual Basic 2008 - Make advanced paint program Rate Topic: -----

#1 eak2k  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 09


Dream Kudos: 0

Share |

Visual Basic 2008 - Make advanced paint program

Post icon  Posted 19 January 2009 - 08:10 AM

'###############
'## Copyright (C)	##
'## EaK2k  2008	 ##
'## All rights		  ##
'## Reserved		##
'#############
Public Class Form1
	Dim xStart, yStart, xEnd, yEnd As Integer
	Dim Drawbitmap As Bitmap
	Dim Drawgraphics As Graphics
	Dim myPen As New Pen(Color.BlueViolet, 3)
	Dim myColor As Color = Color.Blue
	Dim myBrush As New Drawing.SolidBrush(Color.Red)
	Dim myBrushWidth As Integer
	Dim ContinuousFlag As Boolean

	Private Sub drawMyline()
		PictureBox1.Image = Drawbitmap
		Drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
		Drawgraphics.DrawLine(myPen, xStart, yStart, xEnd, yEnd)
	End Sub

	Private Sub savebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		SaveFileDialog1.ShowDialog()
		If SaveFileDialog1.FileName <> "" Then
			FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
			FileClose(1)
		End If
	End Sub

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Drawbitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
		Drawgraphics = Graphics.FromImage(Drawbitmap)
		PictureBox1.Image = Drawbitmap
		Drawgraphics.Clear(Color.White)
		myBrushWidth = 4
	End Sub 
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
		xStart = Control.MousePosition.X - (Me.Left + PictureBox1.Left + 4)
		yStart = Control.MousePosition.Y - (Me.Top + PictureBox1.Top + 31)
		'to do continuous drawing, enable this line 
		'drawMyline()
		If RadioButton1.Checked = True Then
			ContinuousFlag = True
		End If
	End Sub

	Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
		If ContinuousFlag Then
			Drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.None
			Drawgraphics.FillEllipse(myBrush, e.X, e.Y, myBrushWidth, myBrushWidth)
			PictureBox1.Image = Drawbitmap
		End If
	End Sub

	Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
		xEnd = Control.MousePosition.X - (Me.Left + PictureBox1.Left + 4)
		yEnd = Control.MousePosition.Y - (Me.Top + PictureBox1.Top + 31)

		If RadioButton1.Checked Then
			ContinuousFlag = False
		Else
			drawMyline()
		End If
	End Sub



part of my code, rest of my code is the colors and clear the image area!
Now the question:
How can I make a OPEN DIALOG when the save dialog look like this:
 Dim Savefiledialog1 As New SaveFileDialog()
		Savefiledialog1.Filter = "Bitmap Image (*.bmp)|*.bmp |All Files |*.*"
		If Savefiledialog1.ShowDialog() = DialogResult.OK Then
			PictureBox1.Image.Save(Savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
		End If



Next, can I make a color dialog?
Also, when I tried the program, the painting don't goes "smooth" its like dotted.
How can I fix that?

Probably more questions is coming :D
Was This Post Helpful? 0
  • +
  • -


#2 Shadow_x21  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 15-September 08


Dream Kudos: 0

Re: Visual Basic 2008 - Make advanced paint program

Posted 19 January 2009 - 04:00 PM

weell i did not understand wtf u want but here goes...

this is to open a file


Dim openfiledialog1 As New openFileDialog()
		openfiledialog1.Filter = "Bitmap Image (*.bmp)|*.bmp |All Files |*.*"
		If openfiledialog1.ShowDialog() = DialogResult.OK Then
			PictureBox1.Image = image.fromfile(openfiledialog1.FileName)
		End If


and heres an example on da colordialog
Dim colordialog2 As New ColorDialog
		If colordialog2.ShowDialog = Windows.Forms.DialogResult.OK Then
			Form1.BackColor = colordialog2.Color
		End If



i dont know y your painting the is dotted...the smoothingmode.highquality should have helped it. make sure u dont have a dashstyle or something goin on
Was This Post Helpful? 0
  • +
  • -

#3 eak2k  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 09


Dream Kudos: 0

Re: Visual Basic 2008 - Make advanced paint program

Posted 20 January 2009 - 06:43 AM

Thx for answerer me!

You didn't understand, should I post more of the code? :P
I choose a color in the color dialog and then I want the pencil to be that color I chosen.
How can I do that?

About the dotted pencil, how can I fix that?

EDIT:
Tested open function, problems :o
I can't find the files that I already saved at desktop. How to fix it?

This post has been edited by eak2k: 20 January 2009 - 06:51 AM

Was This Post Helpful? 0
  • +
  • -

#4 eak2k  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-January 09


Dream Kudos: 0

Re: Visual Basic 2008 - Make advanced paint program

Posted 21 January 2009 - 06:18 AM

Any help please?
Was This Post Helpful? 0
  • +
  • -

#5 mrmcpott  Icon User is offline

  • D.I.C Head
  • Icon

Reputation: 3
  • View blog
  • Posts: 95
  • Joined: 24-November 08


Dream Kudos: 50

Re: Visual Basic 2008 - Make advanced paint program

Posted 22 January 2009 - 12:20 PM

Please post more detail about your question/problem. We would love to help; we can only help you if we know exactly what you are asking.

Are you trying to open a simple picture file to edit, etc?
Was This Post Helpful? 0
  • +
  • -

#6 Rolzac  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-February 09


Dream Kudos: 0

Re: Visual Basic 2008 - Make advanced paint program

Posted 18 February 2009 - 09:01 AM

This was really helpful thanks.
When I tried this though, i could not reload the saved bitmap and then draw over it.

I tried to load the bitmap into the picture box from the picture properties, then copied the picturebox to my bit map like this:-

Drawbitmap = PictureBox1.Image

the image was seen in my picture box, but i could not draw onto it.

Is there a way I can do this

I am new at vb.net 2008, am struggling, but making good headway.

thanks

Roland
Was This Post Helpful? 0
  • +
  • -

#7 daviga404  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-June 09


Dream Kudos: 0

Re: Visual Basic 2008 - Make advanced paint program

Posted 27 June 2009 - 04:12 AM

View Posteak2k, on 19 Jan, 2009 - 08:10 AM, said:

'###############
'## Copyright (C)	##
'## EaK2k  2008	 ##
'## All rights		  ##
'## Reserved		##
'#############
Public Class Form1
	Dim xStart, yStart, xEnd, yEnd As Integer
	Dim Drawbitmap As Bitmap
	Dim Drawgraphics As Graphics
	Dim myPen As New Pen(Color.BlueViolet, 3)
	Dim myColor As Color = Color.Blue
	Dim myBrush As New Drawing.SolidBrush(Color.Red)
	Dim myBrushWidth As Integer
	Dim ContinuousFlag As Boolean

	Private Sub drawMyline()
		PictureBox1.Image = Drawbitmap
		Drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
		Drawgraphics.DrawLine(myPen, xStart, yStart, xEnd, yEnd)
	End Sub

	Private Sub savebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		SaveFileDialog1.ShowDialog()
		If SaveFileDialog1.FileName <> "" Then
			FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
			FileClose(1)
		End If
	End Sub

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Drawbitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
		Drawgraphics = Graphics.FromImage(Drawbitmap)
		PictureBox1.Image = Drawbitmap
		Drawgraphics.Clear(Color.White)
		myBrushWidth = 4
	End Sub 
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
		xStart = Control.MousePosition.X - (Me.Left + PictureBox1.Left + 4)
		yStart = Control.MousePosition.Y - (Me.Top + PictureBox1.Top + 31)
		'to do continuous drawing, enable this line 
		'drawMyline()
		If RadioButton1.Checked = True Then
			ContinuousFlag = True
		End If
	End Sub

	Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
		If ContinuousFlag Then
			Drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.None
			Drawgraphics.FillEllipse(myBrush, e.X, e.Y, myBrushWidth, myBrushWidth)
			PictureBox1.Image = Drawbitmap
		End If
	End Sub

	Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
		xEnd = Control.MousePosition.X - (Me.Left + PictureBox1.Left + 4)
		yEnd = Control.MousePosition.Y - (Me.Top + PictureBox1.Top + 31)

		If RadioButton1.Checked Then
			ContinuousFlag = False
		Else
			drawMyline()
		End If
	End Sub



part of my code, rest of my code is the colors and clear the image area!
Now the question:
How can I make a OPEN DIALOG when the save dialog look like this:
 Dim Savefiledialog1 As New SaveFileDialog()
		Savefiledialog1.Filter = "Bitmap Image (*.bmp)|*.bmp |All Files |*.*"
		If Savefiledialog1.ShowDialog() = DialogResult.OK Then
			PictureBox1.Image.Save(Savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
		End If



Next, can I make a color dialog?
Also, when I tried the program, the painting don't goes "smooth" its like dotted.
How can I fix that?

Probably more questions is coming :D


The reason that it is coming up dotted is because:
When you hold down your mouse and move even a pixel, it makes an ellipse, usually, when you move your mouse you skip lots of pixels. therefore, it will skip that area and not draw an ellipse there. I don't know how to fix this, but at least it will give you an idea of what's gone wrong.
Daviga404 :)
Was This Post Helpful? 0
  • +
  • -

#8 billy bob joe  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 06-March 10


Dream Kudos: 0

Re: Visual Basic 2008 - Make advanced paint program

Posted 06 March 2010 - 04:08 PM

View Postdaviga404, on 27 June 2009 - 04:12 AM, said:

View Posteak2k, on 19 Jan, 2009 - 08:10 AM, said:

'###############
'## Copyright (C)	##
'## EaK2k  2008	 ##
'## All rights		  ##
'## Reserved		##
'#############
Public Class Form1
	Dim xStart, yStart, xEnd, yEnd As Integer
	Dim Drawbitmap As Bitmap
	Dim Drawgraphics As Graphics
	Dim myPen As New Pen(Color.BlueViolet, 3)
	Dim myColor As Color = Color.Blue
	Dim myBrush As New Drawing.SolidBrush(Color.Red)
	Dim myBrushWidth As Integer
	Dim ContinuousFlag As Boolean

	Private Sub drawMyline()
		PictureBox1.Image = Drawbitmap
		Drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
		Drawgraphics.DrawLine(myPen, xStart, yStart, xEnd, yEnd)
	End Sub

	Private Sub savebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		SaveFileDialog1.ShowDialog()
		If SaveFileDialog1.FileName <> "" Then
			FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
			FileClose(1)
		End If
	End Sub

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Drawbitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
		Drawgraphics = Graphics.FromImage(Drawbitmap)
		PictureBox1.Image = Drawbitmap
		Drawgraphics.Clear(Color.White)
		myBrushWidth = 4
	End Sub 
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
		xStart = Control.MousePosition.X - (Me.Left + PictureBox1.Left + 4)
		yStart = Control.MousePosition.Y - (Me.Top + PictureBox1.Top + 31)
		'to do continuous drawing, enable this line 
		'drawMyline()
		If RadioButton1.Checked = True Then
			ContinuousFlag = True
		End If
	End Sub

	Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
		If ContinuousFlag Then
			Drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.None
			Drawgraphics.FillEllipse(myBrush, e.X, e.Y, myBrushWidth, myBrushWidth)
			PictureBox1.Image = Drawbitmap
		End If
	End Sub

	Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
		xEnd = Control.MousePosition.X - (Me.Left + PictureBox1.Left + 4)
		yEnd = Control.MousePosition.Y - (Me.Top + PictureBox1.Top + 31)

		If RadioButton1.Checked Then
			ContinuousFlag = False
		Else
			drawMyline()
		End If
	End Sub



part of my code, rest of my code is the colors and clear the image area!
Now the question:
How can I make a OPEN DIALOG when the save dialog look like this:
 Dim Savefiledialog1 As New SaveFileDialog()
		Savefiledialog1.Filter = "Bitmap Image (*.bmp)|*.bmp |All Files |*.*"
		If Savefiledialog1.ShowDialog() = DialogResult.OK Then
			PictureBox1.Image.Save(Savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
		End If



Next, can I make a color dialog?
Also, when I tried the program, the painting don't goes "smooth" its like dotted.
How can I fix that?

Probably more questions is coming :D


The reason that it is coming up dotted is because:
When you hold down your mouse and move even a pixel, it makes an ellipse, usually, when you move your mouse you skip lots of pixels. therefore, it will skip that area and not draw an ellipse there. I don't know how to fix this, but at least it will give you an idea of what's gone wrong.
Daviga404 :)


To make it not dotted, just replace the DrawEllipse part (MouseMove) with this code:
If Not smootherLocation = New Point(0, 0) Then
    Drawgraphics.DrawLine(myPen, smootherLocation.X, smootherLocation.Y, e.X, e.Y)
End If
smootherLocation = New Point(e.X, e.Y)



Then add the smootherLocation point in declarations area:
Dim smootherLocation As New Point(0, 0)



This makes it draw a line from your previous location to the current one. Now add this code to PictureBox1's MouseUp event:
smootherLocation = New Point(0, 0)



Now this makes it so you don't draw a line from one free drawn shape to the one your making.
Correct me if I'm wrong... :/

This post has been edited by billy bob joe: 06 March 2010 - 04:10 PM

Was This Post Helpful? 1
  • +
  • -

#9 Akkeresu  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-March 10


Dream Kudos: 0

Re: Visual Basic 2008 - Make advanced paint program

Posted 21 March 2010 - 10:18 AM

View Postbilly bob joe, on 06 March 2010 - 04:08 PM, said:

To make it not dotted, just replace the DrawEllipse part (MouseMove) with this code:
If Not smootherLocation = New Point(0, 0) Then
    Drawgraphics.DrawLine(myPen, smootherLocation.X, smootherLocation.Y, e.X, e.Y)
End If
smootherLocation = New Point(e.X, e.Y)



Then add the smootherLocation point in declarations area:
Dim smootherLocation As New Point(0, 0)



This makes it draw a line from your previous location to the current one. Now add this code to PictureBox1's MouseUp event:
smootherLocation = New Point(0, 0)



Now this makes it so you don't draw a line from one free drawn shape to the one your making.
Correct me if I'm wrong... :/


It seems like the smoothing still wants to create the additional lines. Any ideas for how to fix this?

Attached thumbnail(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#10 Akkeresu  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-March 10


Dream Kudos: 0

Re: Visual Basic 2008 - Make advanced paint program

Posted 23 March 2010 - 06:20 AM

Hey y'all! I got the program working a bit better. It's not the best, but it'll have some elements that others can full from this too.

Public Class PaintForm
    Dim xStart, yStart, xEnd, yEnd As Integer
    Dim Drawbitmap As Bitmap
    Dim Drawgraphics As Graphics
    Dim myPen As New Pen(Color.Black, 4)
    Dim myColor As Color = Color.Black
    Dim myPenWidth As Integer
    Dim myBGColor As Color = Color.White
    Dim Drawing As Boolean
    Private Sub drawMyline()
        PictureBox1.Image = Drawbitmap
        Drawgraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        Drawgraphics.DrawLine(myPen, xStart, yStart, xEnd, yEnd)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Drawbitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
        Drawgraphics = Graphics.FromImage(Drawbitmap)
        PictureBox1.Image = Drawbitmap
        Drawgraphics.Clear(Color.White)
        xStart = -1
        yStart = -1
        Drawing = False
        myPenWidth = 4
    End Sub
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        Drawing = True
    End Sub
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If Drawing Then
            xStart = e.X
            yStart = e.Y
            drawMyline()
        End If
        xEnd = e.X
        yEnd = e.Y
    End Sub
    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        Drawing = False
    End Sub
    Private Sub widthUD_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles widthUD.ValueChanged
        myPenWidth = widthUD.Value
        myPen = New Pen(myColor, myPenWidth)
    End Sub

    Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click
        Drawgraphics.Clear(myBGColor)
        PictureBox1.Image = Drawbitmap
    End Sub

    Private Sub colorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles colorButton.Click
        Me.ColorDialog1.ShowDialog()
        myColor = ColorDialog1.Color
        myPen = New Pen(myColor, myPenWidth)
    End Sub

    Private Sub saveButton_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveButton.Click
        SaveFileDialog1.Filter = "Bitmap Image (*.bmp)|*.bmp |All Files |*.*"
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            PictureBox1.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
        End If
    End Sub

    Private Sub bgcolorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bgcolorButton.Click
        Me.ColorDialog1.ShowDialog()
        myBGColor = ColorDialog1.Color
        Drawgraphics.Clear(myBGColor)
        PictureBox1.Image = Drawbitmap
    End Sub

    Private Sub eraserButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eraserButton.Click
        myColor = Color.White
        myPen = New Pen(myColor, myPenWidth)
    End Sub
End Class




Feel free to add your opinions to make this program smoother. ^^

Attached thumbnail(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users