473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Paint event of a panel

I have a panel that I have in the paint event to draw a Raised 3d border
around it.. The problem is, if a msgbox is popped up or a tooltip is
displayed, it leaves lines on the panel. I've tried invalidate after the
msgbox to no avail...

Here is the event:
Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle,
Border3DStyle.Raised)
End Sub

I've tried calling the base event too, which seemed to do nothing..

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #1
4 11649
Firstly, don't draw borders in the paint event. Add a border to the object
using the window properties or handle the non-client messages correctly.
Windows Forms Tips and Tricks has information on the first option.

Secondly, ControlPaint is a total cheat because it often draws on the deskop
window, not the control window. This is why it leaves unwanted traces of
itself and why you should draw your borders correctly.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Aaron Smith" <th**********@smithcentral.net> wrote in message
news:Be*******************@newssvr19.news.prodigy. com...
I have a panel that I have in the paint event to draw a Raised 3d border
around it.. The problem is, if a msgbox is popped up or a tooltip is
displayed, it leaves lines on the panel. I've tried invalidate after the
msgbox to no avail...

Here is the event:
Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle,
Border3DStyle.Raised)
End Sub

I've tried calling the base event too, which seemed to do nothing..

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.

Nov 21 '05 #2
Bob,

The example that I found on your site is all well and good, but what
about raised 3d borders? I do not want the sunken 3d panel, I want a
raised one. Will it work the same way if I sublcass the panel and set it
through the CreateParams? Again, I'm not doing this in a custom control,
I'm doing it in the standard windows forms panel.

Aaron

Bob Powell [MVP] wrote:
Firstly, don't draw borders in the paint event. Add a border to the object
using the window properties or handle the non-client messages correctly.
Windows Forms Tips and Tricks has information on the first option.

Secondly, ControlPaint is a total cheat because it often draws on the deskop
window, not the control window. This is why it leaves unwanted traces of
itself and why you should draw your borders correctly.

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #3
Aaron,
e.ClipRectangle represents the part of the Panel that needs to be repainted,
it is not the entire panel.

If you want a border around the entire Panel use Panel.ClientRectangle
instead.

Something like:
Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
ControlPaint.DrawBorder3D(e.Graphics, Panel2.ClientRectangle,
Border3DStyle.Raised)
End Sub
You should also consider setting the Panel.DisplayRectangle to compensate
for the size of the border. As DisplayRectangle represents the amount of
usable space in the control that is not used for "adornments" such as the
border. Returning DisplayRectangle is important if you have controls within
your Panel that rely on Docking & Anchoring as Docking & Anchoring take
DisplayRectangle into account...

Note to set the DisplayRectangle you actually have to override the property
in a derived class, which I would do to encapsulate the painting any way.
Something like:

Public Class PanelEx
Inherits System.Windows.Forms.Panel

Public Overrides ReadOnly Property DisplayRectangle() As
System.Drawing.Rectangle
Get
Dim value As Rectangle = ClientRectangle
Dim size As size = SystemInformation.Border3DSize
value.Inflate(size.Width * -1, size.Height * -1)
Return value
End Get
End Property

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle,
Border3DStyle.Raised)
End Sub

End Class

Then every place you want a panel with a 3D border you would use a PanelEx
instead of the normal Panel.

Hope this helps
Jay

"Aaron Smith" <th**********@smithcentral.net> wrote in message
news:Be*******************@newssvr19.news.prodigy. com...I have a panel that I have in the paint event to draw a Raised 3d border
around it.. The problem is, if a msgbox is popped up or a tooltip is
displayed, it leaves lines on the panel. I've tried invalidate after the
msgbox to no avail...

Here is the event:
Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle,
Border3DStyle.Raised)
End Sub

I've tried calling the base event too, which seemed to do nothing..

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.

Nov 21 '05 #4
Jay,

You rock. That was it. I sat here and played with it more after Bob's
reply thinking it shouldn't have to be that difficult to do what I want.
I saw that if I minimized the window and then restored it, it fixed it.
So I've been trying to find that property... I'm glad you responded. I
probably would have not found it for a long time. lol

Thanks Again,
Aaron

Jay B. Harlow [MVP - Outlook] wrote:
Aaron,
e.ClipRectangle represents the part of the Panel that needs to be repainted,
it is not the entire panel.

If you want a border around the entire Panel use Panel.ClientRectangle
instead.

Something like:

Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
ControlPaint.DrawBorder3D(e.Graphics, Panel2.ClientRectangle,
Border3DStyle.Raised)
End Sub

You should also consider setting the Panel.DisplayRectangle to compensate
for the size of the border. As DisplayRectangle represents the amount of
usable space in the control that is not used for "adornments" such as the
border. Returning DisplayRectangle is important if you have controls within
your Panel that rely on Docking & Anchoring as Docking & Anchoring take
DisplayRectangle into account...

Note to set the DisplayRectangle you actually have to override the property
in a derived class, which I would do to encapsulate the painting any way.
Something like:

Public Class PanelEx
Inherits System.Windows.Forms.Panel

Public Overrides ReadOnly Property DisplayRectangle() As
System.Drawing.Rectangle
Get
Dim value As Rectangle = ClientRectangle
Dim size As size = SystemInformation.Border3DSize
value.Inflate(size.Width * -1, size.Height * -1)
Return value
End Get
End Property

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle,
Border3DStyle.Raised)
End Sub

End Class

Then every place you want a panel with a 3D border you would use a PanelEx
instead of the normal Panel.

Hope this helps
Jay

"Aaron Smith" <th**********@smithcentral.net> wrote in message
news:Be*******************@newssvr19.news.prodigy. com...
I have a panel that I have in the paint event to draw a Raised 3d border
around it.. The problem is, if a msgbox is popped up or a tooltip is
displayed, it leaves lines on the panel. I've tried invalidate after the
msgbox to no avail...

Here is the event:
Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle,
Border3DStyle.Raised)
End Sub

I've tried calling the base event too, which seemed to do nothing..

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.


--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tamir Khason | last post by:
How I can paint something onClick event? I need PaintEventArgs event in order to paint and raise Graphics, but onClick I have only EventArgs Event... Thanx
0
by: Duncan Mole | last post by:
Hi, I have created a control which draws a title bar and provides a drop down menu for a Smart Device Application. It seemed to work fine until I came to add an event handler to act on Paint...
7
by: Schorschi | last post by:
I know there is a way to do this, but I don't know how. Via a custom event? I have some code that I only want to run during a paint event. I could build a form instance that has the code and...
2
by: Simon Jefferies | last post by:
Hello, How can i perform double buffering on the Paint Event of a panel control. TIA Simon
1
by: edi sol | last post by:
Hi, I have a user control and panel in this control. I write a paint event of the panel control. When I strat the application (windows form with this control only) the paint event executes twice....
2
by: Jim Lewis | last post by:
I have a simple worker thread that does "BeginInvoke(UpdateUI)". In UpdateUI I have "panel.Refresh ()" which the debugger shows is executed. Yet a breakpoint in the panel's Paint handler never gets...
12
by: Matt Bitten | last post by:
I've got a wxPython program that needs to do some drawing on a DC on a regular basis, whether or not a paint event happens. I know how to make a ClientDC to do the drawing in, and I know what...
5
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, On a usercontrol I've put a set of radiobuttons within a groupbox. These radiobuttons have visual style enables, i.e. they turn orange when hovering over them and green when pushed. ...
2
tranc3d
by: tranc3d | last post by:
Hello, I have a custom panel in my project (this one: http://www.codeproject.com/KB/graphics/fastimagedrawing.aspx) with a custom paint event ( protected override void OnPaint(PaintEventArgs pe)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.