scroll bars on a panel ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: scroll bars on a panel ?

  1. #1
    Join Date
    Jan 2013
    Posts
    7

    scroll bars on a panel ?

    hi

    i have setup a mdi parent form with 3 panles on it. one docked to the left , one docked to the right and the third docked as fill to sit inbetween the other two.
    i want to display an image on the third panel and have it be scrollable if it is bigger than the panel size. i have tried to get just a single panel on a form, with the panels autoscroll set to true ( and also with the forms autoscroll set to true) and it doesnt want to work , i think i am missing a vital ingredient here.
    Can anyone enlighten me ?
    I have managed to get the scroll bars to appear in a test i did but when i adjust the scroll bars the image on the panel is getting corrupted. i am not doing anything in the OnPaint and it is not overridden so shouldnt the panle just 'move' within the scroll area. i understand it has to be redrawn, but there is nothing i have done to the redraw method (that i am aware of) that would make it alter the content on the panel.

    Could some one provide any code that simply draws say arectangle on a panle and allows it to scroll in a form that is smaller than the panel size.

    many TIA

    Dexter

  2. #2
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: scroll bars on a panel ?

    Are you drawing the image to the panel, or to a picturebox which gets added to the panel?.... Because if you're drawing it to the panel directly, then you need to go back and review how the AutoScroll property works.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: scroll bars on a panel ?

    AceInfinity's solution is essentially correct. Basically you draw to an object (e.g. a picturebox) that the panel contains and then change the location of that object (the coordinates of which are relative to the upper-left corner of the panel, not the form). GDI should take care of the rest of the drawing automagically, I think (been awhile since I did that). Note that you're not going to get amazing performance out of WinForms, but it may be adequate, depending on your purposes.
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: scroll bars on a panel ?

    Put the image to the PictureBox, make the dimensions of the PictureBox no more and no less from the actual control's size, then place the PictureBox at (0, 0) within the panel, and make sure its AutoScroll property is set to true. The panel is a container for controls, so the picturebox actually needs to be added as a child control to the panel.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  5. #5
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: scroll bars on a panel ?

    Quote Originally Posted by AceInfinity View Post
    make the dimensions of the PictureBox no more and no less from the actual control's size
    To clarify: you set the PictureBox to the size of the drawing canvas (image size), not to the size of the panel. Correct?
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #6
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: scroll bars on a panel ?

    Quote Originally Posted by BioPhysEngr View Post
    To clarify: you set the PictureBox to the size of the drawing canvas (image size), not to the size of the panel. Correct?
    Yeah, I meant to say "Picture" I have this auto-completion addon that turned it into "PictureBox" because it was previously typed.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  7. #7
    Join Date
    Jan 2013
    Posts
    7

    Re: scroll bars on a panel ?

    many thanks for the replies, i will have to go back and adjust accordingly.

    what do you suggest as the best route for doing multiple layers onto the image ? i.e. 4 seperate layers combined into on. from a speed point of view.

    thanks

  8. #8
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: scroll bars on a panel ?

    Depends on what you mean by "Layers", new images? Or images painted over the image in one picturebox?

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  9. #9
    Join Date
    Jan 2013
    Posts
    7

    Re: scroll bars on a panel ?

    i was thinking along the lines of 3-5 independant bmp's all the same dimensions layered together. i would imagine it nees some sort of masking applid and if so is it built in or do i need to code it.

    it has been 4+ years since i did any coding in c# and then i had only been looking at it for 6 months, so bear with me if i sound a little naive here.

    thanks

  10. #10
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: scroll bars on a panel ?

    layered together how? You need to define what you mean by 'layer' as mentioned before. In separate PictureBox's? In the same image within one PictureBox?

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  11. #11
    Join Date
    Jan 2013
    Posts
    7

    Re: scroll bars on a panel ?

    sorry should have been clearer, as i said between 3- 5 bmps merged down to a single bmp, transferred to the panel for the purpose of when the panel scrolls.

    im just playing with ideas here, in advance, as im messing about with some lync 2010 code at the same time and the two are vastly different . i am still contemplating taking the whole thing into XNA.
    as that fits more with some 3d stuff im doing in softimage,autodesk apps in general, not enough hours ina day though :S

    thanks

  12. #12
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: scroll bars on a panel ?

    XNA? It's limited though mainly towards gaming.

    For a PictureBox you could take the image out and modify it with GDI before assigning it back to the PictureBox quite easily to layer images into 1. Once you do that though, you can't just "remove" a layer, you have to save the previous image in memory or to the filesystem or something to have something to "revert" back to if that was the case.

    This is what I did for my watermark program a while ago.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center