OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 17-05-2005, 10:03
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default Text selection and sizing

I am writing a macro in CD12 that will take input from a text box, create a rectangle, center the text from the input textbox, enlarge the text to nearly fill the width of the rectangle, then duplicate the whole thing like Alex's Tiler Script.

The problem that I am having is two fold...
1. The text sting (being usually just one word) is not stretching properly. I want the text to fill no more than a 3.5" width, however the current code makes it 350% larger. This won't work with with text that is already almost 3.5". What I would like to see happen is the text becomes 3.5" wide by 2" tall, regardless of the words character count.

2. The text string and the original rectangle are being sized together. I only want the text to scale, not the rectangle. I'm having trouble determining how to make the text my only active selection.

The rectangle size is based on Letter Paper size (w/2 and h/4) hence 4.25"x by 2.75"y. Then the text (and rectangle) are duplicated 8-up (2w x 4h).

Code:
Sub cmdOK_Click()
    ' Description:
    '                Create word sheets
    '
    Dim s1 As Shape
    Dim s2 As Shape
    Dim doc As Document
    
    Set s1 = ActiveLayer.CreateRectangle(0, 0, 4.25, 2.75)
    s1.Fill.ApplyNoFill
    s1.Outline.SetProperties 0.003, OutlineStyles(0), CreateCMYKColor(0, 0, 0, 0), ArrowHeads(0), _
                ArrowHeads(0), False, False, cdrOutlineButtLineCaps, cdrOutlineMiterLineJoin, 0#, 100
    
    ActiveLayer.CreateArtisticText 0, 0, txtInput.Text, cdrEnglishUS, cdrCharSetDefault, "Arial Black", _
                14, cdrFalse, cdrFalse, cdrNoFontLine, cdrCenterAlignment
    
    Set s2 = ActiveSelection
    
    s2.AlignToShape cdrAlignHCenter, s1, cdrTextAlignBoundingBox
    s2.AlignToShape cdrAlignVCenter, s1, cdrTextAlignBoundingBox
    ActiveDocument.ReferencePoint = cdrCenter
    s2.Stretch 3.5
    
    ActiveDocument.CreateSelection s2, s1
    
    Dim dup1 As ShapeRange
    Set dup1 = ActiveSelection.DuplicateAsRange(4.25, 0)
    dup1.OrderToFront
    
    'Continue Duplication
End Sub
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 17-05-2005, 10:11
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Quote:
s2.Stretch 3.5
What this line does is make the text 3.5 times larger. It doesn't make its width 3.5". For that you need to call s2.SetSize 3.5. Or better yet, use Shape.SetBoundingBox method which allows you to specify a rectangle for the object to occupy and it will be stretched/positioned there to fit...
Reply With Quote
  #3  
Old 17-05-2005, 11:06
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Code:
s2.SetBoundingBox(s1.SizeWidth/2, s1.SizeHeight/2, 3.5, 2, False, cdrCenter)
This is what I put in and the compiler keeps popping up saying "Expected: ="

I don't get it...

Also, need to address how to only have the text selected during sizing, so as not to resize the rectangle.

I thought about re-ordering the way in which the shapes are created...
i.e. create the text, resize, then create the rectangle and center them.

I guess I could actually not even put in the rectangle. If I can get this SetBoundingBox thing figured out.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #4  
Old 17-05-2005, 11:18
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

When you can a subroutine in VBA you don't use paretheses for parameters. However you do when you call a function. Comare this:

Code:
Sub MySub(x1 as double, y1 as double)
End Sub

Function MyFnc(x1 as double, y1 as double) As Double
End Function
Now you would call these two methods differently:

Code:
MySub 1, 2
a = MyFnc(1, 2)
So, in your case, you need to call s2.SetBoundingBox x, y, sx, sy and no paretheses...

Another thing, all shape creation methods (such as CreateRectangle and CreateArtisticText) return the shape created as return value, so you don't have to use Selection to manipulate the shapes afterwards. For example:

Instead of this:

Code:
ActiveLayer.CreateRectangle x1, y1, x2, y2
Set sRect = ActiveSelection
you should use:

Code:
Set sRect = ActiveLayer.CreateRectangle(x1, y1, x2, y2)
(also note change of syntax in calls to CreateRectangle above. In first example it is being called as a subroutine (no return value), so the coordinates are not enclosed in paretheses, in the second case it is a function and parameters must be in parentheses... A bit confusing but one gets used to this with experience...
Reply With Quote
  #5  
Old 17-05-2005, 12:12
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Another quick question...
In my macro I have a button that inserts an additional page and sets the focus back on "txtInput" textbox. Is there a way to have the existing text in the text box selected. Currently it is only placing the cursor at the end of the word. I guess I could set txtInput.Text to equal "" and go from there, but I would still like to know if there is a way to select all text in the box when focus is set.

BTW... Here is the completed code with various changes...
Code:
Private Sub cmdAdd_Click()
    ActiveDocument.AddPages (1)
    txtInput.SetFocus
End Sub

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Sub cmdOK_Click()
    ' Description:
    '                Create word sheets
    '
    ActiveLayer.CreateArtisticText 0, 0, txtInput.Text, cdrEnglishUS, cdrCharSetDefault, "Arial Black", _
                14, cdrFalse, cdrFalse, cdrNoFontLine, cdrCenterAlignment

    ActiveShape.SetBoundingBox 0.375, 0.375, 3.5, 2, False, cdrCenter
    
    Dim dup1 As ShapeRange
    Set dup1 = ActiveSelection.DuplicateAsRange(4.25, 0)
    dup1.OrderToFront
    
    ActivePage.Shapes.All.AddToSelection
    Dim dup2 As ShapeRange
    Set dup2 = ActiveSelection.DuplicateAsRange(0, 2.75)
    
    Dim dup3 As ShapeRange
    Set dup3 = ActiveSelection.DuplicateAsRange(0, 2.75)
    
    Dim dup4 As ShapeRange
    Set dup4 = ActiveSelection.DuplicateAsRange(0, 2.75)
End Sub
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #6  
Old 17-05-2005, 14:19
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Yes, just add an event handler for textbox's Enter event. This will be called as soon as the textbox gets keyboard focus. There you can change the text selection:

Code:
Private Sub TextBox1_Enter()
    TextBox1.SelStart = 0
    TextBox1.SelLength = Len(TextBox1.Text)
End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 20:41.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com