当c#中的面板尺寸变大时,就会出现故障 [英] When the panel size get bigger in c#, it Malfunction

查看:66
本文介绍了当c#中的面板尺寸变大时,就会出现故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码动态地将文本框添加到面板:



I have the below code to add the textbox to the panel dynamically:

{
      TextBox[] textbox_item_array = new TextBox[6]; item_textbox.Add(textbox_item_array);
      textbox_item_array[0] = new TextBox();
      textbox_item_array[0].Width = label_bill_item_code.Width;
      textbox_item_array[0].Height = 26;
      textbox_item_array[0].Font = print_font_default;
      textbox_item_array[0].Location = new Point(label_bill_item_code.Location.X, 45 + (20 * row_count));
      textbox_item_array[0].Name = string.Concat("item_code", row_count.ToString());
      panel_bill_item_collections.Controls.Add(textbox_item_array[0]);
      textbox_item_array[0].KeyDown += new KeyEventHandler(dynamic_textbox_keydown);
      textbox_item_array[0].Leave += new EventHandler(dynamic_text_item_code_Leave);
      textbox_item_array[0].DoubleClick += new EventHandler(bill_new_Form_DoubleClick);
      textbox_item_array[1] = new TextBox();
      textbox_item_array[1].Width = label_bill_item_details.Width;
      textbox_item_array[1].Font = textbox_item_array[0].Font;
      textbox_item_array[1].Location = new Point(label_bill_item_details.Location.X, textbox_item_array[0].Location.Y);
      textbox_item_array[1].Name = string.Concat("item_description", row_count.ToString());
      textbox_item_array[1].KeyDown += new KeyEventHandler(dynamic_textbox_keydown);
      panel_bill_item_collections.Controls.Add(textbox_item_array[1]);
      textbox_item_array[2] = new TextBox();
      textbox_item_array[2].Width = label_bill_item_unit.Width;
      textbox_item_array[2].Font = textbox_item_array[0].Font;
      textbox_item_array[2].Location = new Point(label_bill_item_unit.Location.X, textbox_item_array[0].Location.Y);
      textbox_item_array[2].Name = string.Concat("item_unit", row_count.ToString());
      textbox_item_array[2].KeyDown += new KeyEventHandler(dynamic_textbox_keydown);
      panel_bill_item_collections.Controls.Add(textbox_item_array[2]);
      textbox_item_array[3] = new TextBox();
      textbox_item_array[3].Width = label_bill_item_price.Width;
      textbox_item_array[3].Font = textbox_item_array[0].Font;
      textbox_item_array[3].Location = new Point(label_bill_item_price.Location.X, textbox_item_array[0].Location.Y);
      textbox_item_array[3].Name = string.Concat("item_price", row_count.ToString());
      textbox_item_array[3].KeyDown += new KeyEventHandler(dynamic_textbox_keydown);
      panel_bill_item_collections.Controls.Add(textbox_item_array[3]);
      textbox_item_array[4] = new TextBox();
      textbox_item_array[4].Width = label_bill_item_quantity.Width;
      textbox_item_array[4].Font = textbox_item_array[0].Font;
      textbox_item_array[4].Location = new Point(label_bill_item_quantity.Location.X, textbox_item_array[0].Location.Y);
      textbox_item_array[4].Name = string.Concat("item_quantity", row_count.ToString());
      textbox_item_array[4].KeyDown += new KeyEventHandler(dynamic_textbox_keydown);
      textbox_item_array[4].Leave += new EventHandler(bill_new_Form_Leave);
      panel_bill_item_collections.Controls.Add(textbox_item_array[4]);
      textbox_item_array[5] = new TextBox();
      textbox_item_array[5].Width = label_bill_item_total.Width;
      textbox_item_array[5].Font = textbox_item_array[0].Font;
      textbox_item_array[5].Location = new Point(label_bill_item_total.Location.X, textbox_item_array[0].Location.Y);
      textbox_item_array[5].Name = string.Concat("item_total", row_count.ToString());
      textbox_item_array[5].KeyDown += new KeyEventHandler(dynamic_textbox_keydown);
      panel_bill_item_collections.Controls.Add(textbox_item_array[5]);
      row_count++;
      textbox_item_array[0].Focus();
  }





代码工作正常,而面板的大小没有改变但是如果尺寸得到改变了,面板故障。我可以看到,如果我增加面板的大小,它可以正常工作,直到它接近它的大小,然后它变大后再次出现问题。你能帮帮我解决这个问题吗?如果面板不适合这种用途,你可以指导我哪个容器没问题。



The code works fine while the size of the panel is not changed but if the size get changed, the panel Malfunction. What I can see is that if I increase the size of the panel it works fine till it approaches its size then it has problem again after it get bigger. Can you please help me with this problem? If the panel is not appropriate for this use, can you guide me which container is fine.

推荐答案

当你的尺寸变大时,它超出面板的视口尺寸。将面板包裹在Scrollable控件中并相应调整面板大小以适合其孩子。适用于WPF和WinForms控件。



祝你好运!
When your size becomes bigger, it exceeds the viewport size of the panel. Wrap the panel in a Scrollable control and size the panel accordingly to fit it's children. Applies both for WPF and WinForms controls.

Good Luck!


这篇关于当c#中的面板尺寸变大时,就会出现故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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