Search code examples
vb.netbuttonrecursioncolorsflat

Selective recursive component recoloring in VB


I've asked a very similar question before, but this time is not about VB syntax, but rather the best approach. I'm making a method that, when passed a component, will recolor it and all components contained within it. Below is the code I have so far, but it is not recoloring all components, instead only a mere few. My main problem is buttons staying in their "3D" styles and not becoming "flat".

    If TypeOf comp Is System.Windows.Forms.ButtonBase Then
        Dim c As System.Windows.Forms.ButtonBase
        c = comp
        c.FlatStyle = Windows.Forms.FlatStyle.Flat
        c.BackColor = getColor(style, PART_BOX)
        c.ForeColor = getColor(style, PART_TEXT)

        comp = c
    End If

The component passed is comp, and the getColor method looks into a database and returns a color corresponding to the part parameter passed to the method. This works for all low-level components and all simple components like labels.

This is what happens. As you can see, the colors are fetched and applied properly to many components, but not all.

As you can see, this is not my preferred outcome. Does anyone know how to recolor spinners, buttons, and menu bars? Again, I need the button to end up being flat.


Solution

  • You can draw your own menu bars. See: http://msdn.microsoft.com/en-us/library/tdk48z0c(v=VS.100).aspx

    Buttons have a BackColor property and a FlatStyle property:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.buttonbase.flatstyle.aspx