Solved

Custom control not refreshing on scroll.

Posted on 2009-07-01
3
170 Views
Last Modified: 2012-05-07
Hi,

I have the following code below from a custom component, although my issue is that when I scroll away from the rectangle and then back on the control does not refresh so the rectangle keeps getting larger. I have to force a refresh by switching to a different application then back. How can I sort this?

Thanks,
Uni
public partial class MyCustomControl:ScrollableControl {
 
	//Constructor.
	public MyCustomControl() {
		InitializeComponent();
		this.SetStyle(ControlStyles.OptimizedDoubleBuffer|ControlStyles.UserPaint|ControlStyles.AllPaintingInWmPaint, true);
		this.AutoScroll=true;
		this.AutoScrollMinSize=new Size(2000, 2000);
		this.Paint+=new PaintEventHandler(MyCustomControl_Paint);
	}
 
	//The paint method.
	private void MyCustomControl_Paint(object sender, PaintEventArgs e) {
		e.Graphics.FillRectangle(Brushes.Azure, 0, 0, 20, 50);
	}
 
}

Open in new window

0
Comment
Question by:Unimatrix_001
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Rahul Goel ITIL earned 500 total points
ID: 24755749

protected override void OnScroll(ScrollEventArgs se)
        {
            Invalidate(true);
        }

Open in new window

0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24755801
Looks good. :) Next question:
http://www.experts-exchange.com/Q_24536910.html

Thanks,
Uni
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 31598815
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question