I am not sure that my question was clear,
I mistakenly referred to WS_ instead of WM_ in my response. I guess my
answer wasn't that clear either
but this seems not encouraged in c# with all the api limitation
I don't know of the limitations to which you are referring. I don't think
there is any reason why you couldn't force scrollbars using P/Invoke but
it might not be recommended due to the fact that the managed control won't
be "aware" of such a change. IMO, it's perfectly reasonable for you to do
so, if you're prepared to write the required functionality as well. Maybe
someone else would like to give some of their insight on this topic.
so I was just asking if there any difference between the using the
vscroll control or the api(except the hwnd)?
For one thing, the VScrollBar control is managed and provides events and
other ways to control and interact with the scroll bar so that you won't
have to respond to Windows messages. It doesn't make much sense to use
the API directly unless you can't get what you need from the managed
control, which is doubtful. (I believe the VScrollBar class is just a
managed wrapper for an unmanaged vscroll class, IIRC).
Another thing is that since VScrollBar is a control you can place it
anywhere you'd like, including outside of the control that it's scrolling.
You can't do that easily with the API, IMO.
Forcing scrollbars won't help you (via WS_VSCROLL) unless you're prepared
to code all of the functionality yourself. I tried to give you another
solution that I had just thought of, so you wouldn't have to deal with
messages and scrollbars in code. I know that it didn't answer your
question exactly, but I was just trying to help you avoid some extra work
--
Dave Sexton
Yehia A.Salam said:
You won't receive a WS_VSCROLL message unless you have scrollbars but
they won't appear unless you have Controls that are partially or
completely outside of the ScrollableControl's visible area. In other
words, you won't be able to accomplish this using the scroll messages
unless you add your own scrollbars as I suggested.
I am not sure that my question was clear, WS_VSCROLL is a parameter used
in the CreateWindowEx used to give a control scrollbars with no hwnd and
then I can receive the WM_VSCROLL message normally, but this seems not
encouraged in c# with all the api limitation so I was just asking if
there any difference between the using the vscroll control or the
api(except the hwnd)?
<DIV>"Dave Sexton" <dave@jwa[remove.this]online.com>
You won't receive a WS_VSCROLL message unless you have scrollbars but
they won't appear unless you have Controls that are partially or
completely outside of the ScrollableControl's visible area. In other
words, you won't be able to accomplish this using the scroll messages
unless you add your own scrollbars as I suggested.
There might be an easier way that you can accomplish this but I haven't
tested it myself. Please let me know if this works for you:
1. Derive from Control and perform all your drawing operations as
necessary in an OnPaint method override (this will be your drawing
surface). Make sure that the Control's ClientRectangle is always equal
to the calculated bounding rectangle of your drawing so that the surface
of the Control will not clip the drawing at all (i.e. the Control's size
should never be smaller than your drawing's size). You can handle the
Resize event to prevent the Control from being resized smaller than your
drawing's bounding rectangle. Any time the size of your drawing must
change, recalculate the size of the bounding rectangle and set the
Control's size accordingly.
2. Derive another class from Panel or ScrollableControl and add the
previous Control as a private, nested class within its declaration.
3. In the constructor of your second control add a new instance of your
nested Control to the Controls collection and set its location to {0,
0}.
4. Optionally, you can create a subclassed ControlCollection for your
second control that prevents other controls from being added. (Override
CreateControlCollection method.)
5. Set the AutoScroll and other scroll properties of the second control
(the ScrollableControl container) as you desire.
The trick here would be ensuring that the drawing surface control is
always the size of the drawing. The container should automatically
handle the scrollbars for you.
HTH
--
Dave Sexton
but I always used to do it by the WS_VSCROLL style and then trapping
the WM_VSCROLL message in my old c++, but now it's really hard to
accomplish with the c# api limitation(no limitations here but rather
hard to accomplish requires more lines) , should I used the supplied
VScrollBar control, is there any limitation using this control, and
what's the difference between using the two methods?
ScrollableControl ensures that scroll bars will be visible if nested
controls exceed the visible client area. It has nothing to do
with what is drawn on the control.
If you want to have scroll bars appear when your drawing exceeds the
size of the visible client area, then you can use two ScrollBar
Controls. Use one as the horizontal bar and one as the vertical bar.
Calculate the appropriate size and position of each scroll box from
the size of your Control's client area (minus the size of the scroll
bars) and the size of your drawing.
You'll have to handle the Resize event as well if you want your
Control to function properly.
--
Dave Sexton
Hello,
I'm trying to create my own control derived from ScrollableControl
public partial class qViewer : ScrollableControl{
public qViewer() {
VScroll = true;
AutoScroll = true;
}
...
}
I override the OnPaint method with my own code,
however the scrollbars never shows though my drawings exceed the
Control size.
Thanks In Advance
Yehia A.Salm