Solved

Custom control not refreshing on scroll.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
Problem to error 4 47
How to avoid saving tif files a 2nd time using VS2015 and C#? 1 29
Reset asp.net login password 4 34
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

864 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now