Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X