DesktopLabel - how to set FontName without a code?

In my application, i create a global variable for FontName, FontSize and FontColor. For each Label and TextField i set this 3 visual effects.
In my DesktopWindow I have to set these 3 properties for all fields (DesktopLabel and DesktopText). I created global variables and would like to know if I can apply these properties through some property in DesktopLabel and DesktopText without needing code. If I have 10 labels, I have to do it manually through code for each one of them. Below is the code I use. It would be simpler if it were a property that I set somewhere.

// Rectangle
me.RectangleAddProject.FillColor = ColorPaletteColor03

// Window
me.BackgroundColor = ColorPaletteColor02

// Labels
Label01.FontName = FontNameDefault
Label01.FontSize = FontSizeDefault
Label01.TextColor = ColorLetterEnable
Label02.FontName = FontNameDefault
Label02.FontSize = FontSizeDefault
Label02.TextColor = ColorLetterEnable
Label03.FontName = FontNameDefault
Label03.FontSize = FontSizeDefault
Label03.TextColor = ColorLetterEnable

You could create a subclass of DesktopLabel (for example) and set these properties in the constructor.

You could loop through all the controls on your window, and if the control ISA DesktopLabel then set the properties in the loop.

1 Like

Hi, tks for the help. I have no ideia howto do it. Could you share an example or documentation?

You can set the defaults you require in options


but this is global i.e. all projects will have this setting.

HTH
Wayne

1 Like

If you just want to set the font name and size on a single label:

  • Click on the label
  • Click on the Cog tab in the inspector
  • Select your font details etc.

I think you will need to do it via code since you have the properties stored in global variables.

Try the attached project to see if it will accomplish what you want - it uses introspection to loop thru all labels on a window and changes their font properties.

labels.zip (6.6 KB)

Original code from here:

If you use Constants you can use them in the inspector. Proceed them with # before the content name. kFontName would be #kFontName.

OMG introspection is overkill for this.

All you need is a loop in Window.Opening

For each ctl as object in Self.controls
  Select case ctl
  Case IsA DesktopTextControl
    DesktopTextControl(ctl).FontName = FontNameDefault
    DesktopTextControl(ctl).FontSize = FontSizeDefault
    DesktopTextControl(ctl).TextColor = FontColorDefault
  End Select
Next

If you really want to get creative, you could make a window subclass that does this for you automatically…

  1. Add a class to the navigator
  2. Change its super to DesktopWindow
  3. Add Opening event
  4. Right click the event and select Add Event Definition
  5. Paste code above into the Opening event, followed by a line that says RaiseEvent Opening
  6. Whenever you create a new window, set its super to the class you created above.
1 Like

Actually, it was a great suggestion because it motivated you to show me (and others?) a solution that I didn’t know existed. Thanks!

One note, the OP was asking about Labels so DesktopTextControl needs to be replaced with DesktopLabel in your example.

Thanks again.

Agreed. I assumed that DesktopLabel was a desktoptextcontrol, which it is not.

It’s too bad controls that have text size, font and styles do not share a common super

3 Likes

if i want to create a method, how can i pass it as a parameter?

If you would like to try the subclass thing:

menu/Insert Class - call it MyLabel

Then set the super this way

Add an event handler to the class for ‘Opening’

Then all you need to do is add a label to a window, and set the superclass to ‘MyLabel’

1 Like