By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

System.Drawing and GDI+ Question - Please help

P: n/a
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.
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I had same problem: redrawing. There are two way
1) draw picture again (too slow)
2) draw picture to memory bitmap and then copy it to graphis object (here in your code pb1). You can zoom, resize, bend ,what ever... before you show that picture. Fast!
Here more:
http://www.informit.com/content/inde...CF5179E3CBF%7D

Juha V
Jul 21 '05 #2

P: n/a
Thanks, interesting.

Firstly I found that my problem was I was doing more than just drawing in
the overrides onpaint event and that was causing my problem, so I removed
anything that wasn't drawing in that event.

Secondly I was also drawing the rectangle to a panel control and this was
known to cause issues, so I created a new control to draw the rectangle and
I placed this on my control that had the rest of the graphical elements.

It works sweet. This site is very useful http://bobpowell.net/faqmain.htm

Thanks
"Juha Virtanen" <ju***********@elisa.fi> wrote in message
news:0B**********************************@microsof t.com...
I had same problem: redrawing. There are two way
1) draw picture again (too slow)
2) draw picture to memory bitmap and then copy it to graphis object (here in your code pb1). You can zoom, resize, bend ,what ever... before you show
that picture. Fast! Here more:
http://www.informit.com/content/inde...CF5179E3CBF%7D
Juha V

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.