gpt4 book ai didi

c# 动态创建的标签大小不够宽

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:52 25 4
gpt4 key购买 nike

动态创建标签时,部分文本丢失。这是因为标签的尺寸不够宽,它截断了实际字符串的一部分。

我如何让它停止?我不想也不记得为标签设置尺寸。它不应该继续直到字符串为空吗?

示例:value = "Berserker's Iron Axe",它只显示 "Berserker's Iron",因为我没有设置它的大小,它会去掉一部分字符串。

    PictureBox finalResult_pBox = new PictureBox {
Name = "finalResult_pBox" + i,
Size = new Size(64, 64),
Padding = new Padding(0),
BorderStyle = BorderStyle.FixedSingle,

ImageLocation = spidyApi_idByName_result.results[i].img.ToString(),
};
MessageBox.Show(spidyApi_idByName_result.results[i].name.ToString());

Label finalResult_itemName_label = new Label{
Name = "finalResult_itemName_label" + i,
Text = spidyApi_idByName_result.results[i].name,
};

FlowLayoutPanel finalResult_panel = new FlowLayoutPanel{
FlowDirection = FlowDirection.TopDown,
BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle,
Name = "result_flowLayoutPanel" + i,
Size = new System.Drawing.Size(790, 64),
TabIndex = i,
};



finalResult_panel.Controls.Add(finalResult_pBox);
finalResult_panel.Controls.Add(finalResult_itemName_label);
result_flowLayoutPanel.Controls.Add(finalResult_panel);

为什么会发生这种情况,我该如何解决?

最佳答案

只要您保持 Label.AutoSize = true,这是默认设置,它就会自动调整自己的大小。

你可能想做一些测试来查看实际尺寸,比如

  • 设置一个BorderStyle
  • BackColor
  • 或者在文本中插入一个空格,这样它就有机会转到第二行..

  • 当然,您可以测量文本(使用例如 TextRenderer.MeasureText(text, Label.Font); 但这对于text simply to show.. 不过,它对于要求更高的布局控制很有用。

因此,首先要确保 AutoSize 为真,或者您测量并设置了 LabelSize

关于c# 动态创建的标签大小不够宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29447077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com