Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating "virtual" ScrollableControl?

I'm creating my own very basic Grid control. I've decided to derive from ScrollableControl (this is what DataGridView seems to do) and go from there.

I have a lot of code in place to draw my cells, but I am having difficulty figuring out how to utilize the "scrollable" part of the ScrollableControl. It seems that ScrollableControl's designed to be a container of other controls, and it's "auto" scrolling features are oriented around child controls that are outside the bounds of the control.

I'm just looking to set the "virtual" area of the control so I get scroll bars of the correct size, then I do my own drawing into the control to create my own "view".

I'm basically very frustrated by this. What's the simplest way to get this to work?

like image 450
Erik Funkenbusch Avatar asked Aug 20 '09 02:08

Erik Funkenbusch


2 Answers

You have to set the AutoScrollMinSize property to tell the control what area you intend to render.

like image 188
Michael A. McCloskey Avatar answered Nov 06 '22 08:11

Michael A. McCloskey


As far as I know, you would need to have some child of ScrollableControl positioned at the lower-right bounds of your virtual surface. Perhaps a PictureBox with a 1 pixel transparent image would do.

FYI you may want to look at SourceGrid, either as a design inspiration (it makes good use of the MVC pattern), or perhaps it will solve your problem and you will not want to roll your own.

EDIT: Doh! I'm pretty sure Michael's solution is correct/better. However you may still want to have a look at SourceGrid.

like image 22
Eric J. Avatar answered Nov 06 '22 07:11

Eric J.