下拉框和搜索框组合样式_可定制的组合框下拉菜单

下拉框和搜索框组合样式

Downloads

资料下载

The associated files can be downloaded from the following links:

可以从以下链接下载相关文件:

Download Demo Project (39.18 KB)     下载演示项目 (39.18 KB) * Warning, externally hosted. Download Source (8.2 KB)                     下载源 (8.2 KB) * Warning, externally hosted.

Introduction

介绍

This article presents an extension of the .NET ComboBox which provides custom drop-downs. The control can automatically add a resizer grip at the bottom of a drop-down.

本文介绍了.NET ComboBox的扩展,该扩展提供了自定义下拉菜单。 控件可以在下拉菜单的底部自动添加缩放手柄。

Screenshot Examples

Design

设计

Custom drop-down functionality can be achieved using the .NET ToolStripDropDown and ToolStripControlHost classes. These two classes are great because they prevent application forms from becoming inactive during drop-down. The custom popup functionality required by this control has been encapsulated within the class PopupControl (a new addition since the original article posting).

使用.NET ToolStripDropDown和ToolStripControlHost类可以实现自定义下拉功能。 这两个类很棒,因为它们防止应用程序表单在下拉菜单中变为非活动状态。 此控件所需的自定义弹出功能已封装在类PopupControl(自发布原始文章以来的新增功能)内。

In addition to facilitating this control, the PopupControl class can be used to provide drop-down support in your own controls. The PopupControl also integrates the drop-down resize support (now without the need for a nested resizable container, see below for details).

除了简化此控件外,PopupControl类还可用于在您自己的控件中提供下拉支持。 PopupControl还集成了下拉调整大小支持(现在不需要嵌套的可调整大小的容器,有关详细信息,请参见下文)。

Previously the drop-down control was resizable by nesting a resizable container. This was an okay solution (because it worked) but it caused some redraw errors during resize operations. The resize functionality has now been significantly improved, and it is now also possible to define which sides of the drop-down are resizable (if any). Resizing can now also be done by dragging the resizable edges of the drop-down. The new resize functionality is achieved by intercepting Win32 hit testing messages, and responding appropriately based upon the set PopupResizeMode property.

以前,下拉控件是通过嵌套可调整大小的容器来调整大小的。 这是一个不错的解决方案(因为它可以工作),但是在调整大小操作期间导致了一些重绘错误。 调整大小功能现已得到显着改进,现在还可以定义下拉菜单的哪一部分是可调整大小的(如果有)。 现在也可以通过拖动下拉菜单的可调整大小的边缘来调整大小。 新的调整大小功能是通过截获Win32命中测试消息并根据所设置的PopupResizeMode属性进行适当响应来实现的。

The following UML class diagram provides an overview of the presented classes:

以下UML类图提供了所呈现类的概述:

UML Overview

Using the Code

使用代码

As with most controls, this control can be created dynamically at runtime, or by using the Visual C# IDE designer's drag and drop features. During runtime, the property DropDownControl must be assigned to an instance of another control. The assigned control must not be contained elsewhere as this will cause problems.

与大多数控件一样,可以在运行时动态创建此控件,也可以使用Visual C#IDE设计器的拖放功能来动态创建此控件。 在运行时,必须将属性DropDownControl分配给另一个控件的实例。 所分配的控件不能包含在其他地方,因为这会引起问题。

Most drop-down controls appear better when their borders are removed.

当大多数下拉控件的边框被删除时,它们看起来会更好。

namespace CustomComboDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        } 
        private void Form1_Load(object sender, EventArgs e)
        {
            // Dynamically created controls. 
            // Create grid view control.
            DataGridView gridView = new DataGridView();
            gridView.BorderStyle = BorderStyle.None;
            gridView.Columns.Add("Column1", "Column 1");
            gridView.Columns.Add("Column2", "Column 2");
            gridView.Columns.Add("Column3", "Column 3");
            gridView.Columns.Add("Column4", "Column 4");
            gridView.Columns.Add("Column5", "Column 5");
            this.customComboBox1.DropDownControl = gridView; 
            // Create user control.
            UserControl1 userControl = new UserControl1();
            userControl.BorderStyle = BorderStyle.None;
            this.customComboBox2.DropDownControl = userControl; 
            // Create rich textbox control.
            RichTextBox richTextBox = new RichTextBox();
            richTextBox.BorderStyle = BorderStyle.None;
            this.customComboBox3.DropDownControl = richTextBox;
        }
    }
}

Original Article

来源文章

This is an article which I originally wrote and posted at the CodeProject website: http://www.codeproject.com/KB/combobox/CustomDDComboBox.aspx.

这是我最初写并发布在CodeProject网站上的文章: http : //www.codeproject.com/KB/combobox/CustomDDComboBox.aspx

翻译自: https://www.experts-exchange.com/articles/1036/Customizable-ComboBox-Drop-Down.html

下拉框和搜索框组合样式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值