Solved

Custom control not refreshing on scroll.

Posted on 2009-07-01
3
168 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

831 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