paint
paint
paint
paint
paint
paint paint paint paint paint paint paint paint
paint paint
paint
Go Back  Xtreme Visual Basic Talk > > > paint


Reply
 
Thread Tools Display Modes
  #1  
Old 06-26-2007, 05:59 AM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default paint


Hello,
I'm currently working on a paint program.
My code is in the paint event handler. I wanted to know how to click on a button and that will make a new filein the program. Like in MS paint- you click new and a new file opens up.
Thanks.
Reply With Quote
  #2  
Old 06-26-2007, 08:24 AM
AtmaWeapon's Avatar
AtmaWeaponpaint AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

So what have you tried so far? You will obviously need a Menu of some type, there might happen to be controls that have names that would indicate the provide this kind of functionality...
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 06-27-2007, 02:33 AM
boops boops's Avatar
boops boops boops boops is offline
Centurion
 
Join Date: Dec 2006
Location: Holland and France
Posts: 146
Default

Hi amitairoa, since you say "the" paint event, does it mean you still have everything on a Windows Form? If so, the following ideas may help you.

A first step would be to add a new Class to your project to contain all the actual drawing and painting stuff. Define the class with Inherits PictureBox (for example). That will save you a lot of work because an instance of the new class will have all the properties and events of a PictureBox, as well as the special mouse and paint event actions you have programmed. Leave the boring things like interpreting menus and buttons and opening and closing files in the main Form.

Whenever the user opens a new file you create a new instance of the class. Then you can set its size, position, image etc. the same way as any PictureBox.

Was that the hint you needed?

All the best, BB
Reply With Quote
  #4  
Old 06-27-2007, 08:59 AM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default paint

Thanks, but I didn't really understand how to do it. Can you please explain and give me code?
Thanks!
Reply With Quote
  #5  
Old 06-27-2007, 03:39 PM
boops boops's Avatar
boops boops boops boops is offline
Centurion
 
Join Date: Dec 2006
Location: Holland and France
Posts: 146
Default

How about you showing us the code you have written so far? That way I won't have to waste time telling you things you already know -- or more things you possibly won't understand yet.

By the way, if you want to know how to put code in a forum message: put [vb] before the code and [/vb] afterwards. For more possibilities, click the link "Click for help in using vB codes" which appears at the bottom of this forum's threads list. It took me some while to discover that.

regards, BB
Reply With Quote
  #6  
Old 06-27-2007, 04:01 PM
AtmaWeapon's Avatar
AtmaWeaponpaint AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Quote:
Originally Posted by amitairoa View Post
Thanks, but I didn't really understand how to do it. Can you please explain and give me code?
Thanks!
Seriously without some more context of what you have and what you want to do the only code I can give you is this one:

Up Up Down Down Left Right Left Right B A B A Start
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #7  
Old 06-27-2007, 11:39 PM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default paint-code

Once you click a button on the screen- the boolean penciltool=true
Code:
dim mousepath as new graphicspath Private Sub form1_MouseDownp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles TabPage1.MouseDown, MyBase.MouseDown drawgraphic = TabPage1.CreateGraphics If e.Button = Windows.Forms.MouseButtons.Left Then ' draw a filled circle if left mouse is down If penciltool = True Then mousePath.StartFigure() ' The L mouse is down so we need to start a new line in mousePath ' Here is where we do the actual painting Try ' error trapping myUserColor = (ColorDialog1.Color) 'You can remove this line and add a user selected color to 'change the value of myUserColor myAlpha = 255 ' This will give the color a Alpha effect, you can set this to 255 if you want a full color 'Dim CurrentPen As Pen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Set up the pen 'CurrentPen.LineJoin = LineJoin.Round 'drawgraphic.DrawPath(CurrentPen, mousePath) 'draw the path! :) Catch ' MsgBox("Not happening!") End Try End If End If End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabPage1.MouseMove, MyBase.MouseMove drawgraphic = TabPage1.CreateGraphics If e.Button = Windows.Forms.MouseButtons.Left Then ' draw a filled circle if left mouse is down If penciltool = True Then Try mousePath.AddLine(e.X, e.Y, e.X, e.Y) 'Add mouse coordiantes to mousePath Catch MsgBox("No way, Hose!") End Try Try ' error trapping myUserColor = (ColorDialog1.Color) 'You can remove this line and add a user selected color to 'change the value of myUserColor myAlpha = 255 Dim CurrentPen As Pen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Set up the pen CurrentPen.LineJoin = LineJoin.Round drawgraphic.DrawPath(CurrentPen, mousePath) 'draw the path! :) draw = True Catch ' MsgBox("Not happening!") End Try End If End If End Sub Private Sub form11_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint 'Try ' error trapping add a user selected color to change the value of myUserColor myAlpha = 255 'Catch ' ' MsgBox("Not happening!") 'End Try End Sub
Reply With Quote
  #8  
Old 06-28-2007, 09:34 AM
AtmaWeapon's Avatar
AtmaWeaponpaint AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

So basically do you want it to clear the screen when the user clicks the New button or do you want something more like the ability to save/load files too?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #9  
Old 06-28-2007, 01:52 PM
boops boops's Avatar
boops boops boops boops is offline
Centurion
 
Join Date: Dec 2006
Location: Holland and France
Posts: 146
Cool

Right, amitairoa. I think I worked out what you want to do. You want to draw on a Tab Page, and just click on a button to add a new Tab Page when you start a new drawing. Seems like a good idea to me.

Adding a Tab Page in the usual way (using the designer or in code) won't work because it won't have access to your drawing code. So what you need to do is define a new Class which inherits TabPage. To do this, go to the Project menu in VS and select Add Class... You give it a name (I've chosen TabCanvas). Then you get a code window with the empty class. Add Inherits TabPage after the class name.

You can select empty Mouse Events from the dropdown boxes above the code window, in the same way as for a form. And that's where you put your code instead of in Form1.

Going back to Form 1, whenever you click the button for a new drawing you declare a New TabCanvas, and add it to the TabControl. An example of Form1 is also below. Also, in Form1 Designer, go to the TabControl's properties and get rid of the default TabPages: you won't need them.

Note that I just copied and pasted your own code into the Class TabCanvas events. I haven't changed it in any way except to replace TabPage1 by Me in a couple of places, to avoid a compiler error.

But that code is going to give you trouble. Your drawings will disappear whenever you change tabs. That's because you use CreateGraphics instead of putting the drawing work into TabCanvas.Paint. Perhaps you are already working on that, so try it and post again if you're not sure what I mean.

all the best, BB.

Code:
Imports System.Drawing.Drawing2D 'You can call the new class anything you like. I'll opt for "TabCanvas". Public Class TabCanvas 'The Inherits statement is the most important thing. It means that every 'instance of this class will have all the properties and methods of a 'standard TabPage -- plus the things you add yourself in the code below. Inherits TabPage 'Declare the variables that are only used in the code in this class as "Private". 'It actually means the same as Dim, but it looks better in combination with Public. Private mousePath As New GraphicsPath Private drawGraphic As Graphics Private currentPen As Pen 'Use "Public" to declare all the variables you want to reference from outside the class. 'For example, variables you want to change by clicking a button, or show in a label. '(Later you may want to replace these declarations by Properties.) Public pencilTool As Boolean Public myAlpha As Byte Public myUserColor As Color Public myPenWidth As Integer Public draw As Boolean = True 'Add a Public Sub New to initialize your variables. Public Sub New() pencilTool = True myAlpha = 255 myUserColor = Color.Black currentPen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) End Sub 'I've copied the code from your Form1's MouseDown and MouseMove events 'into this class. Change any references to "TabPage1" into "Me". Private Sub TabCanvas_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown drawGraphic = Me.CreateGraphics If e.Button = Windows.Forms.MouseButtons.Left Then ' draw a filled circle if left mouse is down If pencilTool = True Then mousePath.StartFigure() ' The L mouse is down so we need to start a new line in mousePath ' Here is where we do the actual painting Try ' error trapping myUserColor = (Form1.ColorDialog1.Color) 'You can remove this line and add a user selected color to 'change the value of myUserColor myAlpha = 255 ' This will give the color a Alpha effect, you can set this to 255 if you want a full color Catch ' MsgBox("Not happening!") End Try End If End If End Sub Private Sub TabCanvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove 'This is your own code again: drawGraphic = Me.CreateGraphics If e.Button = Windows.Forms.MouseButtons.Left Then ' draw a filled circle if left mouse is down If pencilTool = True Then Try mousePath.AddLine(e.X, e.Y, e.X, e.Y) 'Add mouse coordiantes to mousePath Catch MsgBox("No way, Hose!") End Try Try ' error trapping 'myUsercolor = (Form1.ColorDialog1.Color) 'You can remove this line and add a user selected color to 'change the value of myUserColor 'myAlpha = 255 Dim CurrentPen As Pen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Set up the pen CurrentPen.LineJoin = LineJoin.Round drawGraphic.DrawPath(CurrentPen, mousePath) 'draw the path! :) draw = True Catch ' MsgBox("Not happening!") End Try End If End If End Sub 'I won't bother to transfer your MouseUp and Paint code because there's nothing except comments in there at the moment. End Class '______________________________________________________________ 'Here's an example for your main form. Public Class Form1 Dim CurrentCanvas As TabCanvas Dim CanvasCount As Integer Private Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.Click 'Click the button to create a new TabCanvas Dim Canvas As New TabCanvas TabControl1.TabPages.Add(Canvas) 'this is the crucial command to get your canvas to display as a Tab Page. 'The TabCanvas Type has all the same properties as a TabPage, for example a Text property: CanvasCount += 1 Canvas.Text = "Canvas " & CanvasCount End Sub Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged 'CurrentCanvas is the Canvas you are working on now. You can get it like this: CurrentCanvas = CType(TabControl1.SelectedTab, TabCanvas) End Sub End Class
Reply With Quote
  #10  
Old 06-28-2007, 02:52 PM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default paint

Yes, I want that when you press a button it clears the screen, although when I tried <vb>drawgraphic.clear(colors.white)</vb>- thenit cleared but when I clicked the mouse and moved it- the drawing reappeared!
Hope you can help me!
Reply With Quote
  #11  
Old 06-28-2007, 04:47 PM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default Paint

Thanks a lot!!!!
It's working!
Reply With Quote
  #12  
Old 07-01-2007, 03:07 AM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default paint

Hi!
The tabcnvas works perfectly except for the fact that the drawing keeps disappearing like you said. Can you please help me?
Thanks!
Reply With Quote
  #13  
Old 07-01-2007, 12:07 PM
boops boops's Avatar
boops boops boops boops is offline
Centurion
 
Join Date: Dec 2006
Location: Holland and France
Posts: 146
Default

I'm glad the TabCanvas works. Now you need to give it a proper Paint event handler.

The MouseMove event was the right place for creating your MousePath variable, but the wrong place for drawing and painting commands. Get rid of CreateGraphics; throw it away as far as possible and promise never to use it again.

Instead get your graphics from the PaintEventArgs of the Paint event. Then you can put in your DrawPath command and the Pen stuff necessary to set it up:
Code:
Private Sub TabCanvas_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint 'this is where you get your graphics Dim DrawGraphic As Graphics = e.Graphics Dim CurrentPen As Pen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Set up the pen CurrentPen.LineJoin = LineJoin.Round drawGraphic.DrawPath(CurrentPen, mousePath) 'draw the path! :) End Sub
There may be some other details you need to fix but I hope you can work it out.

If you want an explanation of why you should do things this way, I recommend you have a look at Bob Powell's Graphics FAQ:
http://www.bobpowell.net/faqmain.htm.

You may find it useful to look at some examples of VB.Net drawing programs a bit similar to your own. If so, I suggest you try the VB Helper website http://vb-helper.com/search.html and search for Scribble.

They are both websites worth getting to know. All the best, BB

Last edited by boops boops; 07-01-2007 at 02:47 PM.
Reply With Quote
  #14  
Old 07-01-2007, 03:25 PM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default paint

Hi,
It works, but I need to use me.invalidate- the only problem is- I don't know where to put it! Every where I put it it makes everything flicker and gets stuck!
Can you please help me?
Thanks!
Reply With Quote
  #15  
Old 07-02-2007, 02:56 PM
boops boops's Avatar
boops boops boops boops is offline
Centurion
 
Join Date: Dec 2006
Location: Holland and France
Posts: 146
Default

Short answers: put Me.Invalidate after building the MousePath in the MouseMove event, not in the Paint event (which will hang the program). Maybe you can prevent flickering by putting Me.DoubleBuffering=True in Sub New.

regards, BB
Reply With Quote
  #16  
Old 07-03-2007, 02:35 AM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default paint

Thanks a lot! It works, but now I have a different problem:
When you click a button, a savefiledialog appears and you can save the file. When everything was on form1- after I drew, I wrote:
'drawgraphic=graphics.fromimage(bmap)'
And then When you click save I write
'bmap.save("")'
And it saved perfectly.
But now, when everythings on tabcanvas, I write
'drawgraphic=graphics.fromimage(bmap)'
-after I draw it on tabcanvas, and when I click save- it creates a file- but there's nothing in the saved file!!!
Can you please help me?!?!
Thanks!
Reply With Quote
  #17  
Old 07-03-2007, 09:47 AM
boops boops's Avatar
boops boops boops boops is offline
Centurion
 
Join Date: Dec 2006
Location: Holland and France
Posts: 146
Default

OK, amitairoa, TabCanvas needs its own bitmap to hold the image in - even when it's not showing on the screen. Then you'll be able to save and load images. You'd think it would be easy just to add Public myBitmap to the variable declarations. But that doesn't work well when you want to load a new image from a file.

This is a good example of when it's advisable to define a Property instead of a Public variable. Since a TabPage (and hence a TabCanvas) doesn't have an Image property, we are free to use that name. Besides, let's give the user a choice of scaling a new image or just trimming it to fit the TabCanvas. So add these declarations:
Code:
'This is where TabCanvas will keep the drawing: Private drawBitmap As Bitmap 'Allow users to choose scaling or not Public ScaleNewImage As Boolean 'Now for the Property definition: Public Property Image() As Bitmap Get Return drawBitmap End Get Set(ByVal value As Bitmap) If scaleNewImage = True Then 'Scale an image to fit the TabCanvas... Dim scaledImage As Image = value.GetThumbnailImage(Me.Width, Me.Height, Nothing, Nothing) '(just to keep Option Strict happy) drawBitmap = CType(scaledImage, Bitmap) Else '... or clip the image to TabCanvas size (no scaling). drawBitmap = value.Clone(Me.ClientRectangle, Imaging.PixelFormat.Format32bppArgb) End If 'Attach drawGraphic to the new bitmap so we can draw over it. drawGraphic = Graphics.FromImage(drawBitmap) 'Call the Paint event handler to draw the image on the screen. Me.Invalidate() End Set End Property
The Get part of the property is dead simple, but the Set part looks rather complicated. But once defined they are equally easy to use. For example, on Form1 you could save an image with CurrentCanvas.Image.Save(filename), or you could load an image from file with:
Code:
CurrentCanvas.ScaleNewImage = True CurrentCanvas.Image = Image.FromFile(filename)
The drawing code probably won't need changing much. As long as you do all drawing with drawGraphic.addpath, drawGraphic.FillEllipse etc. and make sure that drawGraphic stays attached to drawBitmap. Then drawBitmap will get displayed in Paint (see below).

It's still necessary to initialize drawBitmap even when you don't read it from a file. We can't do it in Sub New because that is called _before_ the TabCanvas is added to its container (TabControl1) on Form1; and until then a TabPage only has a default postage-stamp size. Instead I suggest doing it in the Paint Event - just once only, the first time the TabCanvas is painted.
Code:
Private Sub TabCanvas_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint If drawBitmap Is Nothing Then 'FIRST PAINT ONLY: 'If drawBitmap doesn't exist as an object yet, 'give the compiler enough information to reserve memory for it. drawBitmap = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height, Imaging.PixelFormat.Format32bppArgb) 'Now attach drawGraphic to the initialized bitmap. drawGraphic = Graphics.FromImage(drawBitmap) Else 'ALL OTHER TIMES: Display drawBitmap on the screen. e.Graphics.DrawImage(drawBitmap, Me.ClientRectangle) End If End Sub
I hope you can move on from here.

FOOTNOTE: I wonder whether the fact that this thread is getting so many views is because:
a) there are hordes of aspiring graphics programmers out there longing for a step-by-step tutorial on how to build a simple paint program; or
b) everybody is curious about why this unexciting thread seems to be getting so many replies and views and keeps coming to the top.
Someone please enlighten me.
Regards, BB

Last edited by boops boops; 07-03-2007 at 10:12 AM.
Reply With Quote
  #18  
Old 07-03-2007, 10:11 AM
AtmaWeapon's Avatar
AtmaWeaponpaint AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

c) His classmates are having trouble with the assignment too?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #19  
Old 07-03-2007, 11:12 AM
boops boops's Avatar
boops boops boops boops is offline
Centurion
 
Join Date: Dec 2006
Location: Holland and France
Posts: 146
Default

Nothing wrong with that, Atma, but if c) is true their teacher ought to be paying me! Still, I've enjoyed exercising my long-neglected instructional writing skills, and I've clarified a few things for myself on the way. And I like the way the program works as a kind of artist's sketchpad, where you can easily flip back and forth through the drawings. But this is taking up too much time so it's time for me to sign off from this thread.

As a consolation, I reproduce my own (working) code below. It will be interesting if all those classmates (156 of them at the last count) turn up with exactly the same solution. Probably they will all get a Fail. Let us know how it pans out, amaitaroa!

Meanwhile, for those who cannot resist the temptation....
Code:
Public Class TabCanvasForm 'The form starts off with 4 buttons, called btnNew, btnColor, and btnLoad and btnSave; plus an empty TabControl. Dim CurrentCanvas As TabCanvas Dim CanvasCount As Integer Private Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.Click 'Click the button to create a new TabCanvas Dim Canvas As New TabCanvas TabControl1.TabPages.Add(Canvas) 'this is the crucial command to get your canvas to display as a Tab Page. 'The TabCanvas type has all the same properties as a TabPage, for example a Text property: CanvasCount += 1 Canvas.Text = "Canvas " & CanvasCount CurrentCanvas = Canvas TabControl1.SelectedIndex = CanvasCount - 1 End Sub Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged 'If you have Option Strict on, you sometimes have to use Ctype to turn a TabPage into a TabCanvas. CurrentCanvas = CType(TabControl1.SelectedTab, TabCanvas) End Sub Private Sub btnColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColor.Click If CurrentCanvas IsNot Nothing Then ColorDialog1.ShowDialog() CurrentCanvas.myUserColor = ColorDialog1.Color End If End Sub Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click If CurrentCanvas IsNot Nothing Then Dim bmp As Bitmap = CType(Image.FromFile("put your own path and filename here"), Bitmap) CurrentCanvas.Image = bmp End If End Sub Private Sub btnSave_Click() 'work that one out for yourself! End Sub End Class mports System.Drawing.Drawing2D 'to make it easier to use Graphics Paths Public Class TabCanvas Inherits TabPage 'private variables Private mousePath As New GraphicsPath Private currentPen As Pen Private previousPoint As Point Private drawGraphic As Graphics Private drawBitmap As Bitmap 'public variables Public pencilTool As Boolean Public circleTool As Boolean Public myAlpha As Byte Public myUserColor As Color Public myPenWidth As Integer Public scaleNewImage As Boolean = True Public Property Image() As Bitmap Get Return drawBitmap End Get Set(ByVal value As Bitmap) If scaleNewImage = True Then 'Scale an image to fit the TabCanvas... Dim scaledImage As Image = value.GetThumbnailImage(Me.Width, Me.Height, Nothing, Nothing) '(just to keep Option Strict happy) drawBitmap = CType(scaledImage, Bitmap) Else '... or clip the image to TabCanvas size (no scaling). drawBitmap = value.Clone(Me.ClientRectangle, Imaging.PixelFormat.Format32bppArgb) End If 'Attach drawGraphic to the new bitmap so we can draw over it. drawGraphic = Graphics.FromImage(drawBitmap) 'Call the Paint event handler to draw the image on the screen. Me.Invalidate() End Set End Property Public Sub New() 'set default values for user drawing variables pencilTool = True myAlpha = 255 myUserColor = Color.Black myPenWidth = 2 Me.DoubleBuffered = True End Sub Private Sub TabCanvas_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown If e.Button = Windows.Forms.MouseButtons.Left Then If pencilTool = True Then mousePath = New GraphicsPath previousPoint = e.Location ElseIf circleTool = True Then 'code for circle tool End If End If End Sub Private Sub TabCanvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove If e.Button = Windows.Forms.MouseButtons.Left Then 'PENCIL TOOL If pencilTool = True Then Dim thisPoint As Point = e.Location mousePath.AddLine(previousPoint, thisPoint) drawGraphic = Graphics.FromImage(drawBitmap) Dim CurrentPen As Pen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Draw the line onto drawBitmap. drawGraphic.DrawPath(CurrentPen, mousePath) 'Reset previousPoint ready for the next MouseMove. previousPoint = thisPoint 'CIRCLE TOOL ElseIf circleTool = True Then 'add code for drawing a circle here End If 'do the drawing Me.Invalidate() End If End Sub Private Sub TabCanvas_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint If drawBitmap Is Nothing Then 'If drawBitmap doesn't exist as an object yet, give the compiler enough information to instantiate it. drawBitmap = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height, Imaging.PixelFormat.Format32bppArgb) drawGraphic = Graphics.FromImage(drawBitmap) Else 'If it already exists, display drawBitmap on the screen. e.Graphics.DrawImage(drawBitmap, Me.ClientRectangle) End If End Sub End Class

End Class, folks! BB
Reply With Quote
  #20  
Old 07-05-2007, 01:51 AM
amitairoa amitairoa is offline
Regular
 
Join Date: Feb 2007
Posts: 53
Default paint

Hi,
Thank you very much for helping me, everythings working. No, I do not learn in a class that teaches programming, I'm writng the paint alone.
Thanks again,
amitairoa
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
paint
paint
paint paint
paint
paint
paint paint paint paint paint paint paint
paint
paint
 
paint
paint
 
-->