Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Help with creating a method

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

    Help with creating a method

    I want to create a method, let say

    Code:
    public void DrawAlotOfThings(...      )
    {
    DrawText(tag, false, text, barsAgo, price, 0, Color.Black, new Font("Arial", 8), StringAlignment.Far, Color.Empty, Color.Empty, 0);
    }
    How can I make something like

    DrawAlotOfThings(Far, Black)

    and have the DrawText to get Color.Black and StringAlignment.Far

    Im not sure how to set this up. I know how to do it with strings and ints, but not with things like Color.Black and StringAlignment.Far.

    #2
    They are simply parameters you pass in.

    In the variables section set

    private Color textColor = Color.Black;

    Then create a property for the text color:
    [Description("Text Color.")]
    [Category("Colors")]
    [Gui.Design.DisplayName("The color of the text.")]
    public Color TextColor
    {
    get { return textColor; }
    set { textColor = value; }
    }

    [Browsable(false)]
    public string TextColorSerialize
    {
    get { return Gui.Design.SerializableColor.ToString(textColor); }
    set { textColor = Gui.Design.SerializableColor.FromString(value); }
    }

    The alignment is set up as an enum type.

    After the Using Declarations section and BEFORE the namespace define your enums:

    public enum StringAlignment { Near, Far, Center };

    In the variables section define the variable for the alignment

    private StringAlignment myStringAlignment = StringAlignment.Far;
    and pass the myStringAlignment as a parameter to your method.

    DrawAlotOfThings(myStringAlignment, textColor);

    Note that you also need to create it as a property:

    [Description("String Alignment.")]
    [GridCategory(
    "Strings")]
    [Gui.Design.DisplayNameAttribute(
    "String Alignment")]
    public StringAlignment MySringAlignment
    {
    get { return myStringAlignment; }
    set { myStringAlignment = value; }
    }

    And set up the Draw() method as:

    DrawALotOfThing(StringAlignment methodStringAlignment, Color methodColor)
    {
    //do calculations
    }

    and call the method as
    DrawALotOfThings(mystringAlignment, text Color);
    Last edited by Zeos6; 01-21-2013, 10:19 AM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by helpwanted, Today, 03:06 AM
    1 response
    14 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    11 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    6 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    244 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    387 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X