Button and disabled icon

The place for threads about TimoSoft ButtonControls.
Post Reply
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Button and disabled icon

Post by Mex »

HI again,

If a use icon with commandbutton and set the enabled property to false then icon with index 3 is used from the image list?
So I must create disabled "gray" icon my self and add it to the image list with index 3?


Regards,
Meelis
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Button and disabled icon

Post by TiKu »

Hi,

yes, this is correct.

Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Cube8
Lieutenant
Posts: 12
Joined: 15 Aug 2015, 15:56
Location: Thessaloniki, Greece

Re: Button and disabled icon

Post by Cube8 »

I don't get it.
The definition is CommandButton.IconIndex([controlState As Long = -1]) As Long.

I thought it goes like this:
  • There is a single hImageList for the control.
  • IconIndex (without arguments, controlState = -1) uses the index provided as the default control icon.
  • IconIndex(3) means that it will use the index provided as the disabled icon.
Am I missing something? I tried setting IconIndex(3) = someindex but the icon doesn't change when I set .Enabled = False.
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Button and disabled icon

Post by TiKu »

Are you setting the UseImprovedImageListSupport property to True? I had to implement it this way to not break existing applications.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Cube8
Lieutenant
Posts: 12
Joined: 15 Aug 2015, 15:56
Location: Thessaloniki, Greece

Re: Button and disabled icon

Post by Cube8 »

Yes.
The icon changes if I change IconIndex for the default controlState. It doesn't work for controlState = 3 and Enabled = False. Instead, it shows the default icon a bit fainted.

Here is a sample, to make it clearer:

Code: Select all

With CommandButton1
    .hImageList = <some image list handle>
    .IconIndex = <default icon>
    .IconIndex(3) = <disabled icon>  'This is ignored
End With
Omitting the .IconIndex = <default icon> statement will make the button use the icon at index 0.
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Button and disabled icon

Post by TiKu »

Try this code:

Code: Select all

With CommandButton1
    .UseImprovedImageListSupport = True
    .hImageList = <some image list handle>
    .IconIndex = <default icon>
    .IconIndex(3) = <disabled icon>
End With
This way it works for me (Windows 7 SP1)
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Cube8
Lieutenant
Posts: 12
Joined: 15 Aug 2015, 15:56
Location: Thessaloniki, Greece

Re: Button and disabled icon

Post by Cube8 »

Hmm. This is very interesting.
I was working with classic theme. After switching to aero, it worked as expected.
This is definitely a bug, although I don't know if it is your code or windows fault.
Also, while on classic theme, I noticed that, if a button has icon+text and Enabled = True, the icon is "almost" hidden:
enabled-disabled.png
(1.27 KiB) Not downloaded yet
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Button and disabled icon

Post by TiKu »

Interesting. You are right. I never noticed this. I'll try to find out whether anything can be done about it.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Button and disabled icon

Post by TiKu »

The problem is that the native button control does not query for the disabled image if classic theme is used. Instead it always queries for the normal image. It would be quite difficult to work around this behavior in a reliable way.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Cube8
Lieutenant
Posts: 12
Joined: 15 Aug 2015, 15:56
Location: Thessaloniki, Greece

Re: Button and disabled icon

Post by Cube8 »

Ok. So this is a windows-related bug. I could write a procedure that changes the default icon whenever I want to enable/disable a button, instead of just setting Enabled = True/False. This is an inconvenience but I want to cover the classic theme scenario.

Also, what about the almost-hidden-icon bug? Is there a workaround for this?
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Button and disabled icon

Post by TiKu »

Cube8 wrote: 14 Mar 2017, 08:23 Also, what about the almost-hidden-icon bug? Is there a workaround for this?
So far I could not reproduce this problem. Do you have a sample project? It might have to do with the color of the icon's top-left pixel.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Cube8
Lieutenant
Posts: 12
Joined: 15 Aug 2015, 15:56
Location: Thessaloniki, Greece

Re: Button and disabled icon

Post by Cube8 »

I found out why I had this problem.
I did a hack, in order to show the icon to the left of the text (not the left edge of the button).
Specifically, I set IconAlignment = 4 (Center), I calculate the IconMarginRight, based on the button's text and then I pad some spaces to the left of the text.
With themes it works fine. Without themes the icon seems almost blank (like in the picture a few posts ago).
Apparently, when using themes, the text is drawn transparent and my hack works as expected, while on classic theme, the text covers the icon entirely.
I don't have WinXP to try it, btw.
Post Reply