tags:

views:

1522

answers:

2

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.

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.

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.

EDIT:
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

+1  A: 

Why would you need the ComboBox to be borderless? Doesn't make much sense to me.

Make you can do is make a read-only ComboBox. You can populate the entries and the user will be allowed to select them but not type in any text.

Just set DropDownStyle to ComboBoxStyle.DropDownList.

this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;


Update:

You can try "hiding" the border by setting DrawMode to DrawMode.OwnerDrawFixed.

this.comboBox1.DrawMode = DrawMode.OwnerDrawFixed;

This won't hide it but makes it less visible.

Samuel
It ruins the look and feel of the form having a combobox on it. It's not that I don't want the user typing in the box, I don't want to see the box. I do however want the functionality of the combobox.
Tester101
+1  A: 

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").

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.

Edit

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

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.

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

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));
}

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.

Matt Hamilton
I want the user to be able to select from the list of emails. I don't want them to have to type, I assume they don't know the address that's why I want to list them.
Tester101
So ... you effectively want a label with a little dropdown arrow next to it which pops up a list?
Matt Hamilton
That's exactly what I want. but I thought rather than creating this, if I could just remove the border from a combobox it would be nice and simple.
Tester101
That was my workaround idea, I just thought it would be easier to remove the border, but I guess not. Thanks.
Tester101