OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Adding controls to forms at runtime (http://forum.oberonplace.com/showthread.php?t=1260)

ddonnahoe 12-12-2005 15:24

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


Lev 13-12-2005 13:35

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


zlatev 14-12-2005 06:52

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.

ddonnahoe 14-12-2005 07:15

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.

ddonnahoe 14-12-2005 09:01

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


Lev 14-12-2005 11:35

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

ddonnahoe 15-12-2005 10:53

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?

ddonnahoe 15-12-2005 15:57

2 Attachment(s)
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.

Lev 16-12-2005 09:46

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
...


ddonnahoe 16-12-2005 15:41

1 Attachment(s)
Here is what I get at the "Collect.Add Inst, Str(numColor)" line...


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

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