[英]Ok and Cancel Button Not showing
为什么我的“确定”和“取消”按钮没有显示在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();
}
您的fileTextbox.Location.Y为零,因此减去80放在表格上方。
尝试fileTextBox.Bottom + 4
或类似的东西。
使用设计器创建此对话框表单可能是更好的选择。 除了控件的位置,您还可以使用锚点使控件与表单的大小相关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.