创建新表单时未全部显示的文本 [英] Text not all displayed by the time new form has been created

查看:18
本文介绍了创建新表单时未全部显示的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用c#构建了一个程序,我想创建一个新的表单(如microsoft word、excel等),我已经可以实现了,但是,到我命令创建时,文本并未全部显示一种新形式.

i built a program by using c#, and i wanted to make a new form (like microsoft word, excel etc), and i already can achieve it, however, the text are not all displayed by the time i command to create a new form.

这是创建新表单之前的图像:

Here is the image before new form created:

这是创建新表单后的图像:

And here is the image after new form created:

我想知道,为什么在我创建新表单后没有显示文本和菜单文件"?我已经调用了这个包含所有文本和文本框的函数,但只有出现的文本框:

I was wondering, why the text and the menu "File" not displayed after i create a new form? i already called this function that contains all the text and the textboxes, but only textboxes that come out:

private void AddObjects(object sender, EventArgs e, Form theForm)
{
  textBoxQuantityContainer = new List<NumericUpDown>();
  textBoxCodeContainer = new List<TextBox>();
  textBoxDescContainer = new List<TextBox>();
  textBoxSubTotalContainer = new List<TextBox>();
  textBoxTotalContainer = new List<TextBox>();
  textBoxAllTotalContainer = new TextBox();

  OleDbDataReader dReader;
  OleDbConnection conn = new OleDbConnection(connectionString);
  conn.Open();
  OleDbCommand cmd = new OleDbCommand("SELECT [Code] FROM [Data]", conn);

  dReader = cmd.ExecuteReader();

  AutoCompleteStringCollection codesCollection = new AutoCompleteStringCollection();

  while (dReader.Read())
  {
    string numString = dReader[0].ToString().PadLeft(4, '0');
    codesCollection.Add(numString);
  }

  dReader.Close();
  conn.Close();

  if (firstForm.comboBox1.SelectedIndex == 0)
  {
    label1.Text = "Code:";
    label1.Location = new Point(60, 125);
    label2.Text = "Welcome to the Selling System.";
    label2.Location = new Point(600, 30);
    label3.Text = "Quantity:";
    label3.Location = new Point(155, 125);
    label4.Text = "Description:";
    label4.Location = new Point(580, 125);
    label5.Text = "Sub Total on Rp:";
    label5.Location = new Point(1020, 125);
    label6.Text = "Total on Rp:";
    label6.Location = new Point(1210, 125);
    label7.Text = "Total on Rp:";
    label7.Location = new Point(1080, 580);
  }

  else if (firstForm.comboBox1.SelectedIndex == 1)
  {
    label1.Text = "Kode:";
    label1.Location = new Point(60, 125);
    label2.Text = "Selamat datang di Selling System.";
    label2.Location = new Point(600, 30);
    label3.Text = "Banyaknya:";
    label3.Location = new Point(145, 125);
    label4.Text = "Keterangan:";
    label4.Location = new Point(580, 125);
    label5.Text = "Sub Total di Rp:";
    label5.Location = new Point(1020, 125);
    label6.Text = "Total di Rp:";
    label6.Location = new Point(1210, 125);
    label7.Text = "Total di Rp:";
    label7.Location = new Point(1080, 580);
  }

  //****TextBox for Code****
  for (int y = 0; y <= 16; y++)
  {
    textBoxCodeContainer.Add(new TextBox());
    textBoxCodeContainer[y].Size = new Size(100, 50);
    textBoxCodeContainer[y].Location = new Point(25, 150 + (y * 25));
    textBoxCodeContainer[y].TextChanged += new System.EventHandler(this.textBox_TextChanged);

    textBoxCodeContainer[y].AutoCompleteMode = AutoCompleteMode.Suggest;
    textBoxCodeContainer[y].AutoCompleteSource = AutoCompleteSource.CustomSource;
    textBoxCodeContainer[y].AutoCompleteCustomSource = codesCollection;

    theForm.Controls.Add(textBoxCodeContainer[y]);
  }

  //****TextBox for Quantity****
  for (int y = 0; y <= 16; y++)
  {
    textBoxQuantityContainer.Add(new NumericUpDown());
    textBoxQuantityContainer[y].Size = new Size(100, 50);
    textBoxQuantityContainer[y].Location = new Point(125, 150 + (y * 25));
    textBoxQuantityContainer[y].TextChanged += new System.EventHandler(this.textBox_TextChanged);
    textBoxQuantityContainer[y].Maximum = 1000;

    theForm.Controls.Add(textBoxQuantityContainer[y]);
  }

  //****TextBox for Description****
  for (int y = 0; y <= 16; y++)
  {
    textBoxDescContainer.Add(new TextBox());
    textBoxDescContainer[y].Size = new Size(750, 50);
    textBoxDescContainer[y].Location = new Point(225, 150 + (y * 25));

    theForm.Controls.Add(textBoxDescContainer[y]);
  }

  //****TextBox for Sub Total****
  for (int y = 0; y <= 16; y++)
  {
    textBoxSubTotalContainer.Add(new TextBox());
    textBoxSubTotalContainer[y].Size = new Size(175, 50);
    textBoxSubTotalContainer[y].Location = new Point(975, 150 + (y * 25));

    theForm.Controls.Add(textBoxSubTotalContainer[y]);
  }

  //****TextBox for Total****
  for (int y = 0; y <= 16; y++)
  {
    textBoxTotalContainer.Add(new TextBox());
    textBoxTotalContainer[y].Size = new Size(175, 50);
    textBoxTotalContainer[y].Location = new Point(1150, 150 + (y * 25));
    textBoxTotalContainer[y].TextChanged += new System.EventHandler(this.textBox_TextChanged);

    theForm.Controls.Add(textBoxTotalContainer[y]);
  }

  //****TextBox for Total All****
  textBoxAllTotalContainer.Size = new Size(175, 50);
  textBoxAllTotalContainer.Location = new Point(1150, 575);
  textBoxAllTotalContainer.TextChanged += new System.EventHandler(this.textBox_TextChanged);

  theForm.Controls.Add(textBoxAllTotalContainer);
}

private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
  AddNewForm(sender, e);
}

private void AddNewForm(object sender, EventArgs e)
{
  this.Hide();

  Form newForm = new Form();

  AddObjects(sender, e, newForm);

  newForm.ShowDialog();
}

提前致谢!

推荐答案

您需要在 Form_Load 事件期间添加控件,否则它们将不会在正确的时间被绘制.

You'll want to add the controls during the Form_Load event, otherwise they won't be drawn at the right time.

这篇关于创建新表单时未全部显示的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆