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 fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,406 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    98 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    160 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    9 views
    0 likes
    Last Post Belfortbucks  
    Working...
    X