【发布时间】:2017-06-29 20:03:03
【问题描述】:
例如,当组合框处于活动状态时,我需要使用 DropDownStyle = DropDownList 为组合框绘制自定义外边框。 want the combobox to appear like this image
我尝试了 WndProc,但它在 DropDownList 样式中出现错误。
【问题讨论】:
例如,当组合框处于活动状态时,我需要使用 DropDownStyle = DropDownList 为组合框绘制自定义外边框。 want the combobox to appear like this image
我尝试了 WndProc,但它在 DropDownList 样式中出现错误。
【问题讨论】:
我不太了解 WinForms 中组合框的样式,但您可以使用 System.Drawings.Graphics 来做您想做的事。检查以下代码sn -p:
public partial class Form1 : Form
{
System.Drawing.Graphics graphics;
System.Drawing.Rectangle rectangle;
public Form1()
{
InitializeComponent();
comboBox1.Enter += ComboBox1_Enter;
comboBox1.Leave += ComboBox1_Leave;
}
private void ComboBox1_Leave(object sender, EventArgs e)
{
graphics.Clear(this.BackColor);
}
private void ComboBox1_Enter(object sender, EventArgs e)
{
ChangeActiveControlStyle((Control)sender);
}
private void ChangeActiveControlStyle(Control control)
{
graphics = this.CreateGraphics();
rectangle = new System.Drawing.Rectangle(control.Location.X -2, control.Location.Y-2, control.Width+4, control.Height+4);
graphics.FillRectangle(Brushes.Yellow, rectangle);
}
}
【讨论】: