Freeform drawing as in MSPaint and Paint.Net

A

André Nogueira

Hi there.
I'd like to allow the user to create some free-form drawing in my
application, in the style of Microsoft Paint (the Brush tool) or Paint.Net.
I've looked through Paint.Net's source code, but could not quite understand
it... :$
So.. what should I do? are there any tutorials?
I've got some code working, but this codes creates a non continuous line and
is kind of slow..
My code is

If desenhar = False Then Exit Sub

Static x As Integer

Static y As Integer

Me.Text = x & " " & e.X & " " & y & " " & e.Y

If e.Button = MouseButtons.Left Then

Dim caneta As New Pen(Color.Gold, 5)

Dim Imagem As Image = Me.PBoxShow.Image

Dim G As Graphics = Graphics.FromImage(imagem)

g.DrawLine(caneta, x, y, e.X, e.Y)

Me.Text = x & " " & e.X & " " & y & " " & e.Y

PBoxShow.Image = imagem

ElseIf e.Button = MouseButtons.Right Then

Dim caneta As New Pen(Color.Navy, 5)

Dim Imagem As Image = Me.PBoxShow.Image

Dim G As Graphics = Graphics.FromImage(imagem)

g.DrawLine(caneta, x, y, e.X, e.Y)

PBoxShow.Image = imagem

End If

x = e.X

y = e.Y

End Sub

Thank you in advance!
 
T

Thomas Wenning

André Nogueira said:
Hi there.
I'd like to allow the user to create some free-form drawing in my
application, in the style of Microsoft Paint (the Brush tool) or Paint.Net.
I've looked through Paint.Net's source code, but could not quite understand
it... :$
So.. what should I do? are there any tutorials?
I've got some code working, but this codes creates a non continuous line and
is kind of slow..
My code is

If desenhar = False Then Exit Sub

Static x As Integer

Static y As Integer

Me.Text = x & " " & e.X & " " & y & " " & e.Y

If e.Button = MouseButtons.Left Then

Dim caneta As New Pen(Color.Gold, 5)

Dim Imagem As Image = Me.PBoxShow.Image

Dim G As Graphics = Graphics.FromImage(imagem)

g.DrawLine(caneta, x, y, e.X, e.Y)

Me.Text = x & " " & e.X & " " & y & " " & e.Y

PBoxShow.Image = imagem

ElseIf e.Button = MouseButtons.Right Then

Dim caneta As New Pen(Color.Navy, 5)

Dim Imagem As Image = Me.PBoxShow.Image

Dim G As Graphics = Graphics.FromImage(imagem)

g.DrawLine(caneta, x, y, e.X, e.Y)

PBoxShow.Image = imagem

End If

x = e.X

y = e.Y

End Sub

Thank you in advance!

Hi Andre,

read this
http://www.eecs.wsu.edu/paint.net/downloads.html
http://www.codeproject.com/csharp/PdnNoiseEffect.asp

Greeting

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top