You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RadioButton.Text无法完整显示文本,仅展示前两词求助

WinForms RadioButton文本无法完整显示的解决方法

你在动态创建RadioButton时遇到了文本截断问题,仅显示前两个词,核心原因是控件尺寸设置过小,不足以容纳完整文本内容。以下是具体解决方法:

解决思路及代码修改

方法1:让控件自动适配文本大小

将固定尺寸的设置替换为自动适配,控件会根据文本长度自动调整宽度,确保内容完整显示:

private void addRadioButton(string text, int indx)
{
    RadioButton radioButton = new RadioButton();
    this.pnlWarehouseGoods.Controls.Add(radioButton);
    radioButton.Text = text;
    // 开启自动适应尺寸,替代固定Size
    radioButton.AutoSize = true;
    radioButton.Location = new Point(0, 30 * indx);
    this.radioButtons.Add(radioButton);
}

方法2:手动设置足够尺寸并开启换行

如果需要限制控件宽度并让文本换行显示,可调整控件尺寸并开启自动换行:

private void addRadioButton(string text, int indx)
{
    RadioButton radioButton = new RadioButton();
    this.pnlWarehouseGoods.Controls.Add(radioButton);
    radioButton.Text = text;
    // 设置足够容纳换行文本的尺寸
    radioButton.Size = new Size(300, 60);
    // 开启自动换行
    radioButton.WordWrap = true;
    // 增大垂直间距避免换行后控件重叠
    radioButton.Location = new Point(0, 70 * indx);
    this.radioButtons.Add(radioButton);
}

额外注意事项

如果容器面板pnlWarehouseGoods的宽度小于RadioButton的宽度,文本依然会被面板截断,此时可以:

  • 调整面板的宽度至足够大小
  • 开启面板的AutoScroll = true,允许滚动查看完整内容

内容的提问来源于stack exchange,提问作者Sergey Frolov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 10:06:45