Home > Software design >  Radiobutton.Text does not show the Text completely
Radiobutton.Text does not show the Text completely

Time:08-06

I have a problem with RadioButton.Text The text is not shown completely, just the first two words. Here is the code:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Magatzem_Open_Arms.forms
{
    public partial class AttachNameForm : Form
    {
        private List<RadioButton> radioButtons = new List<RadioButton>();

        public AttachNameForm()
        {
            InitializeComponent();
        }

        private void AttachNameForm_Load(object sender, EventArgs e)
        {
            for (int i = 0; i<30; i  )
            {
                addRadioButton("Board games have been played in nearly all", i);
            }
        }

        private void addRadioButton(string text, int indx)
        {
            RadioButton radioButton = new RadioButton();
            this.pnlWarehouseGoods.Controls.Add(radioButton);
            radioButton.Text = text;
            radioButton.Size = new Size(200, 20);
            radioButton.Location = new Point(0, 30 * indx);
            this.radioButtons.Add(radioButton);
        }
        
    }
}

The buttons show Text as "Board games", nothing more instead of "Board games have been played in nearly all" as it was planned. I'm using Visual Studio 2017. Can anyone help me, please?

CodePudding user response:

Probably the width of 200 you specified is not wide enough to display whole text. Set the RadioButton's AutoSize property to true instead of specifying a size. The documentation of ButtonBase.AutoSize Property says:

Gets or sets a value that indicates whether the control resizes based on its contents.

private void addRadioButton(string text, int indx)
{
    RadioButton radioButton = new RadioButton();
    this.pnlWarehouseGoods.Controls.Add(radioButton);
    radioButton.Text = text;
    radioButton.AutoSize = true;
    radioButton.Location = new Point(0, 30 * indx);
    this.radioButtons.Add(radioButton);
}
  • Related