473,544 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA function for rounded pdf rectangles

The following Access VBA function creates a string that can be used in
a pdf stream to draw or fill a rectangle of a given color with rounded
corners:

'Begin code-----------
Public Function DrawRoundedRect angle(dblX As Double, dblY As Double, _
dblR As Double, dblW As Double, dblH As Double, _
dblThickness As Double, dblLineR As Double, dblLineG _
As Double, dblLineB As Double, boolFill As Boolean, dblFillR _
As Double, dblFillG As Double, dblFillB As Double) As String
Dim strTemp As String
Dim strCR As String
'C1 = 1 - 4 * (SQRT(2) - 1) / 3 (used for 1/4 circle Bezier Curves)
'As shown in http://www.tinaja.com/glib/bezcirc.pdf
Const C1 = 0.447715

'dblX = X coordinate of LL of rounded rectangle in points
'dblY = Y coordinate of LL of rounded rectangle in points
'dblR = Radius of rounded corners in points
'dblH = Height of rounded rectangle in points
'dblW = Width of rounded rectangle in points
'dblThickness = Thickness of line used to draw the rounded _
rectangle in points
'dblLineR = Red component of line color 0.0 to 1.0
'dblLineG = Green component of line color 0.0 to 1.0
'dblLineB = Blue component of line color 0.0 to 1.0
'boolFill = Fill the rectangle when True, Draw the outline when False
'dblFillR = Red component of fill color 0.0 to 1.0
'dblFillG = Green component of fill color 0.0 to 1.0
'dblFillB = Blue component of fill color 0.0 to 1.0
strCR = Chr(13)
strTemp = "%Rounded Rectangle" & strCR
strTemp = strTemp & "q" & strCR
strTemp = strTemp & CStr(dblThickne ss) & " w" & strCR
strTemp = strTemp & CStr(dblLineR) & " " & CStr(dblLineG) & " " _
& CStr(dblLineB) & " RG" & strCR
If boolFill Then
'h = ClosePath operator
strTemp = strTemp & "h" & strCR
strTemp = strTemp & CStr(dblFillR) & " " & CStr(dblFillG) & " " _
& CStr(dblFillB) & " rg" & strCR
End If
strTemp = strTemp & CStr(Round(dblR + dblX, 6)) & " " _
& CStr(dblY) & " m" & strCR
strTemp = strTemp & CStr(Round(dblX + dblW - dblR, 6)) _
& " " & CStr(dblY) & " l" & strCR
strTemp = strTemp & CStr(Round(dblX + dblW - C1 * dblR, 6)) & " " _
& CStr(dblY) & " " & CStr(Round(dblX + dblW, 6)) & " " _
& CStr(Round(dblY + C1 * dblR, 6)) & " " _
& CStr(Round(dblX + dblW, 6)) _
& " " & CStr(Round(dblY + dblR, 6)) & " c" & strCR
strTemp = strTemp & CStr(Round(dblX + dblW, 6)) & " " _
& CStr(Round(dblY + dblH - dblR, 6)) & " l" & strCR
strTemp = strTemp & CStr(Round(dblX + dblW, 6)) & " " _
& CStr(Round(dblY + dblH - C1 * dblR, 6)) & " " _
& CStr(Round(dblX + dblW - C1 * dblR, 6)) & " " _
& CStr(Round(dblY + dblH, 6)) & " " _
& CStr(Round(dblX + dblW - dblR, 6)) & " " _
& CStr(Round(dblY + dblH, 6)) & " c" & strCR
strTemp = strTemp & CStr(Round(dblX + dblR, 6)) & " " _
& CStr(Round(dblY + dblH, 6)) & " l" & strCR
strTemp = strTemp & CStr(Round(dblX + C1 * dblR, 6)) _
& " " & CStr(Round(dblY + dblH, 6)) & " " _
& CStr(dblX) & " " & CStr(Round(dblY + dblH - C1 * dblR, 6)) & " " _
& CStr(dblX) & " " & CStr(Round(dblY + dblH - dblR, 6)) & " c" & strCR
strTemp = strTemp & CStr(dblX) & " " _
& CStr(Round(dblY + dblR, 6)) & " l" & strCR
strTemp = strTemp & CStr(dblX) & " " _
& CStr(Round(dblY + C1 * dblR, 6)) & " " _
& CStr(Round(dblX + C1 * dblR, 6)) _
& " " & CStr(dblY) & " " & CStr(Round(dblX + dblR, 6)) _
& " " & CStr(dblY) & " c" & strCR
If boolFill Then
'f = Fill operator
strTemp = strTemp & "h f" & strCR
Else
strTemp = strTemp & "S" & strCR
End If
strTemp = strTemp & "Q" & strCR
DrawRoundedRect angle = strTemp
End Function

Function Round(varIn As Variant, intPlaces As Integer) As Variant
Round = Int(10 ^ intPlaces * varIn + 0.5) / 10 ^ intPlaces
End Function
'End code-------------

Perhaps someone will find it useful. BTW, the output from this
function can be assigned to strStream in:

http://groups-beta.google.com/group/...8ab160cf?hl=en

which would in effect make the single pdf page a canvas for any of the
pdf drawing operators. I suppose I should make some of the function's
arguments optional. This function has worked in all the situations I
have tried but use at your own risk, etc. Note: I didn't test out the
normal rounded rectangle without fill after adding in the code for
optional filling. I'll post back if the fill code broke the non-fill
case. I specified two sets of colors in case I want to put a border
with a different color around the filled rectangle someday.

James A. Fortune

Nov 13 '05 #1
1 3588
ji********@comp umarc.com wrote:
...
case. I specified two sets of colors in case I want to put a border
with a different color around the filled rectangle someday.


By simply replacing the "h f" string (closepath, fill) near the end of
the function with "b" (closepath, fill, stroke) I was able to get the
filled rectangle with a border in a different color.

James A. Fortune

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
18649
by: Penguin | last post by:
At some long ago time Steve Jorgensen answered thus: Subject: Re: How can I round a time? Newsgroups: comp.databases.ms-access Date: 1998/12/11 Access represents a date internally as a double and will convert between date/time and double automatically. The double value Access (or VB) creates is based on 1 day = 1.0 and the fractional...
3
22416
by: cai_rongxi | last post by:
Hi, Can some body share the code to find the intersection of two rectangles? Thanks in advance
9
7373
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something different. Programming Microsoft Windows with Microsoft Visual Basic.NET "The Round method with a single argument return the whole number nearest...
6
7595
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
0
1129
by: Fir5tSight | last post by:
Hi All, Again I apologize for posting this topic at the wrong forum, because I don't know where else I can get help on this matter. This is about invisible lines and rectangles in a PDF file. Other developers used "Active Reports" API in Visual Basic to create the PDF file. Since they set some sections to "visible = false", the...
7
7051
by: ddecoste | last post by:
I have a need to add a visual representation to some data in Access. I need to draw a matix of squares inside another square. I have all the data that I need in a record in Access. The data changes according to what the user inputs. I know that Access does not allow you to draw on forms so I decided to put the output in an Excel file for...
3
1834
by: anupamsps | last post by:
HI all, This is my first posting in this forum. I am confused about how to write a function that returns a value rounded to the nearest value of a double variable say X. when X is positive it is simple rounding seems to work. But the same logic fails when X < 0. In Fortran there is intrinsic function called ANINT which serves this...
9
1652
by: active | last post by:
I need a control that displays a grid of rectangles. That is, like a brick wall except the rectangles are lined up. In VB6 I used such a control (may have been called FlexGrid but I'm not sure.) I did see the DataGrid control but that seems oriented to DB usage. It's probably much more complex than what I need, but I'm not sure about...
3
4408
by: cowboyrocks2009 | last post by:
Hi, I am trying to write a Java program to plot rectangles with different colors side by side non overlapping but unfortunately I am unable to do that as of now. Suppose I want to create 3 rectangles:- 100 - 200 200 - 300 300 - 400 I want to have 3 rectangles non overlapping and adjacent to each other with 3 different colors. I am new...
0
7431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7370
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7779
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5920
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1848
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
674
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.