473,386 Members | 1,693 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,386 software developers and data experts.

Scrollbars and controls in general

I'm trying to wrap all the basic controls(Button, scrollbar, etc..) to allow
for skinning. The problem is that many of the controls seem so different in
the way they work. For example, right now I'm trying to wrap teh scrollbar
class but when I override the OnPaint and OnPaintBackground prevent painting
the scrollbar is still painted. How the heck am I suppose to know how to do
these things if I can't find the information about how they work? I would
expect when I override these functions I would prevent the scrollbar from
drawing itself but this doesn't seem to be the case ;/ (while it is the case
for the button)

Ok, so maybe the scrollbar paints in a different way? Maybe the scrollbar
uses teh Controls property to hold the buttons and stuff but still, how does
it paint itself then? When I override the paint methods shouldn't I expect
that no painting should be performed?

It looks like I will have to just implement a new scrollbar class but then
it will be difficult to support the themes of the os? I figured that it
would be very easy just to override the painting and hit tests along with a
few others if I a flag was set and draw a better looking scrollbar that
functions the same way as the original but can easily be turned off. One
could easily refactor it into a program without making any programmatic
changest to support the new look too. But again, I'm running into trouble
trying to figure out what MS did. MSDN doesn't help as it just gives me a
list of properties and methods for the class but not how the class actually
works. (like if they forgot to make the OnPaint virtual so I could override
it)

any ideas? Anywhere I can find some info on this topic that will help clear
up some of my confusion?

Thanks,
Jon
Oct 21 '06 #1
4 1990
Hi Jon,
I'm trying to wrap all the basic controls(Button, scrollbar, etc..) to allow
for skinning. The problem is that many of the controls seem so different in
the way they work. For example, right now I'm trying to wrap teh scrollbar
class but when I override the OnPaint and OnPaintBackground prevent painting
the scrollbar is still painted. How the heck am I suppose to know how to do
these things if I can't find the information about how they work? I would
expect when I override these functions I would prevent the scrollbar from
drawing itself but this doesn't seem to be the case ;/ (while it is the case
for the button)
Try calling the following protected method in your derived class:

SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint,
true);

Then, you should only have to override OnPaint. I haven't tried this myself,
so please let me know if it works for you.

<snip>
It looks like I will have to just implement a new scrollbar class but then
it will be difficult to support the themes of the os? I figured that it
would be very easy just to override the painting and hit tests along with a
few others if I a flag was set and draw a better looking scrollbar that
functions the same way as the original but can easily be turned off. One
could easily refactor it into a program without making any programmatic
changest to support the new look too. But again, I'm running into trouble
trying to figure out what MS did. MSDN doesn't help as it just gives me a
list of properties and methods for the class but not how the class actually
works. (like if they forgot to make the OnPaint virtual so I could override
it)
You can download Rotor, Microsoft's open source CLR, or use .NET Reflector to
go inside and take a look.
any ideas? Anywhere I can find some info on this topic that will help clear
up some of my confusion?
If you are trying to rebuild the Windows controls suite via custom painting
then I'm not sure that deriving from the classes themselves are going to be
useful to you. At this point, you're probably better off creating your own
custom control suite from scratch since the Windows controls were not designed
for managed skinning, per se, although in the 2.0 framework there is new
support for drawing XP styles using the *Renderer objects of related controls.
e.g., ButtonRenderer, CheckBoxRenderer, ScrollBarRenderer, etc.

The closest you'll get to skinning a managed control now is with the
BackgroundImage, BackColor and BorderStyle properties so why not just roll
your own controls or buy a third-party suite? ;)

--
Dave Sexton
Oct 21 '06 #2

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi Jon,
>I'm trying to wrap all the basic controls(Button, scrollbar, etc..) to
allow for skinning. The problem is that many of the controls seem so
different in the way they work. For example, right now I'm trying to wrap
teh scrollbar class but when I override the OnPaint and OnPaintBackground
prevent painting the scrollbar is still painted. How the heck am I
suppose to know how to do these things if I can't find the information
about how they work? I would expect when I override these functions I
would prevent the scrollbar from drawing itself but this doesn't seem to
be the case ;/ (while it is the case for the button)

Try calling the following protected method in your derived class:

SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint,
true);
Yes, this did the trick. I suppose I have to spend some more time
investigating the nuances that exist in the controls class. Just hard to
find any good information on it and I guess I'm being a little lazy in
expecting everything to be laid out for me ;/
Then, you should only have to override OnPaint. I haven't tried this
myself, so please let me know if it works for you.

<snip>
>It looks like I will have to just implement a new scrollbar class but
then it will be difficult to support the themes of the os? I figured that
it would be very easy just to override the painting and hit tests along
with a few others if I a flag was set and draw a better looking scrollbar
that functions the same way as the original but can easily be turned off.
One could easily refactor it into a program without making any
programmatic changest to support the new look too. But again, I'm
running into trouble trying to figure out what MS did. MSDN doesn't help
as it just gives me a list of properties and methods for the class but
not how the class actually works. (like if they forgot to make the
OnPaint virtual so I could override it)

You can download Rotor, Microsoft's open source CLR, or use .NET Reflector
to go inside and take a look.
ok, I'll check it out. Thanks.
>any ideas? Anywhere I can find some info on this topic that will help
clear up some of my confusion?

If you are trying to rebuild the Windows controls suite via custom
painting then I'm not sure that deriving from the classes themselves are
going to be useful to you. At this point, you're probably better off
creating your own custom control suite from scratch since the Windows
controls were not designed for managed skinning, per se, although in the
2.0 framework there is new support for drawing XP styles using the
*Renderer objects of related controls. e.g., ButtonRenderer,
CheckBoxRenderer, ScrollBarRenderer, etc.

The closest you'll get to skinning a managed control now is with the
BackgroundImage, BackColor and BorderStyle properties so why not just roll
your own controls or buy a third-party suite? ;)
But I'd like to support the themes for the OS. I was just going to implement
the scrollbar as a control and do everything myself but I figured that its
no more or less complicated than just deriving from the Scrollbar class
instead of the control class. I'd automatically get the ability to use the
OS's themes by doing this. (just a tad bit more code but nothing
complicated)

Thanks,
Jon
Oct 21 '06 #3
Hi Jon,

<snip>
>The closest you'll get to skinning a managed control now is with the
BackgroundImage, BackColor and BorderStyle properties so why not just roll
your own controls or buy a third-party suite? ;)

But I'd like to support the themes for the OS. I was just going to implement
the scrollbar as a control and do everything myself but I figured that its
no more or less complicated than just deriving from the Scrollbar class
instead of the control class. I'd automatically get the ability to use the
OS's themes by doing this. (just a tad bit more code but nothing
complicated)
The *Renderer classes in 2.0 allow you to do just that - apply the current
visual styles of the OS to your controls:

ScrollBarRenderer on MSDN:
http://msdn2.microsoft.com/en-us/lib...rrenderer.aspx

So, you don't even have to derive from the Windows controls unless you simply
want to retain their public properties and designer support. But you can
always write the properties that you need yourself and use the BCL's
IDesigners on your own controls as well. And using the Windows controls will
be restrictive because you might want to override some properties that aren't
virtual, or you might want to modify some functionality that's internal to the
Control itself. Your best bet is to roll your own, IMO. That way you can use
a skinning architecture that is appropriate for your controls, such as an
ISkin interface and a ButtonSkin implementation, for example, that is assigned
to your SkinableControls.Button class via a VisualSkin property, or something
like that. The hardest controls to rewrite are going to be those controls
that accept text input from an end-user, however you can always just wrap
those controls. ;)

--
Dave Sexton
Oct 21 '06 #4

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
Hi Jon,

<snip>
>>The closest you'll get to skinning a managed control now is with the
BackgroundImage, BackColor and BorderStyle properties so why not just
roll your own controls or buy a third-party suite? ;)

But I'd like to support the themes for the OS. I was just going to
implement the scrollbar as a control and do everything myself but I
figured that its no more or less complicated than just deriving from the
Scrollbar class instead of the control class. I'd automatically get the
ability to use the OS's themes by doing this. (just a tad bit more code
but nothing complicated)

The *Renderer classes in 2.0 allow you to do just that - apply the current
visual styles of the OS to your controls:

ScrollBarRenderer on MSDN:
http://msdn2.microsoft.com/en-us/lib...rrenderer.aspx

So, you don't even have to derive from the Windows controls unless you
simply want to retain their public properties and designer support. But
you can always write the properties that you need yourself and use the
BCL's IDesigners on your own controls as well. And using the Windows
controls will be restrictive because you might want to override some
properties that aren't virtual, or you might want to modify some
functionality that's internal to the Control itself. Your best bet is to
roll your own, IMO. That way you can use a skinning architecture that is
appropriate for your controls, such as an ISkin interface and a ButtonSkin
implementation, for example, that is assigned to your
SkinableControls.Button class via a VisualSkin property, or something like
that. The hardest controls to rewrite are going to be those controls that
accept text input from an end-user, however you can always just wrap those
controls. ;)
Ok, This looks interesting. Unfortunately, for some reason, the scrollbar
renderer does work for non-visual styles so I'd still have to emulate the
look and feel of windows if I wanted to(although it doesn't seem to hard if
I can easily get the metrics for it(which I kidna done already)). But this
does seem to work.

Thanks for your time. I think I might be on the right track now.

Thanks again,
Jon

Oct 21 '06 #5

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

Similar topics

24
by: Nobody | last post by:
Okay, you are all so smart in here. Answer me this: IE6 in standards mode doesn't seem to hide scrollbars on the body element (overflow:hide) Ain't this a quandary. I have it in my head that I...
0
by: Thomasa Gregg | last post by:
I cannot get rid of the scrollbars that are showing up on all my asp.net controls. Buttons, Labels, everything. It has something to do with my css. If I remove rel="stylesheet" from <LINK...
1
by: Fabrício de Novaes Kucinskis | last post by:
Hi all, I have to problems concerning datagrids, tabcontrols and scrollbars: 1) I created a form with a TabControl. This TabControl has two TabPages: the first with a datagrid to browse...
17
by: Dino M. Buljubasic | last post by:
I have a treeview and a checked list view controls one beside another. I want to make them work so that when I scroll down or up one of them the other does the same. Any help will be...
5
by: Christopher Kurtis Koeber | last post by:
Dear All, This may sound like an elementary question but how do you implement scrollbars for the Picturebox control. Do I have to create my own code to do this or is there some property that I can...
2
by: MrNobody | last post by:
I have been struggling with .NET's scrollbars because when I use them I can't seem to get them to go to their maximum value. Searching on the web it looks like the maximum Value you can get on...
6
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I am implementing an Office 2007 – like interface, including the ability to change colors. One issue that I have is that scrollbars look poor if the application color theme (e.g., Black) does...
1
by: mrabie | last post by:
Hi All, I know this has been discussed before but i can't really find an answer to what i want to do. I am developing an application for touchscreen using C#. It's going to be a fullscreen...
1
by: raylopez99 | last post by:
Scrollbars scroll bars adding scrollbars in C# Forms 2.0 scrollbars don't work won't work how to add scrollbar in C# Here is how to add a scrollbar to a form. It's not in any book. For future...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.