Rounded Corners on Translucent Form

  • Thread starter Steve C. Orr [MVP, MCSD]
  • Start date
S

Steve C. Orr [MVP, MCSD]

I have a borderless form with it's Opacity set to 60% so the background
shows through. It looks very nice. But I'd like to round the corners of
this form. All the techniques I've seen so far for creating shaped forms
involve using the TransparencyKey property of the form. But this doesn't
work with a form that is translucent because the form color varies at
runtime based on the background colors that are showing through.
Does anybody have any ideas about ways around this?
 
T

Tim Wilson

What about a custom Region? You could use a GraphicsPath object to build the
desired shape of your Form and then just create a Region object, passing
this GraphicsPath object into the constructor, and assign it to the Region
property of the Form.
 
H

Herfried K. Wagner [MVP]

* "Steve C. Orr said:
I have a borderless form with it's Opacity set to 60% so the background
shows through. It looks very nice. But I'd like to round the corners of
this form. All the techniques I've seen so far for creating shaped forms
involve using the TransparencyKey property of the form. But this doesn't
work with a form that is translucent because the form color varies at
runtime based on the background colors that are showing through.

\\\
\\\
Me.FormBorderStyle = FormBorderStyle.None
Me.Height = 300
Me.Width = 400
Dim p As New Drawing2D.GraphicsPath()
p.StartFigure()
p.AddArc(New Rectangle(0, 0, 40, 40), 180, 90)
p.AddLine(40, 0, Me.Width - 40, 0)
p.AddArc(New Rectangle(Me.Width - 40, 0, 40, 40), -90, 90)
p.AddLine(Me.Width, 40, Me.Width, Me.Height - 40)
p.AddArc(New Rectangle(Me.Width - 40, Me.Height - 40, 40, 40), 0, 90)
p.AddLine(Me.Width - 40, Me.Height, 40, Me.Height)
p.AddArc(New Rectangle(0, Me.Height - 40, 40, 40), 90, 90)
p.CloseFigure()
Me.Region = New Region(p)
Me.BackColor = Color.Red
p.Dispose()
///
 
S

Steve C. Orr [MVP, MCSD]

This is perfect!
Thank you so much.


Herfried K. Wagner said:
\\\
\\\
Me.FormBorderStyle = FormBorderStyle.None
Me.Height = 300
Me.Width = 400
Dim p As New Drawing2D.GraphicsPath()
p.StartFigure()
p.AddArc(New Rectangle(0, 0, 40, 40), 180, 90)
p.AddLine(40, 0, Me.Width - 40, 0)
p.AddArc(New Rectangle(Me.Width - 40, 0, 40, 40), -90, 90)
p.AddLine(Me.Width, 40, Me.Width, Me.Height - 40)
p.AddArc(New Rectangle(Me.Width - 40, Me.Height - 40, 40, 40), 0, 90)
p.AddLine(Me.Width - 40, Me.Height, 40, Me.Height)
p.AddArc(New Rectangle(0, Me.Height - 40, 40, 40), 90, 90)
p.CloseFigure()
Me.Region = New Region(p)
Me.BackColor = Color.Red
p.Dispose()
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top