PDA

View Full Version : Solved: simulating CorelDraw or Photoshop functionality



TrippyTom
07-26-2006, 01:06 AM
I made a form modeless thinking I could simulate something like a photoshop toolbar for my macros. It basically consists of a textbox and 8 different buttons for similar macros that move shapes around. The thing is, it's not acting exactly as I expected:

1) Anything I do is noted as ONE action until the focus goes back to the document, so when I UNDO, it undoes EVERYTHING instead of the last button clicked.

Is that the way it's supposed to behave? If so, how does one make it behave like a normal toolbar in Photoshop or CorelDraw? I'm sure it's probably just a property I have set wrong in my form or something.

TrippyTom
07-31-2006, 11:48 AM
Ok, let me put it another way. Maybe that will help.

Is it possible to have just a textbox in a userform to pass along a variable to various macros I have? No close button; I plan to keep the form up all the time like a toolbar.

...or can i have a textbox in a toolbar like photoshop?

... or is there a better way?

Killian
08-04-2006, 06:10 AM
Here's some code for an Add-In that builds a toolbar with an edit control and some buttons to give you an idea.Sub Auto_Open()
BuildToolbar
End Sub

Sub Auto_Close()
DeleteToolBar
End Sub

Private Sub BuildToolbar()

Dim TBar As CommandBar
Dim btnNew As CommandBarControl
'Dim btnPop As CommandBarControl

DeleteToolBar
Set TBar = CommandBars.Add(Name:="My Custom Toolbar")
With TBar
Set btnNew = .Controls.Add(Type:=msoControlButton)
With btnNew
.Caption = "Command 1"
.Style = msoButtonCaption
.OnAction = "ControlRoutine" 'below
End With
Set btnNew = .Controls.Add(Type:=msoControlButton)
With btnNew
.Caption = "Command 2"
.Style = msoButtonCaption
.OnAction = "ControlRoutine" 'below
End With
Set btnNew = .Controls.Add(Type:=msoControlButton)
With btnNew
.Caption = "Command 3"
.Style = msoButtonCaption
.OnAction = "ControlRoutine" 'below
End With
Set btnNew = .Controls.Add(Type:=msoControlEdit)
With btnNew
.BeginGroup = True
End With
.Visible = True
End With


End Sub

Private Sub DeleteToolBar()
Dim TBar As CommandBar
For Each TBar In Application.CommandBars
If TBar.Name = "My Custom Toolbar" Then TBar.Delete
Next
End Sub

Sub ControlRoutine()

Dim ctrlEdit As CommandBarControl
Dim myVal As String

Set ctrlEdit = CommandBars("My Custom Toolbar").FindControl( _
Type:=msoControlEdit)
If Not ctrlEdit Is Nothing Then
If ctrlEdit.Text <> "" Then
myVal = ctrlEdit.Text
'different action depending on which button was clicked
Select Case CommandBars.ActionControl.Caption
Case "Command 1"
'code for command 1 or call a routine
Case "Command 2"
'code for command 2 or call a routine
Case "Command 3"
'code for command 3 or call a routine
End Select
MsgBox "Do " & CommandBars.ActionControl.Caption & " with value: " & myVal
Else
MsgBox "No value entered"
End If
Else
MsgBox "Could not find control"
End If

End SubYou can also set other properties on each button ("Paramater" and "Tag") to store values for that action and access tham with the "ActionControl" object

TrippyTom
08-04-2006, 11:21 AM
oooh! Thanks again Mr. K.... I can't wait to play with this :bow:

Does it matter where I put this code? (normal or class module)

While building the toolbar, is there a way to specify a different graphic for each button? I have the images saved in a directory -- can I point to those images?

[Edit] -- For some reason, it's skipping your case statements so no matter what value I put in the textbox, it gives me the messagebox "no value entered". How do I make a value entered stay in the textbox until the user changes it? Also, how do I pass this value on to my macros? It should be a decimal, not text.

[Edit AGAIN!] -- I wasn't pressing ENTER when entering a new value. :) I think I'm getting somewhere now...

TrippyTom
08-04-2006, 02:07 PM
wow... I actually figured out how to make it work with my code. Thanks Killian. :)

I'm still curious to see if I can point the buttons to an image instead of using text.

Killian
08-06-2006, 04:15 PM
You can put some validation on the value with IsNumeric If Not ctrlEdit Is Nothing Then
If ctrlEdit.Text <> "" Then
strVal = ctrlEdit.Text
If IsNumeric(strVal) Then
'different action depending on which button was clicked
Select Case CommandBars.ActionControl.Caption
'etc...

Else
MsgBox "Not valid value"
ctrlEdit.Text = ""
End If
'etc...or you can try casting it to the data type you want (with CLng(strVal), CSng(strVal) etc) and trapping any resulting "Type Mismatch" error.

Regarding the custom icons, have you seen if there are any BuiltIn office icons you can use?
(link to FaceID tool (http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaro97ta/html/faceid.asp))

TrippyTom
08-06-2006, 08:26 PM
Thanks for the isnumeric tip. :)


Yeah, I have the Excel add-in that shows all the faces, but nothing in there satisfied my needs. I just need a simple arrow pointing up, down, left, right or at any angle (8 different macros).

[EDIT]: I decided to get rid of the diagonals since they don't always work as expected. That will let me use faceid: 3274-3276 to use with up, down, left and right. Now if I can just find the right syntax to include them. ;)

TrippyTom
08-07-2006, 03:15 PM
Ok, I figured it out based on the info on this page:
http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaro97ta/html/faceid.asp

Thanks for all your help! :hi:
marking this solved.

TrippyTom
08-12-2006, 08:51 AM
In case you wanted to see the final result, here's my add-in (http://trippysite.com/Shape%20Spacer.zip).