Please, help.
I created my contol, ButtonX, which subclasses System.Forms.Wi ndows.Button
class. I am doing my own paiting, by overriding OnPaint and
OnPaintBackgrou nd (without calling base class's OnPaint &
OnPaintBackgrou nd). My button has a shape of rectangle with rounded corners
and is filled with gradient brush, where user specifies the gradient colors.
The dilema I have now is how to paint the button when it's disabled (Enabled
= false). I know how to detect when this happens, but I am not sure how to
give my button the "disabled" look, so it would be somewhat similar to how
native windows controls look.
The idea I had was to BitBlt my button to an image, convert the image to a
gray scale image, and maybe to increase the brightness of RGB in gray scale
(to make it look different if the button is already gray). But it seems like
a hack to me.
Is there a built-in .NET functionality to do something like this? Or maybe a
better way than the one I described above?
There are a lot of other custom controls that I will have to build, so I
guess I am looking for a more or less generic solution.
Thanks for all the help and suggestions.
VR 4 5675
In your paint handler you can detect if the component is disabled and drw
the appropriate pixels.
protected override void OnPaint(PaintEv entArgs e)
{
if(Enabled)
{
// draw the enabled appearance
}
else
{
// draw the disabled appearance.
}
base OnPaint(e);
}
I would advise calling the OnPaint base class implementation at the end
because this enables the Paint event to fire.
--
Bob Powell [MVP]
Visual C#, System.Drawing
The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
<VR@MSDN.COM> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Please, help.
I created my contol, ButtonX, which subclasses System.Forms.Wi ndows.Button class. I am doing my own paiting, by overriding OnPaint and OnPaintBackgrou nd (without calling base class's OnPaint & OnPaintBackgrou nd). My button has a shape of rectangle with rounded
corners and is filled with gradient brush, where user specifies the gradient
colors. The dilema I have now is how to paint the button when it's disabled
(Enabled = false). I know how to detect when this happens, but I am not sure how to give my button the "disabled" look, so it would be somewhat similar to how native windows controls look.
The idea I had was to BitBlt my button to an image, convert the image to a gray scale image, and maybe to increase the brightness of RGB in gray
scale (to make it look different if the button is already gray). But it seems
like a hack to me.
Is there a built-in .NET functionality to do something like this? Or maybe
a better way than the one I described above?
There are a lot of other custom controls that I will have to build, so I guess I am looking for a more or less generic solution.
Thanks for all the help and suggestions.
VR
Bob,
Thanks for your post. As I said in my post, I do know how to detect whether
the control is enabled or disabled. What I am having problem with, is coming
up with a generic implementation that could generate the "disabled" look of
the control from its enabled look.
Thanks,
VR
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:Ok******** ******@TK2MSFTN GP11.phx.gbl... In your paint handler you can detect if the component is disabled and drw the appropriate pixels.
protected override void OnPaint(PaintEv entArgs e) { if(Enabled) { // draw the enabled appearance } else { // draw the disabled appearance. } base OnPaint(e); }
I would advise calling the OnPaint base class implementation at the end because this enables the Paint event to fire.
-- Bob Powell [MVP] Visual C#, System.Drawing
The Image Transition Library wraps up and LED style instrumentation is available in the June of Well Formed for C# or VB programmers http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml <VR@MSDN.COM> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Please, help.
I created my contol, ButtonX, which subclasses
System.Forms.Wi ndows.Button class. I am doing my own paiting, by overriding OnPaint and OnPaintBackgrou nd (without calling base class's OnPaint & OnPaintBackgrou nd). My button has a shape of rectangle with rounded corners and is filled with gradient brush, where user specifies the gradient colors. The dilema I have now is how to paint the button when it's disabled
(Enabled = false). I know how to detect when this happens, but I am not sure how
to give my button the "disabled" look, so it would be somewhat similar to
how native windows controls look.
The idea I had was to BitBlt my button to an image, convert the image to
a gray scale image, and maybe to increase the brightness of RGB in gray scale (to make it look different if the button is already gray). But it seems like a hack to me.
Is there a built-in .NET functionality to do something like this? Or
maybe a better way than the one I described above?
There are a lot of other custom controls that I will have to build, so I guess I am looking for a more or less generic solution.
Thanks for all the help and suggestions.
VR
For your enabled state you're creating a non-standard visual. I'm sure that
it's consistent across your controls, but it's hard for me (us) to suggest a
"standard" disabled state when the enabled state isn't standard to start
with. :-)
From an implementation perspective I'd create a class that models the
ControlPaint class which contains methods that you use to do generic drawing
of your controls. I can't really say what the "best" way to draw a greyed
version of your control is. If I were to do it myself I would just draw the
control two different ways depending on the state (like Bob suggested). You
could do something like your idea (applying a filter over the control to
remove the color) but my feeling is that a disabled control should be
"lighter" than an enabled control and not take more processor power to
paint. Perhaps you could create an implementiation of ControlPaint that
takes the colors to be painted as a parameter to a method and if the control
is disabled it converts those colors to shades of grey before painting them.
If you're looking for a routine to convert the colors to shades of grey
there's not one in .NET that I'm aware of.
I know that there's really any hard content here in my response, but I hope
it helps.
- Rhy
<VR@MSDN.COM> wrote in message news:O9******** ******@TK2MSFTN GP11.phx.gbl... Bob,
Thanks for your post. As I said in my post, I do know how to detect whether the control is enabled or disabled. What I am having problem with, is coming up with a generic implementation that could generate the "disabled" look of the control from its enabled look.
Thanks, VR
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message news:Ok******** ******@TK2MSFTN GP11.phx.gbl... In your paint handler you can detect if the component is disabled and drw the appropriate pixels.
protected override void OnPaint(PaintEv entArgs e) { if(Enabled) { // draw the enabled appearance } else { // draw the disabled appearance. } base OnPaint(e); }
I would advise calling the OnPaint base class implementation at the end because this enables the Paint event to fire.
-- Bob Powell [MVP] Visual C#, System.Drawing
The Image Transition Library wraps up and LED style instrumentation is available in the June of Well Formed for C# or VB programmers http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml <VR@MSDN.COM> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. > Please, help. > > I created my contol, ButtonX, which subclasses System.Forms.Wi ndows.Button > class. I am doing my own paiting, by overriding OnPaint and > OnPaintBackgrou nd (without calling base class's OnPaint & > OnPaintBackgrou nd). My button has a shape of rectangle with rounded corners > and is filled with gradient brush, where user specifies the gradient colors. > > The dilema I have now is how to paint the button when it's disabled (Enabled > = false). I know how to detect when this happens, but I am not sure how to > give my button the "disabled" look, so it would be somewhat similar to how > native windows controls look. > > The idea I had was to BitBlt my button to an image, convert the image > to a > gray scale image, and maybe to increase the brightness of RGB in gray scale > (to make it look different if the button is already gray). But it seems like > a hack to me. > > Is there a built-in .NET functionality to do something like this? Or maybe a > better way than the one I described above? > > There are a lot of other custom controls that I will have to build, so > I > guess I am looking for a more or less generic solution. > > Thanks for all the help and suggestions. > > VR > >
Rhy,
Thanks for your suggestions. It helps a lot, now that I know that I am not
re-inventing the wheel. My worry was that I would come up with this
eloborate way of doing something that's been already done and works much
better...
Thanks again.
VR
"Rhy Mednick" <rh*@rhy.com> wrote in message
news:u9******** ******@TK2MSFTN GP10.phx.gbl... For your enabled state you're creating a non-standard visual. I'm sure
that it's consistent across your controls, but it's hard for me (us) to suggest
a "standard" disabled state when the enabled state isn't standard to start with. :-)
From an implementation perspective I'd create a class that models the ControlPaint class which contains methods that you use to do generic
drawing of your controls. I can't really say what the "best" way to draw a greyed version of your control is. If I were to do it myself I would just draw
the control two different ways depending on the state (like Bob suggested).
You could do something like your idea (applying a filter over the control to remove the color) but my feeling is that a disabled control should be "lighter" than an enabled control and not take more processor power to paint. Perhaps you could create an implementiation of ControlPaint that takes the colors to be painted as a parameter to a method and if the
control is disabled it converts those colors to shades of grey before painting
them. If you're looking for a routine to convert the colors to shades of grey there's not one in .NET that I'm aware of.
I know that there's really any hard content here in my response, but I
hope it helps.
- Rhy
<VR@MSDN.COM> wrote in message
news:O9******** ******@TK2MSFTN GP11.phx.gbl... Bob,
Thanks for your post. As I said in my post, I do know how to detect whether the control is enabled or disabled. What I am having problem with, is coming up with a generic implementation that could generate the "disabled" look of the control from its enabled look.
Thanks, VR
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message news:Ok******** ******@TK2MSFTN GP11.phx.gbl... In your paint handler you can detect if the component is disabled and
drw the appropriate pixels.
protected override void OnPaint(PaintEv entArgs e) { if(Enabled) { // draw the enabled appearance } else { // draw the disabled appearance. } base OnPaint(e); }
I would advise calling the OnPaint base class implementation at the end because this enables the Paint event to fire.
-- Bob Powell [MVP] Visual C#, System.Drawing
The Image Transition Library wraps up and LED style instrumentation is available in the June of Well Formed for C# or VB programmers http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml <VR@MSDN.COM> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. > Please, help. > > I created my contol, ButtonX, which subclasses System.Forms.Wi ndows.Button > class. I am doing my own paiting, by overriding OnPaint and > OnPaintBackgrou nd (without calling base class's OnPaint & > OnPaintBackgrou nd). My button has a shape of rectangle with rounded corners > and is filled with gradient brush, where user specifies the gradient colors. > > The dilema I have now is how to paint the button when it's disabled (Enabled > = false). I know how to detect when this happens, but I am not sure
how to > give my button the "disabled" look, so it would be somewhat similar
to how > native windows controls look. > > The idea I had was to BitBlt my button to an image, convert the image > to a > gray scale image, and maybe to increase the brightness of RGB in gray scale > (to make it look different if the button is already gray). But it
seems like > a hack to me. > > Is there a built-in .NET functionality to do something like this? Or maybe a > better way than the one I described above? > > There are a lot of other custom controls that I will have to build,
so > I > guess I am looking for a more or less generic solution. > > Thanks for all the help and suggestions. > > VR > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sagaert Johan |
last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up.
I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the OnPaint .
The recangle draws correct when i press the mouse, but when i release the mouse the background is not restored
What should i do in the Onpaint to make sure the background (the form) is restored correctly ?
This problem already keeps...
|
by: Vern |
last post by:
I have a custom button control that compares the user security level to the
buttons security level property. If the user level is greater than the
button level, then the button is enabled, else it is disabled. Now for the
three questions:
1) I tried to retrieve the buttons security level property during the
buttons constructor, but it can't get the actual value assigned to that
button until sometime after the contructor finishes. Is...
|
by: Brian Henry |
last post by:
I am trying to make a custom user control that gets a list of users from our
database and populates the list, its an owner drawn control also, the
problem is, I placed the item onto a form and every time i make a change to
the control it reads the database and adds new items to the listing but
never gets rid of the old items in the list, the form seems to be makeing a
stored copy of the items locally then rebuilding the list ontop of it......
|
by: RSH |
last post by:
How do I go about overriding a Control's OnPaint Method?
I would like to prevent a control's color from changing when it is disabled.
I have overridden the Form's OnPaint Method but I need to do it at the
control level.
Thanks,
Ron
|
by: Kenneth Siewers Møller |
last post by:
Hi there
I have a custom label control (GradientLabel) which enherits from Label and
basically just paints the background of a label in a gradient.
In my code I have the following for the overidden OnResize event:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
| |
by: cashdeskmac |
last post by:
I have created a control and added a few properties. One of these is an
array of DateTime objects, looking like this:
public DateTime MyDates
{
get { return theDate;}
set {theDate = value;}
}
|
by: H-S |
last post by:
Please help. This is a real puzzler!
Originally posted on microsoft.public.dotnet.framework.windowsforms but
no answer found!
I have a read-only textBox which shows the results of a selection on
another form. When the selection changes from the saved data, I wish
to show it a different colour. As it is read-only the ForeColor
property has no effect.
|
by: ChopStickr |
last post by:
I have a custom control that is embedded (using the object tag) in an html document.
The control takes a path to a local client ini file.
Reads the file.
Executes the program specified in the ini on the client's PC.
After the program has ended the control looks in a client side temp folder (specified by the ini file) for an image created by the executed program.
If the image is there, then the control moves the file to a public folder...
|
by: rarobbi |
last post by:
I created a custom label so I can write characters in apex and also in this way:
ex.: Ac.
Now I have a problem: when my CustomLabel is in a disabled groupBox , the label does not appear disabled because the text I write with DrawText is
g.DrawString(text,usedFont, new SolidBrush(this.ForeColor),startPosition);
How can I solve this problem? How can I render a disabled label?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |