473,413 Members | 1,727 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,413 software developers and data experts.

Problem in painting custom panel control (.Net Framework 4.0).

88 64KB
I have inherited the standard panel control to create a panel having custom border color. The problem is, while the panel is on a form and any other form is moved across it, it paints hapazard lines of the same color as the panel custom border color, all throughout background of the panel. I tried to Refresh or Invalidate the panel in its paint event but of no avail. The same is happening while designing in the design editor too. See attached image. Why is this happening and how to get rid of it?
My code follows:

Expand|Select|Wrap|Line Numbers
  1. Namespace CustomPanelControl
  2.     Public Class CustomPanel
  3.         Inherits Panel
  4.  
  5.         Public Sub New()
  6.             MyBase.New()
  7.         End Sub
  8.  
  9.         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  10.             MyBase.OnPaint(e)
  11.  
  12.             'Set the backcolor of the panel according to the focus on it.
  13.             If Me.ContainsFocus Then
  14.                 Me.BackColor = Color.Yellow
  15.             Else
  16.                 Me.BackColor = Color.White
  17.             End If
  18.  
  19.             'Draw the border of the panel.
  20.             If Me.BorderStyle = BorderStyle.None Then
  21.                 Dim borderWidth As Integer = 1
  22.                 Dim BorderColor As Color = Color.Blue
  23.                 ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, BorderColor, borderWidth, ButtonBorderStyle.Solid, BorderColor, borderWidth, ButtonBorderStyle.Solid, BorderColor, _
  24.                 borderWidth, ButtonBorderStyle.Solid, BorderColor, borderWidth, ButtonBorderStyle.Solid)
  25.             End If
  26.         End Sub
  27.     End Class
  28. End Namespace
  29.  
Attached Images
File Type: jpg Normal.jpg (12.0 KB, 188 views)
File Type: jpg DirtyWhileExecute.jpg (19.1 KB, 196 views)
File Type: jpg DirtyWhileDesign.jpg (22.0 KB, 268 views)
Dec 7 '11 #1
1 2336
priyamtheone
88 64KB
The following line needs to be changed.

Expand|Select|Wrap|Line Numbers
  1. ControlPaint.DrawBorder(e.Graphics, Me.ClientRectangle, BorderColor, borderWidth, ButtonBorderStyle.Solid, BorderColor, borderWidth, ButtonBorderStyle.Solid, BorderColor, _
  2.                 borderWidth, ButtonBorderStyle.Solid, BorderColor, borderWidth, ButtonBorderStyle.Solid)

The reason I draw border for e.ClipRectangle, which may be just a small part of the control that has been invalidated for current paint event. So I need to use the control's ClientRectangle property.
For more advanced painting the clip rectangle can be used to only redraw the invalidated area.
Dec 13 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
3
by: Dexter | last post by:
Hello all, I'm building a web custom control, but i hava a problem. In the Sub Render, i have a html code as output. All ok. I have a other class that has a function that return a image object,...
1
by: Dexter | last post by:
Hello all, I'm developing a custom web control that mount a webpage, but now i don't can to modify the properties of my custom web control. by exemplo: the property NumeroGuia is 0 by default,...
1
by: Martin | last post by:
Hi, I have produced a custom server control that simple outputs a row of 26 buttons, one button for each letter of the english alphabet. now what I would like to do is catch the button click...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
11
by: BoloBaby | last post by:
OK, check this out... I have a form with a panel control and button on it (outside the panel control). I have two event handlers - one handles the click event of the button on the form. The...
6
by: shumaker | last post by:
How do I make a panel control invisible, but still recieve events? I have a panel that I set visible= false, and over it I am using GDI+ to paint a grid of rectangles. It has to be invisble or...
2
by: Smokey Grindle | last post by:
I am trying to write a custom panel control that I can place objects into at design time, however, i want a header on the top of it which can not contain controls (its a static header) in the image...
3
by: Charles Zhang | last post by:
I want to create a simple server control that does thing like: <Mc:CollapsibleControl TitlePanelID="panel1" BodyPanelID="Panel2"> <asp:Panel ID="panel1"> ... </asp:Panel> <asp:Panel...
0
by: melance | last post by:
I am developing a custom panel control that inherits the usercontrol and uses a designer that inherits the parentcontroldesigner. It has a panel on the control where controls will be placed and a...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.