从组合框中删除边框 [英] Remove the border from a combobox

查看:184
本文介绍了从组合框中删除边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#中的用于显示信息的表单,但是我仍然需要允许对信息进行一些操作。我真正想做的是从组合框中删除边框,这将使我可以显示信息,同时还允许用户选择集中的其他项目而不必全部显示。

I am working on a form in C# that is used for displaying information, but I still need to allow some manipulation of the information. What I really want to do is remove the border from a combobox, this would allow me to display the information while also allowing the user to select other items in the set without having to display them all.

更具体地说,我列出了4到5个电子邮件地址,但我只想一次显示一个,同时允许用户轻松选择其他项目。我已经搜索了所有内容,但是找不到修改组合框边框的简便方法,而且没有边框的组合框很适合我的需求。

To be more specific I have a list of 4 or 5 email addresses, but I only want to display one at a time while allowing the user a way to easily select a different item. I have searched all over but can't find an easy way to modify the border of a combobox, and a border less combobox will fit my needs nicely.

我刚刚开始使用C#,所以我还在学习,也许我缺少一些东西。看来这应该比实际要容易得多,希望有人能帮助我。

I just started with C# so I'm still learning, maybe I am missing something. Seems like this should be a lot easier than it's turning out to be, hopefully somebody can help me out.

编辑:

表单正在使用标签以显示信息,因此中间有一个组合框会使它看起来很糟糕。基本上,我要寻找的是一个链接,单击该链接可打开默认电子邮件程序并填写地址,但是我需要下拉按钮,以便可以选择其他地址。如果不需要,我不想显示大量的地址,我只想一次显示一个。像组合框一样,但没有边框。


The form is using labels to display information, so having a combobox in the middle of it makes it look awful. Basically what I'm looking for is a Link that when clicked opens the default email program and fills in the address, but I want the drop-down button so an alternate address can be selected. I don't want to display a huge list of addresses if I don't have to, I just want to display one at a time. Like a combobox, but with no border.

我可能只需要添加一个显示备用地址列表的按钮,但是如果我可以删除轮子,为什么还要重新发明轮子呢?组合框的边框,正是我在寻找什么?
谢谢

I could probably just add a button that displays a list of the alternate addresses, but why reinvent the wheel if I can just remove the border from a combobox and have exactly what I'm looking for? Thanks

推荐答案

也许您根本不需要ComboBox。假设您使用的是Windows窗体,则可以使用标准的TextBox,并将电子邮件地址列表添加到其AutoCompleteCustomSource(并将AutoCompleteSource设置为 CustomSource)。

Perhaps you don't need a ComboBox at all. Assuming you're using Windows Forms, You could use a standard TextBox and add your list of email addresses to its AutoCompleteCustomSource (and set AutoCompleteSource to "CustomSource").

然后如果将TextBox的AutoCompleteMode设置为 Append,则用户将永远不会看到电子邮件地址的完整列表-他们将在键入时获得在TextBox中填充的关闭匹配项。只需编写一些代码,您甚至可以使用向上和向下箭头键引入循环浏览可用项的功能。

Then if you set the TextBox's AutoCompleteMode to "Append" the user will never see the full list of email addresses - they'll just get the closes match populated in the TextBox as they type. With a bit of code-behind you might even be able to introduce the ability to cycle through the available items with the up and down arrow keys.

编辑

现在,您已经更新了问题,我建议使用一种完全不同的方法。

Now that you've updated your question, I'll suggest a completely different approach.

将默认电子邮件地址添加为标准标签。哎呀-将其添加为LinkLabel并使其可单击,以便其行为类似于网页上的mailto:链接。在该标签旁边,添加一个普通按钮。将其FlatStyle属性设置为 System,将字体名称设置为 Marlett,将标题设置为 u,因此它具有一个不错的下拉按钮外观。

Add the "default" email address as a standard Label. Heck - add it as a LinkLabel and make it clickable so it behaves like a mailto: link on a web page. Next to that label, add a normal Button. Set its FlatStyle property to "System", Font name to "Marlett" and caption to "u", so it has a nice "dropdown button" look to it.

现在,将ContextMenuStrip添加到表单中,并为每个电子邮件地址添加一个菜单项。您可以在代码中轻松完成此操作。

Now add a ContextMenuStrip to your form and add a menu item for each email address. You could do this in code pretty easily.

现在为按钮添加此Click事件处理程序:

Now add this Click event handler for your button:

private void button1_Click(object sender, EventArgs e)
{
    contextMenuStrip1.Show(button1, new Point(0, button1.Height));
}

因此,当单击按钮时,菜单弹出,显示备用电子邮件地址。您所需要做的就是捕捉菜单项的Click事件,以使用所选的电子邮件地址。

So when the button is clicked, the menu pops up displaying the "alternate" email addresses. All you'll need to do is catch the Click event of the menu items to "use" the selected email address.

这篇关于从组合框中删除边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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