Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Font property...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Font property...

    Hello,

    I am attempting to create a font property, found a thread that talked about it and it does not fully work, for me.

    Using version 8.0.27.1 64-bit
    Code:
    if (State == State.SetDefaults)
    
    NinjaTrader.Gui.Tools.SimpleFont shortFont = new NinjaTrader.Gui.Tools.SimpleFont("Consolas", 16) { Size = 32, Bold = false};
    ...
    
    [Display(Name="Font", Description="Display font", GroupName="Short")]
    public NinjaTrader.Gui.Tools.SimpleFont shortFont
    { get; set; }
    ​
    The property does show in the dialog but does not expand when selected.

    Click image for larger version

Name:	font.png
Views:	173
Size:	8.0 KB
ID:	1250095
    Ideas?

    Thanks,

    Mark

    #2
    NinjaTrader or a knowledgable user can chime in if there is an inbuilt type convertor for this. Otherwise, you could make a custom type converter to make this work. Basically a type converter just converts an arbitrary type to and from a string so that the string can be stored and worked with in the UI. A similar mechanism lets you custom-populate a dropdown control as if it were an enum, but really, it's just a list you made of the fonts.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Thanks for the response Bruce.
      I found a thread from 2017 that showed the code I posted with an image of the properties dialog and it worked.
      This post: here
      .
      Post.#2


      Comment


        #4
        Hello Mark--,

        Like other nullable types, you must set a default value for the property for this to display in the UI without errors occurring.

        Attached is an example.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the response ChelseaB.

          I had done that but your post got me to look at my code again and I found my error, in bold


          if (State == State.SetDefaults)

          NinjaTrader.Gui.Tools.SimpleFont shortFont = new NinjaTrader.Gui.Tools.SimpleFont("Consolas", 16) { Size = 32, Bold = false};


          Removed the bold and worked as expected.

          Comment


            #6
            Hello Mark--,

            This would fall under general C# education, however any variable can only be used in the scope in which it is declared.

            If you declare a variable in a method, it can only be used in that method. If you declare a variable in the action block of an if statement (branching command) that variable can only be used in that action block and not outside of it.

            Your variable was already declared in the scope of the class as public. It doesn't need to be declared a second time in the method.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post

              Your variable was already declared in the scope of the class as public. It doesn't need to be declared a second time in the method.
              Right. It was a copy and paste from a strategy I wrote and did not properly look over the paste.

              Thanks for your time.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              649 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              370 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              574 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              576 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X