Modify Combobox

[Top]  [Chapter]  [Previous]  [Next]

With the previous code we can change the text in the editor quite easily. But we also want that the combo boxes are updated according to the text at the current cursor position.

 

The following sub procedure can be used to read font name and font size. If the attribute is not defined in the text the respective combo box will be cleared.

Note: TextDynamic supports undefined attributes, they are important for the operation of paragraph styles. Only text which does not define a certain attribute will use that attribute as defined in attached paragraph style.

 

  Public Sub ReadCurrentAttributes(ByVal MaybeCurrEditor As WPDynamic.WPDLLInt)

      ' We ignore the call if this is not the current editor!

      If MaybeCurrEditor Is WpdllInt1 Then

          ' There is no active editor

          If WpdllInt1 Is Nothing Then

              FontNameSel.SelectedIndex = -1

              FontSizeSel.Text = ""

              FontNameSel.Enabled = False

              FontSizeSel.Enabled = False

          Else ' update the active editor

              FontNameSel.Enabled = True

              FontSizeSel.Enabled = True

              ' Get font name and size from active editor

              Dim ff As String

              If Not WpdllInt1.TextAttr.GetFontface(ff) Then

                  FontNameSel.SelectedIndex = -1

              Else

                  FontNameSel.SelectedIndex = FontNameSel.Items.IndexOf(ff)

              End If

              Dim s As Single

              If Not WpdllInt1.TextAttr.GetFontSize(s) Then

                  FontSizeSel.Text = ""

              Else

                  FontSizeSel.Text = Convert.ToString(s)

              End If

          End If

      End If

  End Sub

 

But where should be call this procedure?

 

a) At the end of WordsMDIParent1_MdiChildActivate

 

  Private Sub WordsMDIParent1_MdiChildActivate(..)

       ...

       ReadCurrentAttributes(WpdllInt1)

  End Sub

 

b) In the OnUpdateGUI event of the TextDynamic editor - in the child form add.

 

  Private Sub WpdllInt1_OnUpdateGUI(ByVal Sender As System.Object,

               ByVal Editor As System.Int32, ByVal UpdateFlags As System.Int32,

               ByVal StateFlags As System.Int32, ByVal PageNr As System.Int32,

               ByVal PageCount As System.Int32, ByVal LineNr As System.Int32)

               Handles WpdllInt1.OnUpdateGUI

      WordsMDIParent1.ReadCurrentAttributes(WpdllInt1)

  End Sub

 

It is common that a word processor display the current position in the status bar. So we add some elements to the StatusStrip control on the main form. The property AutoSize should be off.

 

clip0149

 

Now just three additional lines of code in the above event handler to update the statusbar

 

      WordsMDIParent1.StatusStrip.Items(0).Text = Convert.ToString(PageNr) _

         + "/" + Convert.ToString(PageCount)

      WordsMDIParent1.StatusStrip.Items(1).Text = Convert.ToString(LineNr)

 

 


[modifycombobox.htm]    Copyright © 2007 by WPCubed GmbH