为什么我的确定和取消按钮没有显示在 UI 屏幕上?我看到了表单、标签和文本框,但看不到“取消”和“确定”按钮。为了给你一个背景知识,我正在以编程方式创建这个对话框,我只需要几个文本框,当然还有它们的标签。还有一个确定和取消按钮。
我在这里使用的所有这些尺寸都是通过反复试验,因为我在 Visual C# 2010 的 UI 控制领域没有太多经验。
public void function x ()
{
var fileNameDialog = new Form();
fileNameDialog.Text = "Save New Name";
Label fileLabel = new Label();
fileLabel.Size = new System.Drawing.Size(150, 40);
fileLabel.Text= "Enter Person Name";
fileNameDialog.Controls.Add(fileLabel);
TextBox fileTextBox = new TextBox();
fileTextBox.Location = new System.Drawing.Point(fileLabel.Location.X + 300, fileLabel.Location.Y);
fileTextBox.Size = new System.Drawing.Size(220, 40);
fileNameDialog.Controls.Add(fileTextBox);
fileTextBox.TextChanged += TextBox_TextChanged;
fileTextBox.Text= textboxValue;
Button okButton = new Button();
okButton.Visible = true;
okButton.Text = "OK";
okButton.Location = new System.Drawing.Point(fileTextBox.Location.X, fileTextBox.Location.Y - 80);
fileNameDialog.Controls.Add(okButton);
okButton.Click += new EventHandler(okButton_Click);
Button cancelButton = new Button();
cancelButton.Visible = true;
cancelButton.Text = "Cancel";
fileNameDialog.Controls.Add(cancelButton);
cancelButton.Click += new EventHandler(cancelButton_Click);
cancelButton.Location = new System.Drawing.Point(fileTextBox.Location.X+50, fileTextBox.Location.Y - 80);
fileNameDialog.ShowDialog();
}