Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:03:22+00:00 2026-06-17T20:03:22+00:00

I have a simple Windows Forms application with a tabControl . I have 3

  • 0

I have a simple Windows Forms application with a tabControl. I have 3 panels on the tabControl, each having 5 buttons. The text on first set of buttons is hard-coded, but the next set populates when you click one from the first group, and then the same thing happens again for the last group when you click one of the buttons from the second group. In the [Design] view I manually set the TextAlign property of each button to MiddleCenter. However, when I run the application the text on the middle set of buttons is never centered. It is always TopLeft aligned. I’ve tried changing the font size and even explicitly setting the TextAlign property every time I set button text programmatically, as follows:

private void setButtons(List<string> labels, Button[] buttons)
    {
        for (int i = 0; i < buttons.Count(); i++)
        {
            if (i < labels.Count)
            {
                buttons[i].Text = labels.ElementAt(i);
                buttons[i].TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                buttons[i].Enabled = true;
            }
            else
            {
                buttons[i].Text = "";
                buttons[i].Enabled = false;
            }
        }
    }

This image shows the result:
alignment issue

Does anyone have any ideas for what I’m missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:03:23+00:00Added an answer on June 17, 2026 at 8:03 pm

    Trim text which you are assign to button. Also you can refer label by index, without calling ElementAt

    private void setButtons(List<string> labels, Button[] buttons)
    {
        for (int i = 0; i < buttons.Count(); i++)
        {
            Button button = buttons[i];
    
            if (i < labels.Count)
            {
                button.Text = labels[i].Trim(); // trim text here
                // button.TextAlign = ContentAlignment.MiddleCenter;
                button.Enabled = true;
            }
            else
            {
                button.Text = "";
                button.Enabled = false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple windows application in C# with 3 forms. first form is
I have a requirement to create a simple windows forms application that allows an
On Windows 7, VB.NET Express, I have developed a simple Forms application. I don't
I have (what should be) a very simple Windows Forms application. There is a
I have a borderless Windows Forms application. The main window creates other forms (simple
I have a simple Windows Forms application which binds a DataView to a ListBox.
I have a simple windows Forms application where in I have a usercontrol called
I have a fairly simple Windows Forms application that I would like to add
I have a simple Windows Forms (C#, .NET 2.0) application, built with Visual Studio
I have simple Windows Forms application (not WPF), and I have two controls on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.