Draw rectangle with rounded corners

  • Thread starter Thread starter Hallgeir
  • Start date Start date
H

Hallgeir

I want to have a rectangle with rounded corners as a frame around some of
the controls in my report. Does anyone know if there is an easy way to do
this, or do I have to draw it in mspaint or simular and then insert it as a
picture file in my report.

Regards Hallgeir
 
Hallgeir said:
I want to have a rectangle with rounded corners as a frame around some of
the controls in my report. Does anyone know if there is an easy way to do
this, or do I have to draw it in mspaint or simular and then insert it as a
picture file in my report.


You can use the Line and Circle methods in the Print event
of the section containing the controls. Kind of tedious
calculating the coordinates of all the end points, but
doable.

For example, let's say you have two text boxes, txt1 and
txt2, the same width and txt1 above txt2, and you want your
1/4 inch radius rounded corner rectangle around both of
them:

Const Pi As Double = 3.14159265
Const R As Long = 0.25 * 1440
Line (txt1.Left + R, txt1.Top)- _
(txt1.Left + txt1.Width - R, txt1.Top)
Line (txt1.Left, txt1.Top + R)- _
(txt1.Left, txt2.Top + txt2.Height - R)
Line (txt1.Left + txt1.Width, txt1.Top + R)- _
(txt1.Left + txt1.Width, txt2.Top + txt2.Height - R)
Line (txt1.Left + R, txt2.Top + txt2.Height)- _
(txt1.Left + txt1.Width - R, txt2.Top + txt2.Height)
Circle (txt1.Left + R, txt1.Top + R), R, , Pi / 2, Pi
Circle (txt1.Left + txt1.Width - R, _
txt1.Top + R), R, , 0, Pi / 2
Circle (txt1.Left + R, _
txt2.Top + txt2.Height - R), R, , Pi, 3 * Pi / 2
Circle (txt1.Left + txt1.Width - R, _
txt2.Top + txt2.Height - R), R, , 3 * Pi / 2, 0
 
Here is a generic function that you can save in a standard module. Call it
as noted in the code. For instance

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
RoundCornerBox 4000, 6000, 100, 200, 300, Me
End Sub

Private Sub Report_Page()
RoundCornerBox Me.Width - 200, 13000, 100, 100, 300, Me, 8
End Sub

Sub RoundCornerBox( _
lngWidth As Long, _
lngHeight As Long, _
lngTop As Long, _
lngLeft As Long, _
lngRadius As Long, _
rptReport As Report, _
Optional intLineWeight As Integer = 1)
'call this from a report with syntax like
'
'Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' RoundCornerBox 4000, 6000, 100, 200, 300, Me
'End Sub

Dim sngStart As Single
Dim sngEnd As Single
Dim dblPI As Double
dblPI = 3.14159265359
rptReport.DrawWidth = intLineWeight

'Top Left
sngStart = 2 * dblPI * 0.25 ' Start of pie slice.
sngEnd = 2 * dblPI * 0.5 ' End of pie slice.
rptReport.Circle (lngLeft + lngRadius, _
lngTop + lngRadius), _
lngRadius, vbBlue, sngStart, sngEnd
'Top line
rptReport.Line (lngLeft + lngRadius, lngTop)- _
(lngLeft + lngWidth - lngRadius, lngTop)

'Top Right
sngStart = 2 * dblPI * 0.000001
sngEnd = 2 * dblPI * 0.25
rptReport.Circle (lngLeft + lngWidth - _
lngRadius, lngTop + lngRadius), _
lngRadius, vbBlue, sngStart, sngEnd
'right line
rptReport.Line (lngLeft + lngWidth, _
lngTop + lngRadius)- _
(lngLeft + lngWidth, _
lngTop + lngHeight - lngRadius)

'Bottom right
sngStart = 2 * dblPI * 0.75
sngEnd = 2 * dblPI
rptReport.Circle (lngLeft + lngWidth - _
lngRadius, lngTop + lngHeight - lngRadius), _
lngRadius, vbBlue, sngStart, sngEnd
rptReport.Line (lngLeft + lngRadius, _
lngTop + lngHeight)- _
(lngLeft + lngWidth - lngRadius, lngTop + lngHeight)

'Bottom Left
sngStart = 2 * dblPI * 0.5
sngEnd = 2 * dblPI * 0.75
rptReport.Circle (lngLeft + lngRadius, _
lngTop + lngHeight - lngRadius), _
lngRadius, vbBlue, sngStart, sngEnd
'right line
rptReport.Line (lngLeft, lngTop + lngRadius)- _
(lngLeft, lngTop + lngHeight - lngRadius)

End Sub
 
Back
Top