Link to home
Start Free TrialLog in
Avatar of michael2705
michael2705

asked on

Render Taskbar Button

Hi All,
I try to make an AppBar and I'd like to have some Buttons on it.
So far, everthing is ok. But I try to give my buttons the style of the taskbar buttons. Same background, same mouse over effect, same everything...
I tried using VisualStyleRenderer but no luck.
Any ideas?
Thanks
Avatar of dungla
dungla
Flag of Viet Nam image

Your application don't work on XP OS?
I think you should check VisualStyles is enabled or not on selected theme.
Check out this link:
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic37106.aspx

Hope this helps
Avatar of michael2705
michael2705

ASKER

Thanks so far. Maybe you missunderstood me. I know how to use the VisualStyleRenderer but I just can't find the TaskBarButtonBackground and Edges in the list of the VisualStyleElements.
for back ground,  you can use sub-class of VisualStyleElement.Taskbar including: BackgroundTop, BackgroundBottom, BackgroundLeft and BackgroundRight.
For Edges you can use DrawEdge method (VisualStyleRenderer.DrawEdge return Rectangle)
Sounds good, but I can't follow you.
On Vista, for example, the buttons have rounded edges...
I just post what I've got so far.
class MyButton : Button
    {
        public MyButton()
            : base()
        {
 
        }
 
        protected override void OnPaint(PaintEventArgs pevent)
        {
            VisualStyleElement el = VisualStyleElement.Taskbar.BackgroundBottom.Normal;
            VisualStyleRenderer r = new VisualStyleRenderer(el);
            r.DrawBackground(pevent.Graphics, this.ClientRectangle);
            r.DrawEdge(pevent.Graphics, this.ClientRectangle, Edges.Left, EdgeStyle.Etched, EdgeEffects.None);
            r.DrawEdge(pevent.Graphics, this.ClientRectangle, Edges.Top, EdgeStyle.Etched, EdgeEffects.None);
            r.DrawEdge(pevent.Graphics, this.ClientRectangle, Edges.Right, EdgeStyle.Etched, EdgeEffects.None);
            r.DrawEdge(pevent.Graphics, this.ClientRectangle, Edges.Bottom, EdgeStyle.Etched, EdgeEffects.None);
        }
    }

Open in new window

Still no idea!
So actually if you want to draw round button, you must use GraphicsPath (System.Drawing.Drawing2D namespace) instead of using VisualStyleRenderer. There are a lot of sample, have a look.

http://www.xtremedotnettalk.com/showthread.php?t=77290
http://www.codeproject.com/KB/buttons/aquabutton.aspx
Thanks. But, that still doesn't help me to determine the current visual sytle of the taskBarButton.
ASKER CERTIFIED SOLUTION
Avatar of michael2705
michael2705

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Congratulation! :)
Yea, finally! :-)
Thanks, anyways
...but it only works on Vista! Any ideas for XP?