Now we add some addtional buttons to the toolbar to set the fonts styles, such as bold, italic.
![]()
Into property "Text" for each of this new buttons we enter the name of the wpaAction we intend to execute. For this buttons above this are: bold, italic, underline, left, center, justified, right.
Using the following method we can retrieve the action ID for each of the action names:
Dim UpdateLanguage As Boolean = True
Private Sub InitToolbar()
Dim i, id As Integer
Dim aName, aCaption, aHint As String
Dim SelState As Byte()
Dim tb As ToolStripButton
If Not WpdllInt1 Is Nothing Then
SelState = WpdllInt1.wpaGetFlags(0)
For i = 0 To ToolStrip.Items.Count - 1
tb = TryCast(ToolStrip.Items(i), ToolStripButton)
If Not tb Is Nothing Then
' Set TAG if still undefined
If tb.Tag = 0 Then
id = WpdllInt1.wpaGetID(tb.Text)
If id >= 0 Then
tb.Tag = id + 1 ' add one !
Else
tb.Tag = -1 ' this is not a wpaAction!
End If
Else
End If
' Update if an action
If tb.Tag > 0 Then
' Update Captions
If UpdateLanguage Then
If WpdllInt1.Memo.wpaGetCaption(ToolStrip.Items(i).Tag - 1, aName, aCaption, aHint) Then
tb.Text = aCaption
tb.ToolTipText = aHint
End If
End If
' Update Selected and disabled state
tb.Enabled = (SelState(tb.Tag - 1) And 1) <> 0
tb.Checked = (SelState(tb.Tag - 1) And 2) <> 0
End If
End If
Next
UpdateLanguage = False ' Update only the first time!
End If
End Sub
This code basically loops all elements in the toolbar and checks the caption of each element if it is a wpaAction or not. If it is an action it updates sets "Tag" = id+1. Then it updates the Text and the states. After this method has been called, the Tag property should bei either -1 or the wpa action ID. This method can be executed again to update the checked and enabled states so we add a "InitToolbar()" at the end of ReadCurrentAttributes!
Now we create one new event for the new buttons (we select the buttons and add the event for all!)
' OnClick for all buttons which represent wpaActions
Private Sub AllButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles ToolStripButton7.Click ....
Dim tb As ToolStripButton
If Not WpdllInt1 Is Nothing Then
tb = DirectCast(sender, ToolStripButton)
If tb.Tag >= 0 Then
If tb.Checked Then
WpdllInt1.wpaExec(tb.Tag - 1, "0")
Else
WpdllInt1.wpaExec(tb.Tag - 1, "1")
End If
End If
InitToolbar()
End If
End Sub