Thursday, March 23, 2006

Scroll in .Net user control.

Scroll in a user control is a pretty tricky. I used to have to override the WndProc procedure and call OnVScroll and OnHScroll there. It is not bad. But the whole idea of .Net is RAD,if you have to put a lots of P/Invoke methods, that defeats the whole idea.

I spent some time to do it in managed way. A couple of steps I have to follow is :

1> I have to set the AutoScroll = true.
2> I have to set the AutoScollMinSize to the drawing bitmap size. That way, if the client rectangle is smaller than this one. The scroll bar will show up.
3> Another feature I requested is programmatically scroll, when the mouse is moving out the client area, it should scroll the control. For this, I have to manually set the AutoScrollPosition property.

No comments: