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 14-10-2004, 15:33
chinkyk
Guest
 
Posts: n/a
Default simple example

Hello,

Can someone help me with an simple example with dealing with user interfaces.


this is a starting point of my work and this will also give me an idea of how to implement rest of the stuff i am doing



thanks
Reply With Quote
  #2  
Old 17-10-2004, 11:03
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: simple example

Ok, here are all the steps that you need to create your new project with user interface:

1. Create a new GMS file. For this do the following:
- Go to CorelDRAW's GMS folder which is by default in "C:\Program Files\Corel\Corel Graphics 12\Draw\GMS".
- Create a new empty text file (right click in the folder and select New>Text Document from the pop-up menu").
- Rename the created file to "ObjCreator.gms" (for example)
2. Now start CorelDRAW
3. Press Alt-F11 to open up VBA editor.
4. You should see something similar to the UI pictured in the attached Figure 1.
5. In the upper left corener you should see Project Explorer docker which lists all installed GMS modules. Find the project titled "GlobalMacros (ObjCreator.gms)" (It is shown selected in the Fig 1)
6. Now you need to change the default project name (GlobalMacros) to something unique. In the Properties window right below Project Explorer you should see the name of the project shown. Select it and change the name to, say, "ObjCreator"
7. Expand the "ObjCreator (ObjCreator.gms)" project. See Fig 2 for reference.
8. Now right-click the module and select "Insert>UserForm" from the popup menu (Fig 3)
9. This will create a new empty form entitled "UserForm1". You will also see a toolbox window which contains all the default controls you can put on the form. (Fig 4)
10. With the form still visible, go to the Properties window and change the "(Name)" property from "UserForm1" to "MainForm" to represent the purpose of the dialog. You might use any other name, or just leave it as UserForm1 if that suits you.
11. Change the form caption to "Object Creator" (Fig 5)
12. Now, use the toolbox to layout controls you need on the form:
- Select and drag a radio button onto the form. Change the default (Name) properties from "OptionButton1" to "RadioLine" and change its caption to "Line" (Fig 6).
- Add another radio button and change its name to RadioRectangle and caption to "Rectangle"
- Add a text label (shown as "A" in the toolbox) and change its caption to "X1:"
- Add a text box (shown as "ab|") next to the label and change its name to "txtX1" (Fig 7)
- Add another label below and change its caption to "Y1:"
- Add one more text box and change its name to "txtY1"
- In the same manner add labels and text boxes for X2 and Y2.
- Add a pushbutton to the dialog and change its name to "cmdOK" and caption to "OK"
- Add one button named "cmdCancel" and with caption "Cancel"
Now you should see a dialog similar to one pictured on Fig8.
13. Now let's add some code to make this form live. Double-click on the Cancel button. This will add a default event handler which will be called when the button is pressed. Add just "Unload Me" command in it to close the form without doing anything else (Fig 9).
14. In similar manner you can add the event handler to the OK button which could look like this:

Code:
Private Sub cmdOK_Click()
    Dim bDrawLine As Boolean
    Dim x1 As Double, y1 As Double
    Dim x2 As Double, y2 As Double
    
    If RadioLine.Value <> 0 Then
        bDrawLine = True
    ElseIf RadioRectangle.Value <> 0 Then
        bDrawLine = False
    Else
        MsgBox "Select either Line or Rectangle option", vbCritical
        Exit Sub
    End If
    
    x1 = Val(txtX1.Text)
    y1 = Val(txtY1.Text)
    x2 = Val(txtX2.Text)
    y2 = Val(txtY2.Text)
    
    If x1 = x2 And y1 = y2 Then
        MsgBox "Points (x1,y1) and (x2,y2) can't be the same", vbCritical
        Exit Sub
    End If
    
    If bDrawLine Then
        ActiveLayer.CreateLineSegment x1, y1, x2, y2
    Else
        ActiveLayer.CreateRectangle x1, y1, x2, y2
    End If
End Sub
Now just a few final touches left.

15. Right-click on ObjCreator (ObjCreator.gms) project in Project Explorer and select Insert>Module. Change the module name to MainModule in the Properties window.
16. Add the following macro to it, which can be used to show the form:

Code:
Sub ShowForm()
    MainForm.Show vbModal
End Sub
See Fig 10.

Now you are as good as done. You can run the macro or add a button to CorelDRAW toolbar. I have attached the complete GMS file for you to see.
Attached Images
          
Attached Files
File Type: gms ObjCreator_900.gms (19.0 KB, 540 views)
Reply With Quote
  #3  
Old 18-10-2004, 13:39
chinkyk
Guest
 
Posts: n/a
Default Re: simple example

Thanks a lot Alex this will help me a lot
Reply With Quote
  #4  
Old 19-10-2004, 14:50
chinkyk
Guest
 
Posts: n/a
Default simple question

I am a new user to this corel draw VBA programming
and I am helping my staff to automise their work
now Ales x helped me a lot to by giving a perfect example of and showing every step to drw a line or rectangle that helped a lot and now i can actually input values and my work get sdone.
I dont know whether i am making my problem clear.but i hope one understands it
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Bar code generator Webster Code Critique 2 06-09-2010 01:41
Installer for GMS ssb CorelDRAW/Corel DESIGNER VBA 8 15-02-2005 02:22
Simple Loop? dan CorelDRAW/Corel DESIGNER VBA 3 13-10-2004 13:31
exporting to jpg ddonnahoe CorelDRAW/Corel DESIGNER VBA 7 26-01-2004 11:53


All times are GMT -5. The time now is 15:54.


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