Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Serializing colors

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

    Serializing colors

    Hi Guys, I'd be grateful for some help on serializing colors. This is what I have so far:

    PHP Code:
    //variables
    private SolidBrush                 boxoutline            = new SolidBrush(Color.White); 
    
    PHP Code:
    //Properties
    [Category("2. Colors")]
           [Description("Colors.")]
            [Gui.Design.DisplayName("Box Outline color")]
            public Color Boxoutline
            {
                get { return boxoutline.Color; }
                set { this.boxoutline = new SolidBrush(value); }
            }
            
            [Browsable(false)]
            public string BoxoutlineSerialize
            {
            get { return SerializableColor.ToString(boxoutline); }
            set { boxoutline = SerializableColor.FromString(value); }    
            } 
    
    The problem is for the last two lines I'm getting the "The name SerializableColor does not exist in the current context" error. I followed the example exactly.

    Any ideas on this one. Thanks in advance. DJ

    #2
    Opacity

    The other problem is being able to set the opacity in the properties section for this. For example I'd like to be able to change the 150 in properties...

    PHP Code:
    graphics.FillRectangle(new SolidBrush(Color.FromArgb(150,Color.Red.R,Color.Red.G,Color.Red.B)), bounds.X +(bounds.Width/2)+1-60, bounds.Top + 2, 59, 59); 
    
    I've have this from another indicator but seems to be fixed at 10 so not sure how to modify it:

    PHP Code:
    [Category("2. Colors")]
            [Description("Colors.")]
            [Gui.Design.DisplayName("Box Opacity")]
            public int Opacity
            {
                get { return opacity; }
                set { opacity = Math.Min(Math.Max(0, value),10); }
            } 
    
    Thanks in advance
    DJ

    Comment


      #3
      DJ, the max is set here to a 10 in the property -

      set { opacity = Math.Min(Math.Max(0, value),10);

      Are you saying the indicator would set the opacity of the custom Rectangle? I would expect this only to work for the NT default DrawRectangle, as it implements an opacity paramters / setting.

      Comment


        #4
        For the color please try with :

        [Category("2. Colors")]
        [Description("Colors.")]
        [Gui.Design.DisplayName("Box Outline color")]
        public Color Boxoutline
        {
        get { return boxoutline.Color; }
        set { this.boxoutline = new SolidBrush(value); }
        }

        [Browsable(false)]
        public string BoxoutlineSerialize
        {
        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( boxoutline); }
        set { boxoutline = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
        }

        Comment


          #5
          another similar question with regards to color (and opacity). When I change the background color of a panel, is there a way to apply opacity to the background colors?

          Comment


            #6
            Would not be directly supported in NnjaScript, however you can look into setting it via the Color.FromArgb like - BackColor = Color.FromArgb(100, Color.DarkBlue);

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              For the color please try with :

              [Category("2. Colors")]
              [Description("Colors.")]
              [Gui.Design.DisplayName("Box Outline color")]
              public Color Boxoutline
              {
              get { return boxoutline.Color; }
              set { this.boxoutline = new SolidBrush(value); }
              }

              [Browsable(false)]
              public string BoxoutlineSerialize
              {
              get { return NinjaTrader.Gui.Design.SerializableColor.ToString( boxoutline); }
              set { boxoutline = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
              }
              Thanks Bertrand, but that didn't work either. Here is a picture of the error. Also, this is how I'm using it so not sure if that is causing the problem as well.

              PHP Code:
              graphics.DrawRectangle(new Pen(boxoutline),  bounds.X +(bounds.Width/2)+60, bounds.Top+1, 60, 60); 
              
              Also this is what I have in variables:

              PHP Code:
              private SolidBrush                 boxoutline            = new SolidBrush(Color.White); 
              
              Thanks. DJ
              Attached Files
              Last edited by djkiwi; 02-28-2013, 11:07 AM.

              Comment


                #8
                Ok, found the answer exactly in this post:

                Comment

                Latest Posts

                Collapse

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