Page 1 of 1

Using the ampersand "&" in TextGadgets

Posted: Mon Jun 07, 2004 10:24 pm
by Sparkie
Can anyone explain why the ampersand "&" doesn't display in the first 2 TextGadgets of this code...

Code: Select all

If OpenWindow(0, 0, 0, 300, 150,  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar , "test")
  If CreateGadgetList(WindowID())
    TextGadget(1, 20, 40, 160, 20, "Dumb & Dumber")
    TextGadget(2, 20, 70, 160, 20, "Dumb " + Chr(38) + " Dumber")
    TextGadget(3, 20, 100, 160, 20, "Dumb &" + Chr(38) + " Dumber")
    For g = 1 To 3
      Debug GetGadgetText(g)
    Next
  EndIf
EndIf

Quit = #False

Repeat
  event = WaitWindowEvent()
  
  Select event
    
    Case #PB_EventCloseWindow
      Quit = #True
      
  EndSelect
Until Quit
End

The TextGadgets display as:

#1 displays as Dumb_Dumber
#2 displays as Dumb_Dumber
#3 displays as Dumb & Dumber

and the Debug window displays as expected. :?

Posted: Mon Jun 07, 2004 10:34 pm
by Paul
Because & is a special Windows character that tells it the next character after the & should be underlined.

If you want "Dumb & Dumber" you need "Dumb && Dumber"

In your example you see "Dumb_Dumber" because the next character after your & is a space, so it is underlining the space.

Posted: Mon Jun 07, 2004 10:42 pm
by Sparkie
Thank you for clearing that up Paul :)