C
Colin McGuire
Hi there. I have written a small procedure to draw various shapes on
things. A bit of it is shown below.
Private Sub drawShape(ByVal shapeType As Integer, ByRef g As Graphics)
Select Case shapeType
Case 1 : g.DrawRectangle(New Pen(Color.Black), 0, 0, 50, 10)
Case 2 'draw a circle
Case 3 'draw a triangle
Case 4 'draw other shape
Case 5 'draw other shape
Case 6 'draw other shape
Case Else 'etc. draw other shapes
End Select
End Sub
If on Form1, I override the OnPaint method with
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
drawShape(1, e.Graphics)
End Sub
it paints my rectangle as I would expect drawing it on Form1 at 0,0
with width 50 and height 10.
I have lots of other controls on the form, such as buttons, labels,
groupboxes etc. My question is how do I get 'g' (a valid Graphics
instance) for the buttons, labels, groupboxes and other things.
The obvious thing I tried below doesn't work (I see no rectangle on
the GroupBox, called GroupBox1) but still see the rectangle on the
form. I want to see both.
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
drawShape(1, e.Graphics)
drawShape(1, Me.GroupBox1.Creategraphics())
End Sub
Thank you in advance for all your help and sorry to post more of these
verbose and tricky questions.
Colin
things. A bit of it is shown below.
Private Sub drawShape(ByVal shapeType As Integer, ByRef g As Graphics)
Select Case shapeType
Case 1 : g.DrawRectangle(New Pen(Color.Black), 0, 0, 50, 10)
Case 2 'draw a circle
Case 3 'draw a triangle
Case 4 'draw other shape
Case 5 'draw other shape
Case 6 'draw other shape
Case Else 'etc. draw other shapes
End Select
End Sub
If on Form1, I override the OnPaint method with
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
drawShape(1, e.Graphics)
End Sub
it paints my rectangle as I would expect drawing it on Form1 at 0,0
with width 50 and height 10.
I have lots of other controls on the form, such as buttons, labels,
groupboxes etc. My question is how do I get 'g' (a valid Graphics
instance) for the buttons, labels, groupboxes and other things.
The obvious thing I tried below doesn't work (I see no rectangle on
the GroupBox, called GroupBox1) but still see the rectangle on the
form. I want to see both.
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
drawShape(1, e.Graphics)
drawShape(1, Me.GroupBox1.Creategraphics())
End Sub
Thank you in advance for all your help and sorry to post more of these
verbose and tricky questions.
Colin