using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
#region
InitializeComponent();
this.Text = Environment.UserName;
this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中顯示。
comboBox1.DataSource = Enum.GetNames(typeof(KnownColor));
#endregion
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
foreach (string text in comboBox1.Items)
{
comboBox1.DropDownWidth = Math.Max(comboBox1.DropDownWidth, TextRenderer.MeasureText(text, comboBox1.Font).Width);
}
comboBox1.ClientSize = new Size(comboBox1.DropDownWidth, comboBox1.ClientSize.Height);
}
}
}