Create Smooth Rounded Corners Form | Border Radius - C# & WinForms

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.พ. 2025

ความคิดเห็น • 38

  • @Pixeliria
    @Pixeliria 3 ปีที่แล้ว +7

    Just know that your work is very appriciated, i used many of your tutorials on different projects trying to learn how to create windows applications. Definitly top tier design guides on the platform. Please continue to educate us on your designs!

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  3 ปีที่แล้ว

      Also thank you very much for watching my videos

  • @blackcamce6566
    @blackcamce6566 3 ปีที่แล้ว +1

    Nice (la única palabra que se en inglés XD)
    PD: justo eso trataba de hacer y casi destruyo visual studio XD
    Siempre ayudando a la comunidad gracias bro

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  3 ปีที่แล้ว +1

      😅...XD, Igualmente gracias por mirar mis videos, el código fuente ya está disponible en la descripción del vídeo.

  • @mohamad_xd4392
    @mohamad_xd4392 2 ปีที่แล้ว

    Thanks for the source code Mr.RJ Code | cool tutorial btw :D

  • @janslanina2209
    @janslanina2209 3 ปีที่แล้ว

    You are my hero ! :) awesome job

  • @chilinh2206
    @chilinh2206 2 ปีที่แล้ว

    great, this is what i was looking for

  • @saurabhtyagi4209
    @saurabhtyagi4209 3 ปีที่แล้ว +1

    Great Tutorial...❤❤👍👍

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  3 ปีที่แล้ว +1

      Thanks Saurabh, the source code is already available in the video description.

  • @ntsinh445
    @ntsinh445 ปีที่แล้ว

    so awesome, however i cant understand how FormRegionAndBorder method work, wishing u can explain each line of code in this method on another video, love it !

  • @davidPicado7209
    @davidPicado7209 3 ปีที่แล้ว +2

    Excelente Tutorial

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  3 ปีที่แล้ว

      Gracias David, el código fuente ya está disponible en la descripción del vídeo.

  • @CAST4O
    @CAST4O 2 ปีที่แล้ว

    فيديو حصري جدا جدا و مميز للغاية
    you are talking about a rare subjects where always no answer for them in the network search

  • @rudi4505
    @rudi4505 3 ปีที่แล้ว +3

    I tried some modifications . So I used the screen bitmap for the outer edge of the form. The result is - for me - a really satisfying outer edge of the Rounded Corner Form. But the solution for the inner side of the borderline could be even better.
    Hope that nevertheless this will be helpful in some aspect (the code is written in C#9 on Visual Studio 2019).
    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.RunTime.InteropServices;
    using System.Windows.Forms;
    namespace RoundedForm
    {
    public partial class Form1 : Form
    {
    // fields
    private int borderSize = 2;
    private int borderRadius = 30;
    private Color borderColor = Color.Red;
    private Bitmap fullScreenBitmap;
    // constructor
    public Form1()
    {
    InitializeComponent();
    FormBorderStyle = FormBorderStyle.None;
    Padding = new(borderSize);
    }
    #region DllImport
    : (unchanged)
    #endregion
    // private methods
    private void GetFullScreenBitmap()
    {
    Bitmap fullScreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
    Screen.PrimaryScreen.Bounds.Height,
    PixelFormat.Format32bppArgb);
    Graphics graphics = Graphics.FromImage(fullScreen);
    graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
    Screen.PrimaryScreen.Bounds.Y,
    0, 0,
    Screen.PrimaryScreen.Bounds.Size,
    CopyPixelOperation.SourceCopy);
    fullScreenBitmap = fullScreen;
    }
    private void SetScreenAsFormBackground()
    {
    Rectangle sourceRect = new(Location.X, Location.Y, ClientRectangle.Width, ClientRectangle.Height);
    BackgroundImage = (Image)fullScreenBitmap.Clone(sourceRect, fullScreenBitmap.PixelFormat);
    }
    private void PaintFormBackColor(Graphics graph)
    {
    Rectangle inflated = ClientRectangle;
    inflated.Inflate(-borderSize - 1, -borderSize - 1);
    GraphicsPath path = GetRoundedPath(inflated, borderRadius - borderSize);
    graph.FillPath(new SolidBrush(BackColor), path);
    Pen pen = new(BackColor, 1);
    pen.Alignment = PenAlignment.Center;
    graph.DrawPath(pen, path);
    }
    private GraphicsPath GetRoundedPath(Rectangle rect, float radius)
    {
    : (unchanged)
    }
    private void FormRegionAndBorder(Form form, float radius, Graphics graph,
    Color borderColor, float borderSize)
    {
    : (unchanged)
    }
    // event handling
    private void Form1_Load(object sender, EventArgs e)
    {
    GetFullScreenBitmap();
    SetScreenAsFormBackground();
    }
    protected override void OnPaintBackground(PaintEventArgs e)
    {
    base.OnPaintBackground(e);
    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
    PaintFormBackColor(e.Graphics);
    }
    Privat void Form1_Paint(object sender, PaintEventArgs e)
    {
    FormRegionAndBorder(this, borderRadius, e.Graphics, borderColor, borderSize);
    }
    private void Form1_ResizeEnd(object sender, EventArgs e)
    {
    SetScreenAsFormBackground();
    }
    // exit
    private void BtnExit_Click(object sender, EventArgs e)
    {
    Application.Exit();
    }
    }
    }

    • @VyrexVexy
      @VyrexVexy 2 ปีที่แล้ว

      source ?

    • @rudi4505
      @rudi4505 2 ปีที่แล้ว

      @@VyrexVexy Hi, Source is the code as brought to us by RJ Code in bis video "Create Smooth Rounded Corners Form". In my example here I only worte down the modified parts.

    • @VyrexVexy
      @VyrexVexy 2 ปีที่แล้ว

      @@rudi4505 i mean the project 💀

  • @okipulluplol
    @okipulluplol 2 ปีที่แล้ว

    THANK YOU SO MUCH DUDE

  • @nguyentinh2030
    @nguyentinh2030 6 หลายเดือนก่อน

    Hello, thanks for a good tutorial,
    have a issue with border when mouse up event when move form.

    • @nguyentinh2030
      @nguyentinh2030 6 หลายเดือนก่อน

      I have update code to fix this issue
      private bool dragging = false;
      private Point startPoint = new Point(0, 0);
      private void panelTitleBar_MouseDown(object sender, MouseEventArgs e)
      {
      //ReleaseCapture();
      //SendMessage(this.Handle, 0x112, 0xf012, 0);
      dragging = true;
      startPoint = new Point(e.X, e.Y);
      }
      private void panelTitleBar_MouseMove(object sender, MouseEventArgs e)
      {
      if (dragging)
      {
      Point p = PointToScreen(e.Location);
      Location = new Point(p.X - this.startPoint.X, p.Y - this.startPoint.Y);
      }
      }
      private void panelTitleBar_MouseUp(object sender, MouseEventArgs e)
      {
      dragging = false;
      }

  • @rudi4505
    @rudi4505 3 ปีที่แล้ว

    Pretious as always... I appreciate your work so much. A good graphical UI is so helpful. How about integrating this Rounded Corners Form into your Custom Controls collection?

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  3 ปีที่แล้ว

      No problem, you can use the custom controls on this form just like any other.

  • @notnotducminh
    @notnotducminh ปีที่แล้ว

    may I ask what font are you using on Visual Studio? thanks

  • @darrenbrook4641
    @darrenbrook4641 ปีที่แล้ว

    How do you make it so the rounded form can be made opaque / implement opacity?

  • @shenghdc
    @shenghdc 3 ปีที่แล้ว

    How to beautify the scroll? Or divider? Thank you

  • @kasunukk
    @kasunukk 3 ปีที่แล้ว

    good video. Can you make about custom scrollbar video. thank you

  • @one-word-edu
    @one-word-edu 3 ปีที่แล้ว

    How to rotate a text box in a custom degree in a form or report? please

  • @johnmutethia580
    @johnmutethia580 2 ปีที่แล้ว

    Is it possible to customize checkboxes in datagridview (datagridviewcheckboxcolumn) to have different symbols instead of tick for three states.
    State 1 with /
    State 2 with \
    State 3 with x
    These will be good for ticking attendance
    / present in morning
    \ present in evening
    X present morning and evening.

  • @balladsamu
    @balladsamu 3 ปีที่แล้ว

    Is it ok if i call you Bill gates.... I am just saying I really appreciate what you do. you are the best of the best

  • @PalladTV
    @PalladTV 2 ปีที่แล้ว

    Hi man, whats visual studio theme you have here?

    • @PalladTV
      @PalladTV 2 ปีที่แล้ว

      or what you font have :>

  • @osrobo
    @osrobo 10 หลายเดือนก่อน

    For Multiple Forms?

  • @codyplayer4329
    @codyplayer4329 3 ปีที่แล้ว

    Lástima que soy tan tonto y no puedo hacerlo, que bueno seria descargar la fuente :((((((((((((((

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  3 ปีที่แล้ว

      El código está en la descripción del vídeo.

  • @Elzelgator
    @Elzelgator ปีที่แล้ว +1

    It doesn't look good front of a white page.

  • @ДанилаТрофимчук-т3ю
    @ДанилаТрофимчук-т3ю 2 ปีที่แล้ว

    21 минуту ты делал этот изич, он делается в 2 минуты

  • @setinfosolucoes3249
    @setinfosolucoes3249 2 ปีที่แล้ว

    Help, please. I try use your class component and fine, now i need to implement opacity property at this class component, when add this component marked with opacity property at form controls this component start blinking.
    Imports System.ComponentModel
    Imports System.Drawing.Drawing2D
    Public Class DkPanel
    Inherits Panel
    Private Const WS_EX_TRANSPARENT As Integer = &H20
    Public Sub New()
    SetStyle(ControlStyles.Opaque, True)
    End Sub
    Public Sub New(con As IContainer)
    con.Add(Me)
    End Sub
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)
    Dim graph As Graphics = e.Graphics
    Using brush = New SolidBrush(Color.FromArgb(Opacity * 255 / 100, BackColor))
    graph.FillRectangle(brush, ClientRectangle)
    End Using
    If BorderRadius > 1 Then
    Dim rectBorderSmooth = ClientRectangle
    Dim rectBorder = Rectangle.Inflate(rectBorderSmooth, -BorderSize, -BorderSize)
    Dim smoothSize As Integer = If(BorderSize > 0, BorderSize, 1)
    Using pathBorderSmooth As GraphicsPath = GetFigurePath(rectBorderSmooth, BorderRadius)
    Using pathBorder As GraphicsPath = GetFigurePath(rectBorder, BorderRadius - BorderSize)
    Using penBorderSmooth As Pen = New Pen(Parent.BackColor, smoothSize)
    Using penBorder As Pen = New Pen(BorderColor, BorderSize)
    Region = New Region(pathBorderSmooth)
    graph.SmoothingMode = SmoothingMode.AntiAlias
    penBorder.Alignment = System.Drawing.Drawing2D.PenAlignment.Center
    graph.DrawPath(penBorderSmooth, pathBorderSmooth)
    graph.DrawPath(penBorder, pathBorder)
    End Using
    End Using
    End Using
    End Using
    Else
    Using penBorder As Pen = New Pen(BorderColor, BorderSize)
    Region = New Region(ClientRectangle)
    penBorder.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset
    graph.DrawRectangle(penBorder, 0, 0, Width - 0.5F, Height - 0.5F)
    End Using
    End If
    End Sub
    Private Function GetFigurePath(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
    Dim path As GraphicsPath = New GraphicsPath()
    Dim curveSize As Single = radius * 2.0F
    path.StartFigure()
    path.AddArc(rect.X, rect.Y, curveSize, curveSize, 180, 90)
    path.AddArc(rect.Right - curveSize, rect.Y, curveSize, curveSize, 270, 90)
    path.AddArc(rect.Right - curveSize, rect.Bottom - curveSize, curveSize, curveSize, 0, 90)
    path.AddArc(rect.X, rect.Bottom - curveSize, curveSize, curveSize, 90, 90)
    path.CloseFigure()
    Return path
    End Function
    'Propertys
    Private _BorderColor As Color = Color.MediumSlateBlue
    Private _BorderSize As Integer = 1
    Private _BorderRadius As Integer = 0

    Public Property BorderColor As Color
    Get
    Return _BorderColor
    End Get
    Set(ByVal value As Color)
    _BorderColor = value
    Invalidate()
    End Set
    End Property

    Public Property BorderSize As Integer
    Get
    Return _BorderSize
    End Get
    Set(ByVal value As Integer)
    If value >= 1 Then
    _BorderSize = value
    MyBase.Padding = New Padding(2, 2, 2, 2)
    Invalidate()
    Else
    _BorderSize = value
    MyBase.Padding = New Padding(0, 0, 0, 0)
    Invalidate()
    End If
    End Set
    End Property

    Public Property BorderRadius As Integer
    Get
    Return _BorderRadius
    End Get
    Set(ByVal value As Integer)
    If value >= 0 Then
    _BorderRadius = value
    Invalidate()
    End If
    End Set
    End Property

    Public Overrides Property BackColor As Color
    Get
    Return MyBase.BackColor
    End Get
    Set(ByVal value As Color)
    MyBase.BackColor = value
    Invalidate()
    End Set
    End Property

    Public Overrides Property ForeColor As Color
    Get
    Return MyBase.ForeColor
    End Get
    Set(ByVal value As Color)
    MyBase.ForeColor = value
    End Set
    End Property

    Public Overrides Property Font As Font
    Get
    Return MyBase.Font
    End Get
    Set(ByVal value As Font)
    MyBase.Font = value
    End Set
    End Property
    Private _Opacity As Integer = 100

    Public Property Opacity() As Integer
    Get
    Return _Opacity
    End Get
    Set
    If Value < 0 OrElse Value > 100 Then
    Throw New ArgumentException("value must be between 0 and 100")
    ElseIf Value < 100 Then
    'SetStyle(ControlStyles.Opaque, True)
    Else
    'SetStyle(ControlStyles.Opaque, True)
    End If
    _Opacity = Value
    Invalidate()
    End Set
    End Property
    Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
    Dim cpar As CreateParams = MyBase.CreateParams
    cpar.ExStyle = cpar.ExStyle Or WS_EX_TRANSPARENT
    Return cpar
    End Get
    End Property
    End Class