Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scrolling with GDI

Status
Not open for further replies.

Echilon

Programmer
Feb 22, 2007
54
GB
I'm trying to draw a sort of table onto a UserControl in C#. The table will resemble something like an Excel spreadsheet, with a header at the top and a column visible to the left side (these will always be visible, regardless of scroll state). I'm also going to have a number of vertical columns, each of which will line up with a rectangle on the header. I've split my UserControl into two sectione by adding panels, one for the header and one for the rest. The problem is the scrolling.

I can't see to get the panel to scroll, even though there are rectangles drawn outisde the visible co-ordinates and autoscroll is set to true.

I read that drawing to a bitmap might be an option, but I need to process mouse clicks on elements which are drawn inside the columns. I was thinkining of splitting them each into separate UserControls, then rendering each one and the sub-controls it contains. This would allow me to process mouse events much more easily.

Would this be the best option? Is it even possible to scroll a panel when you're drawing with GDI?
 
If you are purely drawing using GDI+ then you have to manually set the scrollbar max value and handle the scroll event. When the scroll event occurs - you need to calculate where the scroll bar is and redraw your control as desired. For instance, if you had a 1000 cells and 100 fit in the view at any given time, you could set a max scroll of 10. then for every increase of 1 on the scrollbar you would move 100 cells.

It takes a bit of work in getting the scrolling right but it will have the best performance. If you want to do 3 separate controls that is also good but be aware that the other panels will lag a bit behind the scroll of the main control. It's just due to the drawing order of your controls and the speed of GDI+.

 
I've managed to get it working by using panelName.AutoScrollPosition.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top