Categories > Coding > C# >

[Tutorial] How to put windows 11 rounded edges on a WPF/WForms Project.

Posts: 4

Threads: 1

Joined: Dec, 2021

Reputation: 0

Posted

Since the windows 11 release they've added rounder edges to any app.

If you want this on your own application you will have to use dwmapi.dll for it to work.

 

C#

Go on to your .cs (example form1.cs or MainWindow.xaml.cs).

We will have to use "using System.Runtime.InteropServices;" & "using System.Windows.Interop;"

 

After that go to "public partial class MainWindow Window" under that you'll have to paste this,

 

        public enum DWMWINDOWATTRIBUTE

        {

            DWMWA_WINDOW_CORNER_PREFERENCE = 33

        }

 

        public enum DWM_WINDOW_CORNER_PREFERENCE

        {

            DWMWCP_DEFAULT = 1,

            DWMWCP_DONOTROUND = 1,

            DWMWCP_ROUND = 2,

            DWMWCP_ROUNDSMALL = 1

        }

 

        [DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]

        private static extern long DwmSetWindowAttribute(IntPtr hwnd,

                                                         DWMWINDOWATTRIBUTE attribute,

                                                         ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,

                                                         uint cbAttribute);

 

/ Now when we've done that look for "InitializeComponent();"

Under that paste this,

 

            IntPtr hWnd = new WindowInteropHelper(GetWindow(this)).EnsureHandle();

            var attribute = DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE;

            var preference = DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND;

            DwmSetWindowAttribute(hWnd, attribute, ref preference, sizeof(uint));

 

Now run your application and have fun!

NOTE: This is only visible on windows 11.

 

 

 

  • 0

https://cdn.discordapp.com/attachments/894327057859870751/918198109975248956/zoidbanner.png

blueless

Failed to fetch.

vip

Posts: 324

Threads: 34

Joined: Dec, 2021

Reputation: 14

Replied

i know a way to do this in windows 11/10/7, ill probably release that tomorrow

  • 0

Failed to fetch.

Posts: 4

Threads: 1

Joined: Dec, 2021

Reputation: 0

Replied

@blueless

You can just elipse and add a border, but if u can just use microsoft's official method.

  • 0

https://cdn.discordapp.com/attachments/894327057859870751/918198109975248956/zoidbanner.png

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )