Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# Graphics Drawing & Scrolling

Options
  • 17-11-2004 1:50pm
    #1
    Posts: 0


    Hey all,

    Need a bit of help regarding the subject.
    I've just really started C# but so far, I'm pleasantly surprised how close the thing is to Java, once you get around the slight differences (class layouts, event-handling, etc), it's almost the same.

    However, I remember in Java the Scrollable interface, where you could put scrolling functionality into something like a Jpanel or component...how would I get the same functionality in C#?

    My goal is to draw shapes on the screen (directly to the Graphics object) and then be able to scroll the whole screen down a bit and the drawn graphics will stay at the top, allowing me to draw more below the visible area and then scroll later.

    Hope my description is clear, any help/pointers in the right direction would be great thanks :)


Comments

  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    You shouldn't need to code anything at all for that functionality.

    If you look at controls like Panel, they have a property (don't recall it offhand) which will autoscroll (Maybe its a boolean property called AutoScroll!) which will cause the Panel to display scrollbars whenever it contains stuff outside its drawable area.

    So, drop a Panel of size CanvasHeight,CanvasWidth into a Panel of size DisplayHeight,DisplayWidth, with AutoScroll (or whatever) set on the outer panel....et voila.

    I use a variant of the technique quite a lot, cause I draw my UI (typically boring field-based business apps) onto a Panel with MinimumSize set to something reasonable (as small as will display all controls at reasonable size), and drop the Panel onto the form. Set Dock to true, and AutoScroll on the Form to true. User can now resize the app to their hearts content, and instead of the "working area" getting shrunk too small, I get scrollbars on it.
    Using a couple of panels judiciously, I can keep things like buttons and so on visible at all times, whilst allowing the user the ability to shrink the program and use it in "scroll up and down" mode...very handy on "long" forms.

    jc


Advertisement