![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Changing the drawing style of a button from code ( c++ or c# ) What's the best way to change the way a button draws itself using only code? I've tried a few things and none of them do exactly what I'd like. - Setting the Background property ( either directly or with a Style ). Doesn't change the background color when the button is shown highlighted ( due to the mouse being over it ). - Deriving from Button and overriding OnRender. It appears as though you can only add to the drawing - the original drawing code is still executed - the documentation says as much as well. - Using a decorator. I don't really understand decorators but this seemed to have pretty much the same effect as the previous solution. I could add my own drawing to the decorator but the original button still drew as well. So is there a way to accomplish this? What I'm trying to do is to style a button that looks like the 'red x' close button on a window. I'm sure I could acccomplish it by deriving a new class from UIElement and completely re-implementing the button behaviour but it seems like just changing the drawing of the button is all I really need to do. I'm using C++/CLI but a C# example is easily translatable as well. Thanks- John Dunn |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Changing the drawing style of a button from code ( c++ or c# ) Hi John, I would suggest doing so the same way you would do it in XAML. By assigning a new Control Template / Style. Here's how you might replace the button's template with a Red Rectangle (in C#). Button button = ...; ControlTemplate template = new ControlTemplate(typeof(Button)); FrameworkElementFactory rect = new FrameworkElementFactory(typeof(Rectangle)); rect.SetValue(Rectangle.FillProperty, Brushes.Red); template.VisualTree = rect; button.Template = template; - Doug "John Dunn" <jhndnn@community.nospam> wrote in message news F705F00-A994-44D6-B985-B2D5E06F020D@microsoft.com...> What's the best way to change the way a button draws itself using only > code? > I've tried a few things and none of them do exactly what I'd like. > > - Setting the Background property ( either directly or with a Style ). > Doesn't change the background color when the button is shown highlighted ( > due to the mouse being over it ). > > - Deriving from Button and overriding OnRender. It appears as though you > can > only add to the drawing - the original drawing code is still executed - > the > documentation says as much as well. > > - Using a decorator. I don't really understand decorators but this seemed > to > have pretty much the same effect as the previous solution. I could add my > own > drawing to the decorator but the original button still drew as well. > > So is there a way to accomplish this? What I'm trying to do is to style a > button that looks like the 'red x' close button on a window. I'm sure I > could > acccomplish it by deriving a new class from UIElement and completely > re-implementing the button behaviour but it seems like just changing the > drawing of the button is all I really need to do. I'm using C++/CLI but a > C# > example is easily translatable as well. > > Thanks- > > John Dunn |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Changing the drawing style of a button from code ( c++ or c# ) Thanks- That helped quite a bit. Trying to use a lot of the WPF stuff without using XAML is like stumbing around in the dark. "Douglas Stockwell" wrote: > Hi John, > > I would suggest doing so the same way you would do it in XAML. By assigning > a new Control Template / Style. > > Here's how you might replace the button's template with a Red Rectangle (in > C#). > > Button button = ...; > > ControlTemplate template = new ControlTemplate(typeof(Button)); > FrameworkElementFactory rect = new > FrameworkElementFactory(typeof(Rectangle)); > rect.SetValue(Rectangle.FillProperty, Brushes.Red); > template.VisualTree = rect; > button.Template = template; > > - Doug > > "John Dunn" <jhndnn@community.nospam> wrote in message > news F705F00-A994-44D6-B985-B2D5E06F020D@microsoft.com...> > What's the best way to change the way a button draws itself using only > > code? > > I've tried a few things and none of them do exactly what I'd like. > > > > - Setting the Background property ( either directly or with a Style ). > > Doesn't change the background color when the button is shown highlighted ( > > due to the mouse being over it ). > > > > - Deriving from Button and overriding OnRender. It appears as though you > > can > > only add to the drawing - the original drawing code is still executed - > > the > > documentation says as much as well. > > > > - Using a decorator. I don't really understand decorators but this seemed > > to > > have pretty much the same effect as the previous solution. I could add my > > own > > drawing to the decorator but the original button still drew as well. > > > > So is there a way to accomplish this? What I'm trying to do is to style a > > button that looks like the 'red x' close button on a window. I'm sure I > > could > > acccomplish it by deriving a new class from UIElement and completely > > re-implementing the button behaviour but it seems like just changing the > > drawing of the button is all I really need to do. I'm using C++/CLI but a > > C# > > example is easily translatable as well. > > > > Thanks- > > > > John Dunn > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Contacts folder keep changing view style | Vista General | |||
| DOS-style code on boot? | Vista General | |||
| Changing System font style. | General Discussion | |||
| words fuzzy after changing "style" of windows.. | Vista mail | |||