Home > Net >  How about WINFORM dynamic load control is faster
How about WINFORM dynamic load control is faster

Time:05-11

In addition to rely on new control a new one out, are there any other way is faster

CodePudding user response:

Get a faster computer, or asynchronous loading control, make dynamic a little ease user interface looks for anxiety,

CodePudding user response:

Don't slack off,
Unless you write common methods,

CodePudding user response:

Speed difference, the dynamic benefit is saving memory, rather than the CPU

CodePudding user response:

Serialization and deserialization.
Cloning;

CodePudding user response:

 public void LoadControl (Object sender, string tableName) {
The Form Form=sender as Form;
The DataBase mydate=new DataBase ();
int i=0;
DataGridView dv=form. Controls. The Find (" DataGridView ", true) [0] as DataGridView.
Dv. Columns. The Clear ();
The Panel Panel=form. Controls. The Find (" Table ", true) [0] as a Panel;
The panel. Controls. The Clear ();
Mydate.Cmd.Com mandType=CommandType. Text;
Mydate.Cmd.Com mandText="select * from t_Dty where TableName='" + TableName +"' order by ColumnSx ";
Try
{
If (mydate. Conn. State==ConnectionState. Closed)
{
Mydate. Conn. The Open ();
}
SqlDataReader reader=mydate. Cmd. ExecuteReader ();
While (reader. The Read ())
{
//input box name
The Label Label=new Label ();
Label. The Name="lb" + reader [r]. "the TableColumn" ToString ();
Label. The Text=reader [r]. "ColumnName" ToString () + ":";
Label. AutoSize=true;
Label. The Visible=true;
Label. The Location=new Point (10 + I % 2 * 150, 10 + I/2 * 25);
The panel. Controls. The Add (label);

If (reader) [r]. "ColumnName" ToString ()=="department")
{
ComboBox ComboBox=new ComboBox ();
ComboBox. Name=reader [r]. "the TableColumn" ToString ();
ComboBox. Enabled=false;
ComboBox. Visible=true;
ComboBox. Size=new Size (reader) [r]. "ColumnSize GetHashCode (), 25).
ComboBox. Location=new Point (label, Text Length * 11 + label in the Location. The X + 5, 10 + I/2 * 25-5).
This.Com BoxItem (comboBox, "DeMent");
The panel. Controls. The Add (comboBox);
}
Else if (reader) [r]. "ColumnName" ToString ()=="employee type")
{
ComboBox ComboBox=new ComboBox ();
ComboBox. Name=reader [r]. "the TableColumn" ToString ();
ComboBox. Enabled=false;
ComboBox. Visible=true;
ComboBox. Size=new Size (reader) [r]. "ColumnSize GetHashCode (), 25).
ComboBox. Location=new Point (label, Text Length * 11 + label in the Location. The X + 5, 10 + I/2 * 25-5).
ComboBox. Items. The Add (" ");
ComboBox. Items. The Add (" 1. The salesman ");
ComboBox. Items. The Add (" 2. The buyer ");
ComboBox. Items. The Add (" 3. The warehouse controller ");
The panel. Controls. The Add (comboBox);
}
The else {
TextBox TextBox=new TextBox ();
TextBox. Name=reader [r]. "the TableColumn" ToString ();
TextBox. ReadOnly=true;
TextBox. Visible=true;
TextBox. Size=new Size (reader) [r]. "ColumnSize GetHashCode (), 25).
TextBox. Location=new Point (label, Text Length * 11 + label in the Location. The X + 5, 10 + I/2 * 25-5).
The panel. Controls. The Add (textBox);
}

//query shows columns to add
DataGridViewColumn dc new DataGridViewColumn ();
Dc. DataPropertyName=reader [r]. "the TableColumn" ToString ();
Dc. Visible=true;
Dc. Name="T" + reader [r]. "the TableColumn" ToString ();
Dc. The HeaderText=reader [r]. "ColumnName" ToString ();
Dc. Width=reader [r]. "ColumnSize GetHashCode ();
DataGridViewCell dgvcell=new DataGridViewTextBoxCell ();
Dc. CellTemplate=dgvcell;
Dv. Columns. The Add (dc);
i++;
}
The panel. Height=I/2 * 25 + 50;
}
The catch (Exception ex)
{
Throw the ex.
}
The finally
{
Mydate. Conn. Close ();//connection is closed, but don't release the object memory location of the
}
}

This is my test code, and later for each type of control independent one way out, just don't know, after the late data, so will the card,

CodePudding user response:

I go to, write a few entity class, load is not more?
Write a bunch of new, there will be more fast,
  •  Tags:  
  • C #
  • Related