Link to home
Start Free TrialLog in
Avatar of Unimatrix_001
Unimatrix_001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Custom control not refreshing on scroll.

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

ASKER CERTIFIED SOLUTION
Avatar of Rahul Goel
Rahul Goel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Unimatrix_001

ASKER

:)