gpt4 book ai didi

c# - 为什么我的标签没有显示所有文本?

转载 作者:行者123 更新时间:2023-12-03 19:08:58 25 4
gpt4 key购买 nike

public int dialog()
{
Form prompt = new Form(); // creates form

//dimensions
prompt.Width = 300;
prompt.Height = 125;

prompt.Text = "Adding Rows"; // title

Label amountLabel = new Label() { Left = 50, Top = 0, Text = "Enter a number from 1-50" }; // label for prompt
amountLabel.Font = new Font("Microsoft Sans Serif", 9.75F);
TextBox value = new TextBox() { Left = 50, Top = 25, Width = prompt.Width / 2 }; // text box for prompt
Button confirmation = new Button() { Text = "Ok", Left = prompt.Width / 2 - 50, Width = 50, Top = 50 }; // ok button
confirmation.Click += (sender, e) => { prompt.Close(); }; // if clicked it will close

prompt.AcceptButton = confirmation; // enter

prompt.KeyPreview = true;
prompt.KeyDown += (sender, e) =>
{
if (e.KeyCode == Keys.Escape) prompt.DialogResult = DialogResult.Cancel; // user presses ESC key to close
};

// adding the controls
prompt.Controls.Add(value);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(amountLabel);
prompt.ShowDialog();

// returning and checking if int block
int num;
Int32.TryParse(value.Text, out num);
return num;
}

这是完整的代码。代码的简短版本是:

Label amountLabel = new Label() { Left = 50, Top = 0, Text = "Enter a number from 1-50" };
prompt.Controls.Add(amountLabel);

My Prompt

问题是它只会显示“输入数字”。由于某种原因,它不会显示全文。我尝试了更短的“E”并且它起作用了。我什至尝试了“输入数字来自”,但它仍然没有完全显示。

最佳答案

您可以启用 AutoSize,如果您通过设计器创建它,它默认设置为 true:

Label amountLabel
= new Label { AutoSize = true, Left = 50, Top = 0, Text = "Enter a number from 1-50" };

关于c# - 为什么我的标签没有显示所有文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21224971/

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