Normal buttons look Rectangular and I was trying to figure out how to round the edges of it and found myself with a headache.. How do those pro designers do it? How do they get the custom GUI's and the buttons rounded or even custom buttons in any shape?

Kind of look like this: http://i.imgur.com/QGdco.png

There are no tutorials around on this :c I tried searching a lot.. and only find things telling you to just copy and paste this and that.. and include some file..

So anyone do this before or know how to do it?
I code in .Net Managed and I'm learning Win32 API. Can read API but not write it :c

Dani AI

Generated

Quick practical follow-up for and pointed you in the right direction. Below are concrete patterns you can apply in .NET (WinForms and WPF) and native Win32, plus pitfalls that commonly cause the headaches you mentioned.

For WinForms a small custom control that sets a non-rectangular Region, enables double-buffering and paints with anti-aliasing covers most needs. Also add a cheap per-pixel hit-test so clicks on “transparent” parts are ignored:

public class RoundButton : Control
{
    private GraphicsPath path;
    public RoundButton()
    {
        SetStyle(ControlStyles.AllPaintingInWmPaint |
                 ControlStyles.OptimizedDoubleBuffer |
                 ControlStyles.UserPaint, true);
        BackColor = Color.Transparent;
    }
    protected override void OnResize(EventArgs e)
    {
        base.OnResize(e);
        path = new GraphicsPath();
        path.AddEllipse(ClientRectangle); // or build rounded-rect path
        Region = new Region(path);
    }
    protected override void OnPaint(PaintEventArgs pe)
    {
        pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        using (var b = new SolidBrush(Color.CornflowerBlue))
            pe.Graphics.FillPath(b, path);
        TextRenderer.DrawText(pe.Graphics, Text, Font, ClientRectangle, ForeColor,
                              TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
    }
    // Simple alpha hit-test (GetPixel is slow; use LockBits for many clicks)
    private bool IsOpaqueAt(Point p)
    {
        var bmp = BackgroundImage;
        if (bmp == null) return true;
        int x = p.X * bmp.Width / Width, y = p.Y * bmp.Height / Height;
        return bmp.GetPixel(Math.Max(0, Math.Min(bmp.Width-1,x)), Math.Max(0, Math.Min(bmp.Height-1,y))).A > 16;
    }
}

In WPF this is simpler: use a ControlTemplate with vector geometry (Path or Border with CornerRadius) and triggers for visual states — vector shapes scale with DPI and avoid bitmap hit-testing pain.

Native Win32: for fully non-rectangular top-level windows consider per-pixel alpha with the layered-window APIs; for child controls use region-based clipping. Common gotchas: keyboard/accessibility (remember focus, keyboard activation and AccessibleName), high‑DPI scaling (prefer vector where possible), and performance (lockbits or retained/vector drawing over per-pixel GetPixel calls). If you want cross-platform, consider a retained renderer (SkiaSharp) rather than manual per-pixel work.

Recommended Answers

All 2 Replies

You need owner draw buttons.That means you have to create the necessary shapes or bitmaps to resemble each state of a button.There is a style for this which you pass as an argument in the CreateWindowEx function(BS_OWNERDRAW) but the part of drawing each state in case of a WM_COMMAND message must be handled by yourself.

Just draw the buttons as you like. Draw unpressed button, pressed button and mouse over button as an image.

Use events to catch mouse actions and display appropriate image.

From the perspective of a game developer .)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.