473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ScrollableControl Problems

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

Sep 26 '06 #1
6 4379
Hi Yehia,

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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message news:AA**********************************@microsof t.com...
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

Sep 26 '06 #2
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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message
news:AA**********************************@microsof t.com...
>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

Sep 29 '06 #3
Hi Yehia,

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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message news:7C**********************************@microsof t.com...
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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message news:AA**********************************@microsof t.com...
>>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


Sep 29 '06 #4
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>&quot;Dave Sexton&quot; &lt;dave@jwa[remove.this]online.com&gt; wrote
in message news:ec**************@TK2MSFTNGP05.phx.gbl...</DIV>Hi Yehia,
>
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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message
news:7C**********************************@microsof t.com...
>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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message
news:AA**********************************@micros oft.com...
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


Sep 30 '06 #5
Hi Yehia,
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 ;)

<snip>
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" <ye*****@hotmail.comwrote in message news:A7**********************************@microsof t.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.

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>&quot;Dave Sexton&quot; &lt;dave@jwa[remove.this]online.com&gt; wrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...</DIV>Hi Yehia,
>>
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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message news:7C**********************************@microsof t.com...
>>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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message news:AA**********************************@microsof t.com...
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



Sep 30 '06 #6
yea u're right no pointing in reinventing the wheel, I'll just use the
VScrollBar control, Thanks for the answer

<DIV>&quot;Dave Sexton&quot; &lt;dave@jwa[remove.this]online.com&gt; wrote
in message news:%2******************@TK2MSFTNGP05.phx.gbl...</DIV>Hi
Yehia,
>
>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 ;)

<snip>
>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" <ye*****@hotmail.comwrote in message
news:A7**********************************@microsof t.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.

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>&quot;Dave Sexton&quot; &lt;dave@jwa[remove.this]online.com&gt;
wrote in message news:ec**************@TK2MSFTNGP05.phx.gbl...</DIV>Hi
Yehia,
>>>
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

"Yehia A.Salam" <ye*****@hotmail.comwrote in message
news:7C**********************************@micros oft.com...
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
>
"Yehia A.Salam" <ye*****@hotmail.comwrote in message
news:AA**********************************@micr osoft.com...
>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
>
>


Sep 30 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
1
by: Gates72 | last post by:
Hi Gurus, I am attempting to derive a User Control from the ScrollableControl class. I need to have control over which scrollbars get displayed. According to MSDN: "To manually override...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
0
by: Bob | last post by:
I implemented a ScrollableControl and only want vertical scrolling. Every time I make the form smaller then the control the control has h scroll bars even though I set it to false. I have the...
0
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
2
by: Rune Jacobsen | last post by:
Hi all, I have a few questions on deriving from ScrollableControl that I hope will be relatively easy to answer. I am using Visual Studio 2003, C# and ..Net 1.1. I have this custom control I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.