The drop-down box has the DropDownStyle attribute. If you select the DropDownStyle type as the DropDownList, you can only select the drop-down box and cannot enter it. However, the drop-down box does not have a default value. It does not work even if you enter the default value in the Text attribute. It must be modified in the file (XX. Designer. cs.
This is not modified:
This. ComboBox1.Cursor = System. Windows. Forms. Cursors. Default;
This. ComboBox1.DropDownStyle = System. Windows. Forms. ComboBoxStyle. DropDownList;
This. comboBox1.Font = new System. drawing. font ("Arial", 9F, System. drawing. fontStyle. regular, System. drawing. graphicsUnit. point, (byte) (0 )));
This. ComboBox1.FormattingEnabled = true;
This. ComboBox1.Items. AddRange (new object [] {
"1 ",
"2 ",
"3 "});
This. ComboBox1.Location = new System. Drawing. Point (138,124 );
This. ComboBox1.Name = "ComboBox1 ";
This. ComboBox1.Size = new System. Drawing. Size (150, 23 );
This. ComboBox1.TabIndex = 15;
The bold line of code is a drop-down box that can only select settings that cannot be entered.
Add a default value before that line of code. Modify as follows:
This. ComboBox1.Cursor = System. Windows. Forms. Cursors. Default;
This. comboBox1.Font = new System. drawing. font ("Arial", 9F, System. drawing. fontStyle. regular, System. drawing. graphicsUnit. point, (byte) (0 )));
This. ComboBox1.FormattingEnabled = true;
This. ComboBox1.Items. AddRange (new object [] {
"1 ",
"2 ",
"3 "});
This. ComboBox1.Text = this. ComboBox1.Items [0]. ToString ();
This. ComboBox1.DropDownStyle = System. Windows. Forms. ComboBoxStyle. DropDownList;
This. ComboBox1.Location = new System. Drawing. Point (138,124 );
This. ComboBox1.Name = "ComboBox1 ";
This. ComboBox1.Size = new System. Drawing. Size (150, 23 );
This. ComboBox1.TabIndex = 15;
If the first line is bold
This. ComboBox1.Text = "Default Value ";
The default value is the same as that directly entered in the attribute, and will be automatically deleted.
Note: The first line of the bold statement should be written in
This. ComboBox1.Items. AddRange (new object [] {
"1 ",
"2 ",
"3 "});
Statement. The preceding statement can be set in Items attributes.
After all the above are written, the results will be achieved, but the effects will be changed in some components (even if they are not associated with the drop-down box), the entire file will be restructured, the modified statements will be restored, and nothing is changed. In other words, every time a component is modified, the above action must be done again.
My method is to write all the values assigned by the default value in another method written by myself, and then call this method after initialization.