473,484 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Refresh UserControl drawing elements

Hi you all,

I have created a usercontrol with a filledEllipses on a
filledRectangle, using this Paint event:

private void myControl_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
SolidBrush aBrush = new SolidBrush(this.BackColor);
e.Graphics.FillRectangle(aBrush, 10,10, this.Width - 10, this.Height
- 10);
if(m_fOn)
aBrush.Color = m_cOn;
else
aBrush.Color = m_cOff;
e.Graphics.FillEllipse(aBrush, 20, 20, this.Width - 20, this.Width -
20);
aBrush.Dispose();
}

using a Timer I switch m_fOn form true to false and back like this

private void myTimer_Tick(object sender, System.EventArgs e)
{
m_fOn = ! m_fOn;
this.Refresh();
}

Now the control is completly redrown.

For testing I have set the myTimer.interval to 10, and created a
testing application.
I discovered that the memory used by the testing application is
constand increasing.
So I would like to repaint the FillEllipse only.

Any advice on this?

Thanks in advance..

Executor

May 13 '06 #1
1 7182
Yes you are right because timer is constantly refreshing the control no
matter from is visible or not or form is minimized or not. I think you dont
need to refresh your control when your form is minimized or when its not
visible at all. So what you can do is if the form is visible (this.Visible =
True) and then invalidate the form.
The Invalidates method invalidates a specific region of the control and
causes a paint message to be sent to the control. It will cause the Paint
event of the control to fire and in paint event call ReDraw function of this
control.

"Executor" wrote:
Hi you all,

I have created a usercontrol with a filledEllipses on a
filledRectangle, using this Paint event:

private void myControl_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
SolidBrush aBrush = new SolidBrush(this.BackColor);
e.Graphics.FillRectangle(aBrush, 10,10, this.Width - 10, this.Height
- 10);
if(m_fOn)
aBrush.Color = m_cOn;
else
aBrush.Color = m_cOff;
e.Graphics.FillEllipse(aBrush, 20, 20, this.Width - 20, this.Width -
20);
aBrush.Dispose();
}

using a Timer I switch m_fOn form true to false and back like this

private void myTimer_Tick(object sender, System.EventArgs e)
{
m_fOn = ! m_fOn;
this.Refresh();
}

Now the control is completly redrown.

For testing I have set the myTimer.interval to 10, and created a
testing application.
I discovered that the memory used by the testing application is
constand increasing.
So I would like to repaint the FillEllipse only.

Any advice on this?

Thanks in advance..

Executor

May 14 '06 #2

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

Similar topics

1
4002
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...
17
8482
by: SamSpade | last post by:
picDocument is a picturebox When I do picDocument.Invalidate() the box paints. But if instead I do picDocument.Refresh() the box does not paint. What does Refresh do. I guessed it did an...
0
2436
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
2420
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
2
5034
by: Steve | last post by:
This is a weird one. I have a series of "SmartParts" which are CAB (Composite Application Block) Views which are finally just UserControls (99% of the time) Anyway, I layout my UserControl in...
6
12117
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
3
1999
by: Martin | last post by:
Hi ! I've developed a small UserControl with five textbox and label. However, when I want to display the UserControl in a form, controls appear slowly one after one. I've activated double...
4
2454
by: Martin | last post by:
Hi everyone ! For those who haven't read my previous post, I have a problem with a UserControl. When I try to display it on a form, controls seem to appear one after one. In the following...
1
3543
by: =?Utf-8?B?TmV3YnJv?= | last post by:
I have this program running on PDA compact framework in which it will receive paint message from server's networkstream and updates the client's screen by drawing on this custom 'Draw' userControl....
0
7079
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
7137
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...
1
6809
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
7194
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
5403
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4838
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
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
587
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
234
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.