Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Custom control not refreshing on scroll.

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

809 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