Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using DrawText for arrows and numbers

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

    Using DrawText for arrows and numbers

    Hello

    I would like to draw up and down arrows, and have a number above or below that arrow. Here is what I have done followed by my question.

    To do that I am using the following:

    Rising
    DrawText("arr6", false, "á", 0, Lows[6][0], 0, Color.Blue, new Font ("Wingdings", 7, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    DrawText("lab6", false, "30", 0, Lows[6][0]-3*TickSize, 0, Color.Blue, new Font ("Arial", 7, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    Falling

    DrawText("arr6", false, "â", 0, Highs[6][0], 0, Color.Red, new Font ("Wingdings", 7, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    DrawText("lab6", false, "30", 0, Highs[6][0]+3*TickSize, 0, Color.Red, new Font ("Arial", 7, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

    The problem is with the +-3*TickSize. Sometimes it fits but when the scaling changes, the distance needs to be increased or decreased, or arrow and number are laid over each other.

    Next I tried using the font size e.g.

    Rising
    DrawText("arr6", false, "á", 0, Lows[6][0], 0, Color.Blue, new Font ("Wingdings", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    DrawText("lab6", false, "30", 0, Lows[6][0]-fsize*TickSize, 0, Color.Blue, new Font ("Arial", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

    Falling
    DrawText("arr6", false, "â", 0, Highs[6][0], 0, Color.Red, new Font ("Wingdings", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
    DrawText("lab6", false, "30", 0, Highs[6][0]+fsize*TickSize, 0, Color.Red, new Font ("Arial", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

    That gives me better results but it's not optimum yet.

    The 'DrawTextFixed' method with its TopRight and TopBottom uses the "n's" to move up and down. I am wondering whether there's something similar to use in 'DrawText' that I am not aware of yet.

    Any advice to keep arrow and number always close together and not overlapping is appreciated.

    sandman




    #2
    Hello sandman,

    Thanks for your post.

    The only thing I could suggest (in addition to what you have tried) would be to use the Ypixeloffset that is available in the Draw.Text() method. Currently, you have it set to 0. You can try variations to find if something works for you.



    Comment


      #3
      Thank you PaulH. I think I got the idea and will try it out using a positive Ypixeloffset for the arrows and a negative one for the numbers defined by half the value of the font size.
      Will let you know the result.

      sandman

      Comment


        #4
        Perfect. Does exactly what I tried to achieve.

        To complete it, here is the code that did it, i.e. draw an arrow with the text snuggly above or below the arrow no matter the scaling:

        Rising
        DrawText("arr0", false, "á", 0, Lows[0][0], +fsize/2, Color.Blue, new Font ("Wingdings", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
        DrawText("lab0", false, "15", 0, Lows[0][0], -fsize/2, Color.Blue, new Font ("Arial", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

        Falling
        DrawText("arr0", false, "â", 0, Highs[0][0], -fsize/2, Color.Red, new Font ("Wingdings", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);
        DrawText("lab0", false, "15", 0, Highs[0][0], +fsize/2, Color.Red, new Font ("Arial", fsize, FontStyle.Bold),StringAlignment.Center, Color.Empty, Color.Empty, 0);

        Thanks PaulH!

        sandman

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        577 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