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 09-08-2006, 07:17
roly0022
Guest
 
Posts: n/a
Default Devolop in VS 2005

I try to create a cdr from vs 2005 in c#, i reference the COM object(Interop.CorelDRAW.dll) but don't work, i get a reference error.
It's posible create a program that create/modify corel pages?

Thanks.-
Reply With Quote
  #2  
Old 09-08-2006, 07:53
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Yes, it's possible. I don't know why you have the problem. I just created a simple solution which just creates a new document in CorelDRAW X3 and draws a red rectangle on the page.

The actual function that does this looks like this:

Code:
private void DoSomething()
{
    try
    {
        CorelDRAW.Application draw = new CorelDRAW.Application();
        draw.Visible = true;
        CorelDRAW.Document doc = draw.CreateDocument();
        CorelDRAW.Shape rect = doc.ActiveLayer.CreateRectangle2(0, 0, 2, 2, 0, 0, 0, 0);
        rect.Fill.UniformColor.RGBAssign(255, 0, 0);
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
}
I'm attaching the full source code of Visual Studio 2005 solution as well the the complied binaries for you to try...
Attached Files
File Type: zip Sources.zip (11.9 KB, 437 views)
File Type: zip Executable.zip (396.6 KB, 437 views)
Reply With Quote
  #3  
Old 11-08-2006, 09:37
roly0022
Guest
 
Posts: n/a
Default

Thanks for answer, i try the code and works fine. There is a book, webpage where i can find about this?

MeanWhile i try to do this, i have a template, i open it in VS2005 and put the code in the box CodArt1, but i don't know how to put an image and replace with the image that correct with the code in bd, can manage images as jpg?

Thanks again
Attached Files
File Type: cdr template.cdr (12.9 KB, 314 views)

Last edited by roly0022; 11-08-2006 at 12:23.
Reply With Quote
  #4  
Old 07-09-2006, 13:31
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Visual Studio 2005

Alex if you get a moment could you post a similar solution in VB instead of C#. I am finally taking a class in Visual Basic 2005 and I want to play with it and CorelDRAW X3.

The first questions I would have is how do you test if CorelDRAW and your document are all ready open. I see using it more that way, then opening Draw and creating new document.

Thanks,

Shelby
Reply With Quote
  #5  
Old 08-09-2006, 08:15
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

I'd be interested in this as well...
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #6  
Old 08-09-2006, 09:25
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Ok, here is the same project but written in VB.NET 2005

Essentially, here are the steps:

- create a new VB project in Visual Studio.
- Right click the project in the Solution Explorer window and choose "Add Reference..." from the pop up menu
- Go to the "COM" tab of the References dialog and locate "Corel - CorelDRAW 13.0 Library" and click Ok. This will import CorelDRAW type libraries...
- On your default VB form add a simple push button and double-click it to add the Click event handler.
- Make your code look like this:

Code:
Public Class Form1
  Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
    DoSomething()
  End Sub

  Private Sub DoSomething()
    Try
      Dim draw As CorelDRAW.Application = New CorelDRAW.Application()
      draw.Visible = True
      Dim doc As CorelDRAW.Document = draw.CreateDocument()
      Dim rect As CorelDRAW.Shape = doc.ActiveLayer.CreateRectangle2(0, 0, 2, 2, 0, 0, 0, 0)
      rect.Fill.UniformColor.RGBAssign(255, 0, 0)
    Catch e As Exception
      MessageBox.Show(e.Message)
    End Try
  End Sub
End Class
Compile and run. When you click the button, CorelDRAW will launch, a new document will be created and a red rectangle will be created on the page.

See attached the full project sources and compiled executable.
Attached Files
File Type: zip SourcesVB.zip (13.8 KB, 339 views)
File Type: zip ExecutableVB.zip (394.7 KB, 330 views)
Reply With Quote
  #7  
Old 08-09-2006, 11:48
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Vb 2005

Alex like always you are amazing. Your example works perfectly. So the second half of my question. How do you tell if CorelDRAW is open and your document is open?

I see working on current documents more then creating new ones. Just wondering the proper way to handle this. Thanks!

Shelby
Reply With Quote
  #8  
Old 09-09-2006, 18:39
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Well, there is no easy way of determining whether CorelDRAW is already running or not. However I don't think there is a need anyway. When you use object model, it always connects to the same running instance of CorelDRAW or starts one when it isn't running. So, if CorelDRAW is running, using CorelDRAW.Application object will communicate with the running copy and will not start a new one.

That's why you just create an instance of the Application object and make the application visible (in case it was started by the automation, in which case it will be invisible by default).

Then you can do all the necessary checks to see if a document is open or if that document is the one you'd expect...

I hope this makes sense.
Reply With Quote
  #9  
Old 10-09-2006, 15:08
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Sense

Makes perfect sense. Now lets see what I can so with the baby! Thanks for the help,

Shelby
Reply With Quote
  #10  
Old 25-11-2006, 17:41
LeonoCoder LeonoCoder is offline
Junior Member
 
Join Date: Nov 2006
Posts: 10
Default VB.Net

Hi, I have programmed for a long time in VB6, now I'm trying Corel Macros with VBA, but ?, is VBA the better option? what are the beneficts to build a Corel application in VB.Net?, Speed, distribution, code security, more tools?
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
Run macro from VB.Net 2005 jabky CorelDRAW/Corel DESIGNER VBA 4 04-07-2006 21:37


All times are GMT -5. The time now is 03:22.


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