Button Label Text - formatted with only one Underlined Character

I found the way to use a macro to change the button labels.
this would be one way:
ThisComponent.Drawpage.Forms.getByName(“MainForm”).getByName(“btnAdd”).Label = “Add”
no issues there.

What i cannot find an answer to, is how i would be able to underline one specific letter. In this case i want the button to have an underlined ‘A’ and not underlined ‘dd’.
In HTML i would simply do this < u >A< /u >dd. (without the space of course)

I’ve tried these two ways, but both do not work:

'1
com.sun.star.awt.FontUnderline.SINGLE
btnLabel = “A”
com.sun.star.awt.FontUnderline.NONE
btnLabel = btnLabel + “dd”
ThisComponent.Drawpage.Forms.getByName(“MainForm”).getByName(“btnAdd”).Label = btnLabel

'2
btnAdd = ThisComponent.Drawpage.Forms.getByName(“MainForm”).getByName(“btnAdd”).Label
btnAdd.setPropertyValue(CharUnderline,com.sun.star.awt.FontUnderline.SINGLE)

first just gives me a button with the label “Add”, no underlines.
second gives me an error (object variable not set)

is there a way to do this?
any help is appreciated.
thanks.

Hello,

You appear to want an accelerator. Use the ~ prior to the letter wanted. in your case:

btnLabel = "~Add"

Hello Ratslinger, thanks for the super fast reply.
I tried this:
ThisComponent.Drawpage.Forms.getByName(“MainForm”).getByName(“btnAddPart”).Label = “~Add”
However it didn’t change anything. The button label changes the text to “Add”, but no underlining is shown.

and just before i posted this reply i tried one more thing:
ThisComponent.Drawpage.Forms.getByName(“MainForm”).getByName(“btnAddPart”).Label = “~~Add”
two of those characters in a row…
that works. (surprisingly simple :grinning:)

thanks.
Cheers.

As tested:

Dim btnLabel as String
btnLabel = "~Add"
ThisComponent.Drawpage.Forms.getByName("MainForm").getByName("btnAdd").Label = btnLabel
End Sub

Edit:

also tested your code:

Sub ChangeLbl
ThisComponent.Drawpage.Forms.getByName("MainForm").getByName("btnAdd").Label = "~Add"
End Sub

And it worked without issue. Do not understand what problems you are having but two tilde are not necessary.