0

I want to make a round form for my project, but it shows pixels. Is there a way to prevent pixels from appearing? I want it sharp

This my code

Private Sub roundCorners(obj As Form)
    obj.FormBorderStyle = FormBorderStyle.None
    obj.BackColor = Color.Cyan

    Dim DGP As New Drawing2D.GraphicsPath
    DGP.StartFigure()
    'top left corner
    DGP.AddArc(New Rectangle(0, 0, 40, 40), 180, 90)
    DGP.AddLine(40, 0, obj.Width - 40, 0)

    'top right corner
    DGP.AddArc(New Rectangle(obj.Width - 40, 0, 40, 40), -90, 90)
    DGP.AddLine(obj.Width, 40, obj.Width, obj.Height - 40)

    'buttom right corner
    DGP.AddArc(New Rectangle(obj.Width - 40, obj.Height - 40, 40, 40), 0, 90)
    DGP.AddLine(obj.Width - 40, obj.Height, 40, obj.Height)

    'buttom left corner
    DGP.AddArc(New Rectangle(0, obj.Height - 40, 40, 40), 90, 90)
    DGP.CloseFigure()

    obj.Region = New Region(DGP)


End Sub

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

End Class

Can I draw round square with other color to solve this problem?

Marzouk
  • 11
  • 3
  • It's actually the opposite of making it sharp that you want. Each pixel can only be one colour so making it sharp means that all the pixels that are part of the form are one colour and will therefore contrast with the background. What you actually need is to blur the edge, i.e. to use anti-aliasing. That means that the pixels along the edge will be colours that are part-way between that of the form and that of the background, making the edge seem smoother when viewed at a macro level. I don't know how to do that when using a `GraphicsPath` for a form but that is what you should research. – jmcilhinney Aug 21 '21 at 13:10
  • 1
    With a Region, you can do something like this: [How can I draw a rounded rectangle as the border for a rounded Form?](https://stackoverflow.com/a/56533229/7444103). Otherwise, you need a per-pixel-alpha layered Form, e.g. [Form's TransparencyKey leaves ghastly colored edging](https://stackoverflow.com/a/60688580/7444103). Note that you cannot add Controls to this kind of Form, you can only draw on it. -- If you're interested, WPF supports Window transparency/smoothing out of the box; you can add a WPF Window to a WinForms Project. – Jimi Aug 21 '21 at 13:55
  • Regions don't support anti-aliasing. Pretty much the basic reason why you don't see much use for this effect. Once monitors reliably go beyond 300 dpi it will be back. – Hans Passant Aug 21 '21 at 14:01
  • Aren't form corners already sharp by default? – Caius Jard Aug 22 '21 at 06:32
  • Can I draw round square with other color to solve this problem? – Marzouk Aug 22 '21 at 14:54

0 Answers0