0

how can I create smooth corner rounded form in vb .net
I have no idea how I can do this.

enter image description here

In the image above, this has been done, but as you can see, it is pixelated.

vahid Araghi
  • 127
  • 9
  • Hello. Show us the code please. If you are setting the Form's `Region`, then Anti-Aliasing won't work. See [this](https://stackoverflow.com/a/56533229/14171304) example. – dr.null Jul 11 '21 at 09:50
  • I think you might be looking for [Alpha Blended Windows Forms](https://www.codeproject.com/Articles/20758/Alpha-Blended-Windows-Forms) - I think I've seen the same information here on Stack Overflow, but... oh I found something about it: [Per Pixel Alpha Blend](https://stackoverflow.com/questions/26871869/per-pixel-alpha-blend). – Andrew Morton Jul 11 '21 at 10:42
  • @AndrewMorton Dear AndrewMorton this is exactly what I wanted. This works like a charm, thank you for help. – vahid Araghi Jul 11 '21 at 11:37
  • For an Alpha-Blend Layered Form, see the VB.Net declaration and sample usage here: [Form's TransparencyKey leaves ghastly colored edging](https://stackoverflow.com/a/60688580/7444103). It could be useful. -- If you want to use the code linked by dr.null, you can simply draw the Borders well inside the Region area, so it can be anti-aliased better. It's just a setting you define (the internal offset). As in [How to avoid visual artifacts of colored border of zoomable UserControl with rounded corners?](https://stackoverflow.com/a/54794097/7444103) – Jimi Jul 11 '21 at 13:16

1 Answers1

0

Try this , smoother corners

  Private borderForm As New Form

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    With Me
        .FormBorderStyle = Windows.Forms.FormBorderStyle.None
        .Region = New Region(RoundedRectangle(.ClientRectangle, 50))
    End With
    With borderForm
        .ShowInTaskbar = False
        .FormBorderStyle = Windows.Forms.FormBorderStyle.None
        .StartPosition = FormStartPosition.Manual
        .BackColor = Color.Black
        .Opacity = 0.25
        Dim r As Rectangle = Me.Bounds
        r.Inflate(2, 2)
        .Bounds = r
        .Region = New Region(RoundedRectangle(.ClientRectangle, 50))
        r = New Rectangle(3, 3, Me.Width - 4, Me.Height - 4)
        .Region.Exclude(RoundedRectangle(r, 48))
        .Show(Me)
    End With


End Sub
Private Function RoundedRectangle(rect As RectangleF, diam As Single) As Drawing2D.GraphicsPath
    Dim path As New Drawing2D.GraphicsPath
    path.AddArc(rect.Left, rect.Top, diam, diam, 180, 90)
    path.AddArc(rect.Right - diam, rect.Top, diam, diam, 270, 90)
    path.AddArc(rect.Right - diam, rect.Bottom - diam, diam, diam, 0, 90)
    path.AddArc(rect.Left, rect.Bottom - diam, diam, diam, 90, 90)
    path.CloseFigure()
    Return path
End Function

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    Dim r As New Rectangle(1, 1, Me.Width - 2, Me.Height - 2)
    Dim path As Drawing2D.GraphicsPath = RoundedRectangle(r, 48)
    Using pn As New Pen(Color.Black, 2)
        e.Graphics.DrawPath(pn, path)
    End Using
End Sub

 
Bas H
  • 2,114
  • 10
  • 14
  • 23