Autoscroll oversized userControl in panel

N

Newbro

I have this program running on PDA compact framework in which it will receive
paint message from server's networkstream and updates the client's screen by
drawing on this custom 'Draw' userControl.

Now on the PDA this 'Draw' userControl has a size of 480 x 320.
This control is added to a panel with autoscroll set to true. Since the PDA
screen has a size of 320 x 240, scroll will always be visible and show the
left top sectionof the userControl.

The program can receive paint message and update the PDA screen just fine by
drawing on this userControl, however at some point if the draw point if
outside of the current clientRectangle, I want to scroll this point before
drawing on the userControl. However I'm not sure how to do that. Since
clientRectangle can only be read, I've tried us this.Bounds or similar
functions but doesn't seem to do the job.

Any ideas would be great, Thanks in advanced
 
P

Peter Duniho

[...]
The program can receive paint message and update the PDA screen just
fine by
drawing on this userControl, however at some point if the draw point if
outside of the current clientRectangle, I want to scroll this point
before
drawing on the userControl. However I'm not sure how to do that. Since
clientRectangle can only be read, I've tried us this.Bounds or similar
functions but doesn't seem to do the job.

Any ideas would be great, Thanks in advanced

Well, the first thing that comes to mind is the DisplayRectangle and
AutoScrollPosition properties. Changing either of them affects what is
shown in the ScrollableControl (which Panel inherits). If I recall
correctly, changing DisplayRectangle won't update the scroll bars
automatically (there's another method to do that), so probably you want to
set AutoScrollPosition.

That said, I'm also a bit confused by your description. Your post says
that you are drawing into a custom UserControl. However, typically a
UserControl is used for composition of other controls. If you're
compositing other controls, then it seems to me that your panel should
instead be a UserControl and should directly contain the other controls
you want. If that's the case, then you can just use the
ScrollControlIntoView() method to show whatever needs to be shown.

On the other hand, if you're not compositing and you're doing all the
drawing yourself, it seems like the custom control should just be derived
from Control directly. Using a UserControl is overkill in that
situation. Alternatively, your custom control can inherit
ScrollableControl. That would provide the flattest control hierarchy; I
don't see any reason to nest controls when you don't need to. Just draw
whatever you're drawing into the DisplayRectangle, which will be updated
according to the scroll position. Set the AutoScrollPosition as necessary
to ensure that the "draw point" is within the viewable area.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top