graphics won't appear in tab window

urbycoz

New member
Joined
Jul 29, 2007
Messages
3
Programming Experience
Beginner
I'm new to VB.net, and I'm trying to create make program that draws shapes. The trouble is, I'm using tabs and the shapes appear in the background, rather than within the tab window.

eg.

Public Sub draw_Rectangle(ByVal frm As Windows.Forms.Form)
Dim objGraphics As Graphics
Dim recDrawRectangle As Rectangle
recDrawRectangle = frm.DisplayRectangle
recDrawRectangle.Inflate(-80, -120)
objGraphics = frm.CreateGraphics
objGraphics.Clear(System.Drawing.SystemColors.Control)
objGraphics.DrawRectangle(System.Drawing.Pens.Black, recDrawRectangle)
objGraphics.FillRectangle(System.Drawing.Brushes.Blue, recDrawRectangle)
objGraphics.Dispose()
End Sub

How do I make the shapes appear in the tab window?
 
Handle the Paint event of the TabPage, use e.Graphics to draw. Use the Refresh/Invalidate methods of the TabPage if you want to request redraw at specific times.
 
I'm new to VB.net, and I'm trying to create make program that draws shapes. The trouble is, I'm using tabs and the shapes appear in the background, rather than within the tab window.

eg.

Public Sub draw_Rectangle(ByVal frm As Windows.Forms.Form)
Dim objGraphics As Graphics
Dim recDrawRectangle As Rectangle
recDrawRectangle = frm.DisplayRectangle
recDrawRectangle.Inflate(-80, -120)
objGraphics = frm.CreateGraphics
objGraphics.Clear(System.Drawing.SystemColors.Control)
objGraphics.DrawRectangle(System.Drawing.Pens.Black, recDrawRectangle)
objGraphics.FillRectangle(System.Drawing.Brushes.Blue, recDrawRectangle)
objGraphics.Dispose()
End Sub

How do I make the shapes appear in the tab window?

You are saying "objGraphics = frm.CreateGrahpics". Your telling Visual Basic to set your "canvas" if you will, to be your form. You need to say "objGraphics = Me.TabPage1.CreateGraphics()" so you can tell VB to set your canvas to be your TabPage.
 
You are saying "objGraphics = frm.CreateGrahpics". Your telling Visual Basic to set your "canvas" if you will, to be your form. You need to say "objGraphics = Me.TabPage1.CreateGraphics()" so you can tell VB to set your canvas to be your TabPage.
The Graphics instance that CreateGraphics returns is not intended to be used for drawing. Handle the appropriate Paint event.
 
Because at any time will the controls Paint event fire then what you just drew will disappear.
 
Back
Top