【问题标题】:How to make a custom outside border for ComboBox with DropDownStyle(DropDownList)如何使用 DropDownStyle(DropDownList) 为 ComboBox 制作自定义外边框
【发布时间】:2017-06-29 20:03:03
【问题描述】:

例如,当组合框处于活动状态时,我需要使用 DropDownStyle = DropDownList 为组合框绘制自定义外边框。 want the combobox to appear like this image

我尝试了 WndProc,但它在 DropDownList 样式中出现错误。

【问题讨论】:

    标签: c# combobox controls


    【解决方案1】:

    我不太了解 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      相关资源
      最近更新 更多