dcsimg
Results 1 to 11 of 11

Thread: VB NET 2010: Changing a button's back color causes much darker shadow

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    405

    VB NET 2010: Changing a button's back color causes much darker shadow

    I am using the following code to change certain control back colour property.

    Code:
                Me.BackColor = Color.FromArgb(212, 208, 199)
                ' a method of looping through all the controls that require reversion of any background colouring
                For Each Ctrl In Me.Controls
                    If (TypeOf Ctrl Is Button) Or (TypeOf Ctrl Is CheckBox) Or (TypeOf Ctrl Is Label) Or (TypeOf Ctrl Is Panel) Or (TypeOf Ctrl Is TrackBar) Or (TypeOf Ctrl Is GroupBox) Then
                        Ctrl.BackColor = Color.FromArgb(212, 208, 199)
                    End If
                Next
    Just changing the colour of a button causes a much darker shadow which is unwanted behaviour and definitely not what I require. I simply want the button's face to alter to the colour given. All the other controls on the form work as expected, only buttons do this.



    On the left are the buttons before applying a colour to them, to keep it simple I have applied the same colour as the default theme but I could have changed it to any colour, the result would be the same.

    On the right, with the colour applied the buttons seem to have unexpectedly lost the theme or are receiving much deeper shadows.

    My experience on VB6 is that a button back colour is changeable without the same border shadow deepening or losing the theme, I assume the same is possible on VB.NET and I assumed it would be just as simple but I am clearly wrong. I must be missing something vital.

    The code is a simple loop to loop through all controls on a form, if the controls match then the background colour is set. It should work and does so as expected in VB6. There is a subtle "something else" happening.

    Can anyone help?



    Above: Form buttons styled by default, this is how it 'should' look.



    How the form looks when a background colour is applied to all control elements on the form, everything else looks quite correct but the buttons are heavily shaded. Quite wrong but only on the buttons.
    Last edited by yereverluvinuncleber; Dec 4th, 2019 at 03:49 AM. Reason: added images

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    405

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    I've done some digging and I think I have found what is wrong - the trouble is I think it is deliberately designed to prevent you from themeing.

    So forgive me if I am wrong, do correct me.

    I understand that if you change the backcolor property of a button then it changes the value of the .UseVisualStyleBackColor property from True to False.

    This causes the button to lose the default theme. You can set this property back to True but it does nothing. This appears to be a deliberate attempt to stop you themeing the button colour of control by causing it to lose the default theme. I cannot see any other reason for this. No other control seems to be affected, certainly no other on my form, they all style as expected.

    Conversely, VB6 allows you to change the backcolor property of a button, theme styling is retained. VB.NET changes the colour also but then it fecks up the styling, deliberately. That's not good.

    It means once again, that doing something simple in VB6 turns out to be much more complicated than it needs to be when done in VB.NET. I will have to create graphical buttons and assign manually created button images to the buttons that I wish to theme. It should have been as easy as changing the colour but disappointingly it isn't.

    If you can shed any light on why MS would choose to implement button background colours this way then I'll be interested to hear why.

    Better still, if you can think of a work-around I'd appreciate the information.

    You can tell I am getting more than a little frustrated by this migration, so forgive my subdued growling.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    405

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    It is rather a pity that changing button background colours affects their theme-ing as I was rather pleased that up to that point the form theme-ing in general had been so easy.

    Using VB6 I wasn't able to completely theme my form using alternative colours as the mscomctl size slider (bottom left) does not have a back colour property and so it retains the o/s default theme colour.

    The VB.NET trackbar that replaces it does have that property and it takes a colour perfectly, so the form themes beautifully, except for the bleedin' buttons...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    405

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    Just to sum this one up.

    It seems that the method .NET uses to draw styles onto a button does not support a colour change.

    The other elements that could constitute my form (except for tabs) do take a colour change. That is a limitation imposed by .NET's handling of themes. It does not allow you to change button colours whilst retaining a theme.

    VB6 allows the changing of a back colour and it retains such simple themeing that it allows, however a VB6 application does not seem to have access to the full themeing as supplied by NT6 o/s to .NET apps.

    The workaround is to add an image to the button.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    405

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    Duplicate

  6. #6
    Addicted Member
    Join Date
    Jan 2016
    Posts
    178

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    Isn't the darker shadow just because of the darker form color? the shadow isn't a color in of itself, it's just a shaded version of what's behind it.. isn't it? you make the form darker, the shadow will get darker.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    405

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    No, it seems not, in the examples above, the same colour is used.

    The original colour rgb(212, 208, 199) is that used by the classic theme. The button has that by default as part of the theme.

    When you change the background colour, myButton.BackColor = Color.FromArgb(212, 208, 199) then there should be no visual effect, it isn't adding one colour on top another to darken it further if that's what you are hinting at, it is merely setting the colour to any setting. In this case I've chosen the same colour as it demonstrates the issue clearly.

    The same happens if you changed to a much lighter colour.

    If you check the value of .UseVisualStyleBackColor property prior to the colour change you will see it change automatically from True to False.

    Then if you manually change the value of .UseVisualStyleBackColor property from True to False yourself, you'll see the same effect, the button loses the theme. It is the changing of this property that causes it.

    It is just the way it is. VB6 allows it and retains the limited button theme-ing it provides with the classic theme. VB.net removes the theme-ing as soon as a colour is applied. It could be to do with VB.NET supporting more advanced themes.

    I was surprised that it wasn't a more well known side effect. I suggest that most developers are happy with the look of their VB.NET apps as they appear out of the box, it is just chaps like me that worry about things like this as I do lots of theme-ing with my apps. I suppose that is the reason I am finding these issues out.

    The effect is worth noting.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,302

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    It doesn't just look like a darker color, it looks like Black (0,0,0). You make it sound like pretty nearly any change will do this. With my stunted graphical understanding this makes sense, so it is likely a screw up, cause a person with more graphical sense wouldn't think it made sense. To me, it seems like they may have said something like this, "to make a 3D button, you want a darker border on those sides. If the user changes the color, then we don't know what color to make the border...so make it the darkest color available."

    Naturally, that's not a very enlightened position, but I wouldn't be able to do better.

    As you note, this is un-theme-ly behavior. If there is a way around it, I certainly don't know of one...except that I know somebody who is good enough at graphics to avoid this: You. It would take more work, and might be unwelcome, especially since it seems like a poor choice made at some later date...but poor UI graphics choices seems to be what MS is all about, of late. However, consider that a button is never really 3D, it's just an image drawn in a rectangle. You could probably subclass the button and do your own drawing. Heck, just from looking at your images, I think even I could draw the standard button. You'd draw it in flat style, with three parts: The main image, the left and top border, and the right and bottom border. Each part would take a color, or perhaps the main image would take a color, which would set the other two automatically.

    I wouldn't even try to do this, cause I have no taste, but you could certainly do it.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    405

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    Yes, Mr. Hiker, I have my workaround and I will put it into place shortly. It was just one of those unexpected side effects of me doing something. Sometimes, the investigation, trialling the various options, understanding the results, and looking for the correct fix and possible workarounds can take a few hours. Each one of these is blocker or a detour on my route to migration.

    This migration feels like a walk I did around the coast of Britain. On the map it looks simply like a straight path alongside the sea but when you start out you find that to cover five seemingly straight miles as the crow flies you may be walking 15 torturous ones. You have to walk up and down both sides along the top of the cliffs around every little inlet. Sometimes, to cover just 15 yards in distance you'll find yourself walking three hundred inland and then back out again. Then the path goes down to sea level and back up to the tops of cliffs (and back down again). It's leaving me exhausted and in no mood for another migration - ever.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,302

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    In theory, the coast of any country has infinite length. As you keep looking at an increasingly fine scale, you see increasingly fine detail with a fractal nature. Therefore, in theory, you are still walking...and you will never do another migration because one will take you forever.
    My usual boring signature: Nothing

  11. #11
    Lively Member
    Join Date
    Jul 2017
    Location
    Exeter, UK
    Posts
    112

    Re: VB NET 2010: Changing a button's back color causes much darker shadow

    Nicely put

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width