Winform界面处理技巧
winform combobox数据绑定
comboxDevice.DataSource = ProductionLine.DeviceInit();
comboxDevice.DisplayMember = "device_nm";
comboxDevice.ValueMember = "device_type";
//get text
comboxDevice.Text;
(comboxDevice.SelectedItem as ProductionLine).device_nm;
//get value
comboxDevice.SelectedValue
tabControl选项卡外观美化
默认的看上去比较素,选项卡标签加图片,但没有这个属性方法可改,通用绘制实现
//修改以下设计时属性
tabControl1.DrawMode =OwnerDrawFixed; //自绘制模式
tabControl1.SizeMode =Fixed; //tab宽度固定,默认太小,字显示不全
tabControl1.ItemSize = Size(120, 25);//tab大小
//在drawItem事件绘制tab
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
Rectangle Rect = tabControl1.GetTabRect(e.Index);
if (e.Index == tabControl1.SelectedIndex)
e.Graphics.DrawString("测试结果", new Font(this.Font, FontStyle.Bold), Brushes.Black, Rect.Left + 30, Rect.Top + 3);
else
e.Graphics.DrawString("测试结果", this.Font, Brushes.Black, Rect.Left + 30, Rect.Top + 3);
Image image = imageList1.Images[e.Index];
e.Graphics.DrawImage(image, new Rectangle(Rect.X+6, Rect.Y+3, image.Width, image.Height));
}

浙公网安备 33010602011771号