Label grow from right to left

前端 未结 6 580
逝去的感伤
逝去的感伤 2021-02-03 17:00

I have a label on my form which is on the right of the form. This label loads a dynamic text.

Sometimes the text that it loads is too long and the text crosses the borde

6条回答
  •  执念已碎
    2021-02-03 17:27

    using System.Windows.Forms;
    
    /// 
    /// The position of myLabel to the left of the otherControl component when entering 
    /// text "s". 
    /// You must set myLabel.AutoSize = true
    /// 
    /// text
    void WriteText(string s)
    {
        int len = TextRenderer.MeasureText ( s, myLabel.Font ).Width;
        myLabel.Left = otherControl.Left - 5 - len;
        myLabel.Text = s;
    }
    

提交回复
热议问题