Groups | Blog | Home
all groups > asp.net building controls > january 2004 >

asp.net building controls : System.Drawing and GDI+ Question - Please help


Alessandro Zifiglio
1/25/2004 1:06:54 PM
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 ;)

[quoted text, click to view]

padawan
1/26/2004 12:24:15 AM
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.

padawan
1/26/2004 6:01:30 PM
Sorry, thanks.
"Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in
message news:PoOQb.7357$nC1.5313@news.edisontel.com...
[quoted text, click to view]

AddThis Social Bookmark Button