Data Dynamic
Data Dynamic

Reputation: 25

Dynamic button text align to Left

I need to align button's text, horizontally left on C# WinForms application. All the buttons create dynamically. I tried few ways as bellow. But not worked.

private void dynBtnClick(string btnText)  //Dynamic Text List In flp2
{
    string[] listData = File.ReadAllLines(filePath + @"\" + btnText + ".txt");
    
    int e=listData.Count();
   

    flp2.FlowDirection = FlowDirection.LeftToRight;

    flp2.Controls.Clear();
    for ( int j =0; j<e;j++)
    {
      
        Guna.UI2.WinForms.Guna2Button iBtn = new Guna.UI2.WinForms.Guna2Button();

        iBtn.Tag = j;
        iBtn.BorderRadius = 5;
        iBtn.Height = 25;
        iBtn.Width = 200;
        iBtn.AutoSize = false;
        iBtn.Animated = true;
        iBtn.FillColor = ColorTranslator.FromHtml("#263238");

        iBtn.TextAlign = ContentAlignment.MiddleLeft;

        string[] btnFacetext = listData[j].Split('~');
        iBtn.Text = btnFacetext[0].ToString();

      
        iBtn.Click += (s, c) => { flp2Action(btnFacetext[0]+"~"+ btnFacetext[1], btnText); };
        flp2.Controls.Add(iBtn);
    }
}

Not working for me.

iBtn.TextAlign = Left; 
iBtn.TextAlign = ContentAlignment.MiddleLeft;

Here is the current button state (marked by red lines). Need to texts align left. Please help on this.

enter image description here

Upvotes: 0

Views: 933

Answers (1)

aamd
aamd

Reputation: 427

Guna.UI2.WinForms.Guna2Button.TextAlign is of type HorizontalAlignment not ContentAlignment

iBtn.TextAlign = HorizontalAlignment.Left;

Upvotes: 1

Related Questions