Toolbox——Common Controls——ComboBox
- 不可编辑
1) 代码方法
在***.cs中修改,而不是**.Designer.cs中修改
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace loginView
{
public partial class OtherForm : Form
{
public OtherForm()
{
InitializeComponent();
comboBox1.Items.AddRange(new object[] { "锯嘴葫芦", "土拨鼠", "渣渣猫", "波波" });
comboBox1.SelectedIndex = 0;
comboBox2.Items.AddRange(new object[] { "锯嘴葫芦", "土拨鼠", "渣渣猫","波波" });
comboBox2.SelectedIndex = 0;
comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
}
}
}
在代码中修改,设计界面不会显示变化
2) 属性中修改
修改前后设计界面对比图
修改前后运行窗口对比图
- 不可选择
1)代码方法
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace loginView
{
public partial class OtherForm : Form
{
public OtherForm()
{
InitializeComponent();
comboBox1.Items.AddRange(new object[] { "锯嘴葫芦", "土拨鼠", "渣渣猫", "波波" });
comboBox1.SelectedIndex = 0;
comboBox2.Items.AddRange(new object[] { "锯嘴葫芦", "土拨鼠", "渣渣猫","波波" });
comboBox2.SelectedIndex = 0;
comboBox1.Enabled = false;
}
}
}
2)属性修改
修改前后设计界面看不到明显变化
运行窗口界面变化