473,385 Members | 1,983 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.

Problem in drawing my user controls


Hello there...

I have a custom user control, in which i put a panel on the top.
In the Paint event of the panel, i have the following code:

VisualStyleRenderer x = new
VisualStyleRenderer(VisualStyleElement.ExplorerBar .NormalGroupHead.Normal);
x.DrawBackground(e.Graphics, e.ClipRectangle);

VisualStyleRenderer y = new
VisualStyleRenderer(VisualStyleElement.ExplorerBar .NormalGroupExpand.Normal);
y.DrawBackground(e.Graphics, new
Rectangle(e.ClipRectangle.Width-30, e.ClipRectangle.Y, 30,
e.ClipRectangle.Height));

But when I run the application, and resize the form, or move another
program window above my application window, the user control drawing
becomes "noised"... a kind of "broken"...
I don't know what's happening...
Should I use another event instead of Paint??? But if I use another
event, how am I supposed to draw my component???

Regards.

Junior.

Apr 20 '06 #1
2 4499
sb
The problem is that you are trying to paint only _within_ the
cliprect...which is not what I think you want in this case. The
ClipRectangle is basically the portion of the window (Control) that Windows
thinks should be repainted...for whatever reason (a portion just became
visible, a window was restored/maximized, etc.) You can either use this
information and paint only within the cliprect...which can significantly
speed things up...or you can safely ignore it and code the method to repaint
everything. It's completely up to you.

Anyway, I'd try something like this:
private void panel1_Paint(object sender, PaintEventArgs e)
{
// Because the gradient being rendered is based on the entire control's
size, you need to code it like you're repainting it completely.
// Note that the framework will safely ignore painting that falls
outside of the ClipRectangle.
VisualStyleRenderer x = new
VisualStyleRenderer(VisualStyleElement.ExplorerBar .NormalGroupHead.Normal);
x.DrawBackground(e.Graphics, panel1.ClientRectangle);

// Since we're only painting an arrow which is not based on the entire
control's size, we can get away with a quick check to see if it even needs
to be repainted.
// These kinds of quick checks can save a lot of time if you're doing a
lot of painting.
Rectangle r = new Rectangle(panel1.ClientRectangle.Width - 30,
panel1.ClientRectangle.Y, 30, panel1.ClientRectangle.Height);
if (r.IntersectsWith(e.ClipRectangle))
{
VisualStyleRenderer y = new
VisualStyleRenderer(VisualStyleElement.ExplorerBar .NormalGroupExpand.Normal);
y.DrawBackground(e.Graphics, r);
}
}

-sb

"osmarjunior" <os*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...

Hello there...

I have a custom user control, in which i put a panel on the top.
In the Paint event of the panel, i have the following code:

VisualStyleRenderer x = new
VisualStyleRenderer(VisualStyleElement.ExplorerBar .NormalGroupHead.Normal);
x.DrawBackground(e.Graphics, e.ClipRectangle);

VisualStyleRenderer y = new
VisualStyleRenderer(VisualStyleElement.ExplorerBar .NormalGroupExpand.Normal);
y.DrawBackground(e.Graphics, new
Rectangle(e.ClipRectangle.Width-30, e.ClipRectangle.Y, 30,
e.ClipRectangle.Height));

But when I run the application, and resize the form, or move another
program window above my application window, the user control drawing
becomes "noised"... a kind of "broken"...
I don't know what's happening...
Should I use another event instead of Paint??? But if I use another
event, how am I supposed to draw my component???

Regards.

Junior.

Apr 20 '06 #2
Thanks for the reply...
Very helpfull!!!

Junior.

Apr 20 '06 #3

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

Similar topics

3
by: michael haller | last post by:
In my project i have a textfile witch i import in my c# application. The datas in the textfile i show the datas in the textfile in my datagrid..ok that ist not my problem. Now i have a...
1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
2
by: Tim Frawley | last post by:
Source code attached indicates my problem with validation and a button bar save button. Fill the Textbox with some text then tab off the control. The message box will display the text in the...
6
by: ?scar Martins | last post by:
Hi When I'm debugging and somewhere in the code I have a breakpoint, many times when the code after breakpoint finishes and the app returns I can do nothing within in it(it's like freeze)... The...
3
by: Geraldine Hobley | last post by:
Hello, In my project I am inheriting several forms. However when I inherit from a form and add additional subroutines and methods to my inherited form I get all sorts of problems. e.g. I sometimes...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
3
by: kamleshgk | last post by:
Hi, I have a requirement to draw a rectangle and a line on a the container control and sometimes as i move the mouse the drawing must occur on top of user controls and other controls, which are...
3
by: Gerrit | last post by:
Hi, I try to learn programming in c# with databinding controls. Now I have a problem with a ComboBox with the advanced properties for databinding, I want to set the DataSourceUpdateMode to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.