我怎么可以添加控件设计属性组合框一个WinForms自定义控件? [英] How can I add a combobox in control designer properties for a WinForms custom control?

查看:183
本文介绍了我怎么可以添加控件设计属性组合框一个WinForms自定义控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个属性,可以从一组像男人,女人的字符串值,取一个自定义的控制。因此,在控件设计性能我想告诉这些2选择一个组合框。

I'm creating a custom control with a property that can take value from a set of strings like "Man, Woman". So in in control designer properties I want to show a combobox with these 2 choices.

有没有一种标准的方式来做到这一点?如果不是我应该怎么实现?

Is there a standard way to do so ? If not what should I implement ?

推荐答案

最简单的方法来做到这一点是添加的枚举您的code定义可能的选择你的财产,然后配置你自定义的控件的属性来接受这种类型的值。的属性窗口将自动为这个属性与所有在枚举中列出的可能值显示组合框。

The simple way to do that is to add an enum to your code that defines the possible choices for your property, then configure your custom control's property to accept a value of that type. The Properties Window will automatically display a combo box for this property with all of the possible values in your enum listed.

所以,例如:

public enum Gender
{
    Man,
    Woman,
}

public class MyCustomControl : UserControl
{
    public Gender UserGender { get; set; }
}

这篇关于我怎么可以添加控件设计属性组合框一个WinForms自定义控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆