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 12-12-2005, 14:24
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 Adding controls to forms at runtime

I am trying to create a macro that will...
1. Create a temporary palette from the active document...
2. cycle through the new palette...
3. for any named color, add a checkbox contol to my form.

The problem I am having is step 3.

What I would like to see happen is each new checkbox be named
Code:
.Name = "CheckColor" & numColor
where numColor is an incremental integer.

I would also like to be able to create a Command button to the left of my new checkbox that will simulate the color from the palette. I assume that this needs to be done through HSV conversion, but have no idea how to begin. I tried looking through the color replacer to understand this step a little better, to no avail.

Here is my code so far for the adding checkboxes...
Code:
Option Explicit

Private Sub UserForm_Initialize()
    Dim p As Page
    Dim CSColor As Color
    Dim col As New Collection
    Dim s As Shape
    Dim numColor As Integer, tp As Integer
    Dim CSpal As Palette
    Dim ClrCtrl As Control
    
    numColor = 1
    tp = 18
    
    Set CSpal = Application.Palettes.CreateFromDocument("MyPalette")
    
    For Each CSColor In CSpal.Colors
        If CSColor.Name <> "" Then
            With frmColorSeps
                .Controls.Add frmColorSeps!CheckBox, , Visible
                    With ActiveControl
                        .Name = "CheckColor" & numColor
                        .Caption = CSColor.Name
                        .Height = 18
                        .Left = 6
                        .Top = tp
                        .Width = 180
                    End With
            End With
            tp = tp + 18
            numColor = numColor + 1
        End If
    Next CSColor
End Sub
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #2  
Old 13-12-2005, 12:35
Lev
Guest
 
Posts: n/a
Default

here is my variant:
Code:
Option Explicit

Private Sub UserForm_Initialize()
     Dim p As Page
     Dim CSColor As Color
     Dim col As New Collection
     Dim s As Shape
     Dim numColor As Integer, tp As Integer
     Dim CSpal As Palette
     Dim ClrCtrl As Control
 
     numColor = 1
     tp = 18

Set CSpal = Application.Palettes.CreateFromDocument("MyPalette")
      For Each CSColor In CSpal.Colors
         If CSColor.Name <> "" Then
             With frmColorSeps1
                 Set ClrCtrl = Controls.Add("Forms.CheckBox.1", "", Visible)
                     With ClrCtrl
                         .Name = "CheckColor" & numColor
                         .Caption = CSColor.Name
                         .Height = 18
                         .Left = 6
                         .Top = tp
                         .Width = 180
                         .Visible = True
                     End With
             End With
             tp = tp + 18
             numColor = numColor + 1
         End If
     Next CSColor
End Sub
now you can address your check boxes like
Code:
Private Sub CommandButton1_Click()
With Controls("CheckColor1")
MsgBox .Name & vbCrLf & .Caption & vbCrLf & .Value
End With
End Sub
Reply With Quote
  #3  
Old 14-12-2005, 05:52
zlatev
Guest
 
Posts: n/a
Question One question

Why do you refuse to use multiselect listbox? Or two listboxes - one with full list of all named colors met in document, and one with the selected ones. And buttons to add/remove from selection.
Reply With Quote
  #4  
Old 14-12-2005, 06: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

zlatev, 2 words, "Stream lining".

I am trying to create text that is set in the document colors so the will print on each plate at separation time.

I know there is this capability in the separations and print dialog, but the tiny size of this has caused various concerns among the "powers that be" within my company (an 11 person workforce that is family owned). The saying, "It's hard to teach an old dog new tricks." is my boss's motto.

He wants to make everything idiot proof. I think, in doing so, just creates more problems, but at least I'm getting paid to do this stupid routine.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #5  
Old 14-12-2005, 08:01
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

In the code below, I am trying to resize the form as controls are added via userform_initialize code. At the If statement, I get an "Object variable or With block variable not set" error.

Any insight?
Code:
Dim nh As Integer

Private Sub UserForm_AddControl(ByVal Control As MSForms.Control)
    With Me
    If .ActiveControl.Top > 54 Then
        nh = nh + 18
        .Height = nh
    End If
    End With
    
End Sub
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #6  
Old 14-12-2005, 10:35
Lev
Guest
 
Posts: n/a
Default

Why do you want to resize the form each time a CheckBox is added? You can resize it only once, after all controls are added.
Code:
Private Sub UserForm_Initialize()
...
Next CSColor
frmColorSeps.Height = tp + 40
End Sub
in my case 40 - was good enough
Reply With Quote
  #7  
Old 15-12-2005, 09:53
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

My newest problem is, when I create the palette from the document, if the document contains CMYK Black, the palette shows the color name as
C0 M0 Y0 K100
I want the color to be named "Black".

How can I change this via VBA?
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #8  
Old 15-12-2005, 14:57
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

OK I fixed the part above after much hair pulling, but when it comes to Collections, I'm completely lost.

I have attached the GMS for my project. Would someone please look at it and tell me what I am doing wrong? Use the attached CDR file for testing.

What is supposed to happen is this...
1. as the module starts running it creates a palette from the document then creates the controls for the form based on those colors.

2. after the form is created and presented to the user, it is up to the user to turn off color plates that aren't needed and assign a 1, 2, 3 color order in the text boxes.

3. Here comes the hard part. After creating the paragraph text on the page, the code should go back and color each line of text with the appropriate color. This is why I am trying to build a collection, so that I can reference the key for each item.

If anyone can think of a different or better way to do this last part, please HELP. I'm desperate.
Attached Files
File Type: gms PlateColors.gms (41.0 KB, 601 views)
File Type: cdr Test.cdr (14.1 KB, 593 views)
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #9  
Old 16-12-2005, 08:46
Lev
Guest
 
Posts: n/a
Default

The collection key must be string type
Code:
Collect.Add Inst, Str(numColor)
MsgBox Collection - will not work

here you take the idx of active palette but remove the color from CSpal palette
Code:
idx = ActivePalette.GetIndexOfColor(CSColor2)
CSpal.RemoveColor idx
change it to idx = CSpal.GetIndexOfColor(CSColor2)
or even better:
Code:
idx = CSpal.FindColor("C0 M0 Y0 K100")
If idx Then 
CSpal.RemoveColor idx
...

Last edited by Lev; 16-12-2005 at 10:31.
Reply With Quote
  #10  
Old 16-12-2005, 14:41
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

Here is what I get at the "Collect.Add Inst, Str(numColor)" line...
Attached Images
 
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
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
Calendar Date Selection ddonnahoe CorelDRAW/Corel DESIGNER VBA 3 15-01-2004 10:08


All times are GMT -5. The time now is 12:24.


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