By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,996 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,996 IT Pros & Developers. It's quick & easy.

Refresh UserControl drawing elements

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.