-
Aug 2nd, 2017, 03:04 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Rename toolbar submenu captions
Hi all
I have a toolbar button that has four submenus.
I wonder if it is poosible to rename the four submenus at runtime and save the new captions.
thanks
Last edited by newbie2; Aug 2nd, 2017 at 07:16 PM.
-
Aug 2nd, 2017, 03:18 PM
#2
Re: REname toolbar submenu
You mean change the caption/title?
-
Aug 2nd, 2017, 03:24 PM
#3
Thread Starter
Fanatic Member
Re: REname toolbar submenu
thanks sir for responding to my interest
yes, that's exactly what I mean
-
Aug 2nd, 2017, 03:29 PM
#4
Re: REname toolbar submenu
I'll let A respond...very simple. Did you try anything yourself, tho?
-
Aug 2nd, 2017, 03:54 PM
#5
Re: REname toolbar submenu
newbie
I'm a newbie re Toolbars, but until Arno responds, I found this in CodeBank
http://www.vbforums.com/showthread.p...hlight=toolbar
Spoo
-
Aug 2nd, 2017, 05:31 PM
#6
Thread Starter
Fanatic Member
Re: REname toolbar submenu
Originally Posted by SamOscarBrown
I'll let A respond...very simple. Did you try anything yourself, tho?
honestly, no
-
Aug 2nd, 2017, 05:32 PM
#7
Thread Starter
Fanatic Member
Re: REname toolbar submenu
Spooman
thanks for the link
but I want something very simple without need for third party
-
Aug 2nd, 2017, 08:39 PM
#8
Re: Rename toolbar submenu captions
Let's say you have a submenu called sMnuColor, and you set the caption in the IDE to "RED", and when your program is running, you want to change it to "BLUE"
just do this:
sMnuColor.Caption = "BLUE"
-
Aug 3rd, 2017, 03:15 AM
#9
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
SamOscarBrown
you are probably talking about the menu control but what I meant is toolbar control.
thanks
-
Aug 3rd, 2017, 04:19 AM
#10
Re: Rename toolbar submenu captions
Hi,
do you mean something like this..
this will change the the Caption of the Toolbar depending on which Option is selected
Code:
Public Sub updateFormKategorie()
If WhichOptionButton(frmSprache, frmSprache.optSprache(i).Name) = 0 Then
frmKategorie.Toolbar1.Buttons(bNeu).Caption = "Neu"
frmKategorie.Toolbar1.Buttons(bAbbruch).Caption = "Abbrechen"
frmKategorie.Toolbar1.Buttons(bSpeichern).Caption = "Speichern"
frmKategorie.Toolbar1.Buttons(bLoeschen).Caption = "Löschen"
frmKategorie.Toolbar1.Buttons(bEditieren).Caption = "Editieren"
frmKategorie.Toolbar1.Buttons(bExit).Caption = "Ende"
frmKategorie.Toolbar1.Buttons(bListe).Caption = "Liste"
frmKategorie.Frame1.Caption = " Kategorieliste : "
frmKategorie.lblDeutsch.Caption = "Bezeichnung Deutsch : "
frmKategorie.lblEnglisch.Caption = "Bezeichnung Englisch : "
frmKategorie.lblFrench.Caption = "Bezeichnung Franz. : "
frmKategorie.lblWissen.Caption = "Wissenschaftlich : "
Else
If WhichOptionButton(frmSprache, frmSprache.optSprache(i).Name) = 1 Then
frmKategorie.Toolbar1.Buttons(bNeu).Caption = "Add New"
frmKategorie.Toolbar1.Buttons(bAbbruch).Caption = "Cancel "
frmKategorie.Toolbar1.Buttons(bSpeichern).Caption = "Save "
frmKategorie.Toolbar1.Buttons(bLoeschen).Caption = "Delete "
frmKategorie.Toolbar1.Buttons(bEditieren).Caption = "Edit "
frmKategorie.Toolbar1.Buttons(bExit).Caption = "Exit "
frmKategorie.Toolbar1.Buttons(bListe).Caption = "open List"
frmKategorie.Frame1.Caption = " Categorylist : "
frmKategorie.lblDeutsch.Caption = "German Name : "
frmKategorie.lblEnglisch.Caption = "Englisch Name : "
frmKategorie.lblFrench.Caption = "French Name : "
frmKategorie.lblWissen.Caption = "Scientific : "
End If
End If
DoEvents
Unload frmSprache
End Sub
Public Function WhichOptionButton(f As Form, _
optName As String) As Integer
Dim i As Integer
For i = 0 To f.Count - 1
If f.Controls(i).Name = optName Then
If f.Controls(i).Value Then _
WhichOptionButton = _
f.Controls(i).Index: _
Exit For
End If
Next i
End Function
Edit:
forgot this !
this is the Index for the Toolbar and goes in a Modul
Code:
'// Toolbarbuttons Index
Public Enum bButton
bNeu = 1
'//seperator = 2
bAbbruch = 3
'//seperator = 4
bSpeichern = 5
'//seperator = 6
bLoeschen = 7
'//seperator = 8
bEditieren = 9
'//seperator = 10
bExit = 11
'//seperator = 12
bListe = 13
'//seperator = 14
End Enum
regards
Chris
Last edited by ChrisE; Aug 3rd, 2017 at 05:42 AM.
-
Aug 3rd, 2017, 04:57 AM
#11
Re: Rename toolbar submenu captions
newbie
Yes, the more I looked at it, it did seem rather complex. I didn't catch that it entailed a 3rd party.
Originally Posted by newbie2
you are probably talking about the menu control but what I meant is toolbar control.
Like I said, I'm a newbie at ToolBar.
Good distinction vis-a-vis MenuBar ..
Spoo
-
Aug 3rd, 2017, 05:36 AM
#12
Re: Rename toolbar submenu captions
The older one gets, the lesser one reads (eyesight, ya know)...Yeh, sorry, I missed the Tool/Menu thingy.
-
Aug 3rd, 2017, 05:53 AM
#13
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
Thank you everyone
After several attempts, I got the way to rename menu captions.
Code:
Toolbar1.Buttons.Item(1).ButtonMenus.Item(1) = "red"
Now i need to save the new captions.
I tried to retrieve the captions:
Code:
Dim i As Integer
For i = 1 To 4
Debug.Print Toolbar1.Buttons(4).ButtonMenus.Item(i).Text
Next
The output is : The fourth item is printed 4 times.
Let's say I have a button: color
Color
blue
green
white
red
After executing the code, the output is:
red
red
red
red
istead of:
blue
green
white
red
thank you all
-
Aug 3rd, 2017, 05:56 AM
#14
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
ChrisE
Thank you very much
Your example seems extraordinary however As i said previously, I want something very simple.
thanks
-
Aug 3rd, 2017, 06:04 AM
#15
Re: Rename toolbar submenu captions
Originally Posted by newbie2
ChrisE
Thank you very much
Your example seems extraordinary however As i said previously, I want something very simple.
thanks
that is the simple Version !
my other version has Classes and Files to change the Language and all Controls in the App.
regards
Chris
-
Aug 3rd, 2017, 06:47 AM
#16
Re: Rename toolbar submenu captions
newbie
It might be helpful if you could include a screen-shot of your ToolBar as is.
Spoo
-
Aug 3rd, 2017, 07:43 AM
#17
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
Spooman
-
Aug 3rd, 2017, 07:45 AM
#18
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
My concern now is how to retrieve the captions.
Code:
Dim i As Integer
For i = 1 To 4
Debug.Print Toolbar1.Buttons(4).ButtonMenus.Item(i).Text
Next
this code didn't work properly.
-
Aug 3rd, 2017, 07:55 AM
#19
Re: Rename toolbar submenu captions
hi newbie2
what Index does Colors have ?
and what ..I will call it -subIndex- do the colors(blue,green ...) have ?
look in the Toolbar how you set them up
regards
Chris
-
Aug 3rd, 2017, 08:57 AM
#20
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
thank you very much for your interest
this is just a tiny sample for illustration
in this example
Colors button has an index 1
The ButtonMenues have indexes successively from 1 to 4
But in my application the button color has an index 4 with 4 ButtunMenus
Please would help me to save the new captions in textfile or ini file?
I'm using ini file to save and retreive textboxes content in this way:
Code:
RetVal = WriteAppINI(Me.Name & "Control", ctl.Name & " text", CStr(ctl.Text), DataFolder & "\MyAppSettings.ini")
ctl.Text = ReadAppINI(Me.Name & "Control", ctl.Name & " text", ctl.Text, DataFolder & "\MyAppSettings.ini")
I tried with toolbar ButtonMenues in the same way but I failed
Code:
Dim RetVal As Long
Dim i As Integer
For i = 1 To 4
RetVal = WriteAppINI(Me.Name & "Control", Toolbar1.Name & " ButtonMenu(i)", Toolbar1.Buttons(4).ButtonMenus.Item(i).Text, DataFolder & "\MyAppSettings.ini")
Next
This is the function
Code:
Private Function WriteAppINI(strSection As String, strKeyName As String, strValue As String, strFile As String) As Long
Dim intStatus As Long
On Error GoTo PROC_ERR
intStatus = WritePrivateProfileString(StrPtr(strSection), StrPtr(strKeyName), StrPtr(strValue), StrPtr(strFile))
WriteAppINI = (intStatus <> 0)
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox "Error: " & Err.Number & " " & Err.Description, , "WriteAppINI"
Resume PROC_EXIT
End Function
Last edited by newbie2; Aug 3rd, 2017 at 09:01 AM.
-
Aug 3rd, 2017, 09:38 AM
#21
Re: Rename toolbar submenu captions
Hi newbie
there is a diffrence between ..
your normal Toolbar Button Click:
Code:
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
and a Toolbar with menu
here I just passed the button click or should I say the selected menuItem to a Listview
Code:
Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
With ButtonMenu
If .Parent = "Person" Then '<--- the Parent would be in your case the Colors !
Select Case ButtonMenu.Key
Case "New" '<--------------------this would be Blue color
List1.AddItem " I pressed new" ' send to Listview
Personenkonto_Load "New"
Case "View"
PersonenKontenToListView msgPersonView
List1.AddItem " I pressed View" '<----------------------this would be Green color
Case "Update"
PersonenKontenToListView msgPersonUpdate
List1.AddItem " I pressed Update"
Case Else
End Select
Exit Sub
ElseIf .Parent = "Datei" Then
Select Case ButtonMenu.Key
Case "Firma", "Abteilungen", "Bereiche", _
"Dienststellungen", "Feiertage", "Folder"
Verwalten_Stammdaten ButtonMenu.Key
Exit Sub
Case "Ende"
Unload Me
Case Else
End Select
End If
End With
End Sub
all clear ?
regards
Chris
-
Aug 3rd, 2017, 10:00 AM
#22
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
Thanks ChrisE
I know the difference between ButtonClick and ButtonMenuClick
But my main worry now is how to save and retreive toolbar ButtonMenus captions.
-
Aug 3rd, 2017, 10:30 AM
#23
Re: Rename toolbar submenu captions
Originally Posted by newbie2
My concern now is how to retrieve the captions.
Code:
Dim i As Integer
For i = 1 To 4
Debug.Print Toolbar1.Buttons(4).ButtonMenus.Item(i).Text
Next
this code didn't work properly.
You may be beyond this stage, but FWIW, I think your logic in post #18 does work.
Here is my variation
Code:
Private Sub Command1_Click()
'
' retrieve menu captions
txt = ""
With Toolbar1
.Visible = True
For ii = 1 To 4
txt = txt & .Buttons(1).ButtonMenus.Item(ii).Text & vbCrLf
Next ii
End With
' post in textbox to verify
With Text1
.Top = 1000
.Left = 4000
.Height = 1500
.Text = txt
End With
'
End Sub
Here is image
Am I missing something?
EDIT1:
You may already know how to do this, but here I modified the menu captions at runtime.
I added this:
Code:
With Toolbar1
.Visible = True
For ii = 1 To 4
txt = txt & .Buttons(1).ButtonMenus.Item(ii).Text & vbCrLf
Next ii
' alter menu
For ii = 1 To 4
.Buttons(1).ButtonMenus.Item(ii).Text = .Buttons(1).ButtonMenus.Item(ii).Text & " add"
Next ii
End With
and got this
Note that the textbox list did not change as it was "grabbed" before the "alter" step.
I just added add
Natch, you can modify this section to suit your particular needs.
EDIT2:
Come to think of it, I believe this was your original question in post #1 ..
Spoo
Last edited by Spooman; Aug 3rd, 2017 at 11:06 AM.
-
Aug 3rd, 2017, 11:25 AM
#24
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
Spooman
thanks a lot
yes thay's my original question but i solved all theses issues.
The remaining concern is still how to save the neww captions in text or ini files
-
Aug 3rd, 2017, 12:40 PM
#25
Re: Rename toolbar submenu captions
-
Aug 3rd, 2017, 03:09 PM
#26
Re: Rename toolbar submenu captions
newbie
but i solved all theses issues.
LOL .. glad I caught up with you
1. Here is how to retrieve from existing textfile
Assuming the this text file exists (which I created manually in NotePad) ..
then this snippet will READ from the file
Code:
Sub Command2_click()
'
' format: 1..red
' 2..green
'
' retrieve from text file
fpath = "D:\VBForums\menu1.txt"
Open fpath For Input As #1
Do While Not EOF(1)
Line Input #1, xtr
ndx = CInt(Left(xtr, 1))
cap = Mid(xtr, 4)
Toolbar1.Buttons(1).ButtonMenus.Item(ndx).Text = cap
Loop
Close #1
'
End Sub
I chose a rather simplistic format to combine the Index with the Caption
xtr stands for extraction .. one line at a time is processed
ndx stands for the Index
cap stands for the Caption
Obviously missing is a reference to the Button index ...
Modify as needed.
.. and you get this result
Note that the TextBox at the right contains the captions as they were when I created
the Buttons manually in the Edit mode.
2. And here is how to change captions.
This snippet will WRITE new captions to a textfile
Code:
Sub Command3_click()
'
fpath = "D:\VBForums\menu1.txt"
' write to text file .. overwrites existing file
Open fpath For Output As #1
txt = ""
For ii = 1 To 4
txt = CInt(ii) & ".."
Select Case ii
Case 1
cap = "hello"
Case 2
cap = "my"
Case 3
cap = "name is"
Case 4
cap = "Spoo"
End Select
txt = txt & cap
Print #1, txt
Next ii
Close #1
' retrieve new captions
Open fpath For Input As #1
ii = 0
Do While Not EOF(1)
ii = ii + 1
Line Input #1, xtr
ndx = CInt(Left(xtr, 1))
cap = Mid(xtr, 4)
Toolbar1.Buttons(1).ButtonMenus.Item(ndx).Text = cap
Loop
Close #1
'
End Sub
The text file would now appear as this ..
.. and you'd get this
For simplicity, I hardwired the new captions. An alternative would be to allow the user to
edit "on the fly", using, say, a TextBox.
Natch, modify as needed.
Hope that helps.
EDIT1:
There is one slight irregularity contained in the foregoing .. can you spot it? ..
EDIT2:
FWIW, DataMiser's post #3 in this thread deals with APPENDing a textfile,
http://www.vbforums.com/showthread.p...te-To-Log-File
Spoo
Last edited by Spooman; Aug 3rd, 2017 at 04:08 PM.
-
Aug 3rd, 2017, 04:14 PM
#27
Thread Starter
Fanatic Member
Re: Rename toolbar submenu captions
Spooman
That's amazing
You are a great man
Thanks a million times
everything is ok now
-
Aug 3rd, 2017, 04:42 PM
#28
Re: [RESOLVED] Rename toolbar submenu captions
newbie
Glad to be of service.
BTW, the irregularity was in the part 2 discussion ..
.. code snippet referred to file as menu1.txt
.. but the Notepad image shows as menu2.txt
Don't ask !!
Spoo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|