System.Drawing and GDI+ Question - Please help

P

padawan

I have a winforms control that draws a rectangle for a boarder and positions
some graphical elements around the control to create the boarder effect I
desired. In the control I have overriden the onpaint event and added the
code to draw my rectangle and position my graphic items:

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

e.Graphics.Clear(Color.FromArgb(255, 255, 255))

MyBase.OnPaint(e)

Dim g As Graphics = pb1.CreateGraphics

pb1.CreateGraphics.Clear(Color.FromArgb(255, 255, 255))

Dim myPen As System.Drawing.Pen = New System.Drawing.Pen(Color.FromArgb(187,
191, 115))

g.DrawRectangle(myPen, New Rectangle(0, 0, pb1.Width - 1, pb1.Height - 1))

pb1.Width = (Me.Width - 34)

pb1.Height = (Me.Height - 29)

tr.Left = (Me.Width - 32)

br.Left = (Me.Width - 32)

br.Top = (Me.Height - 24)

bl.Top = (Me.Height - 24)

End Sub

Also I have added this line to the Public sub new call of the control:

SetStyle(ControlStyles.ResizeRedraw, True)

As you can see the rectangle is being drawn on a panel control called "pb1".

When I drag this control onto a Windows form in Visual Studio the rectangle
is drawn and behaves as it should when resized etc. However if I switch to
antother tab and switch back the rectangle disapears, this is also the case
when the solution is compiled the form initializes with no rectangle. Can
somebody please help me or point me in the right direction.
 
A

Alessandro Zifiglio

I'm not sure if you noticed but you just posted a windows forms question in
an asp.net news group ;P

You will get proper help if you posted in the appropriate news group ;)
 
P

padawan

Sorry, thanks.
Alessandro Zifiglio said:
I'm not sure if you noticed but you just posted a windows forms question in
an asp.net news group ;P

You will get proper help if you posted in the appropriate news group ;)
 

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

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,079
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top