I am looking for a control (or suggestions on building my own) for a .NET 2.0 (windows) app that works like the address box in the Outlook mail window (bee below)
Outlook Address Control http://content.screencast.com/users/Ryan_Farley/folders/Jing/media/a511142b-dd04-4885-ad1e-f2582c201723/2009-03-12_2116.png
The control basically works where each e-mail address is like an item in the text area. I don't care so much about letting the user also type into this area like you can in Outlook. I just want to be able to add these complete strings (e-mail addresses) to the text area, or list, and the user can select them (but not edit) and can delete or backspace through the list to delete entire items (e-mail addresses).
Anyone know of a control out there that does this? Any suggestions for building my own? (or anyone know what you even call this control so I know what to google?)
Here's some code to get you started.
using System.Text;
using System.Windows.Forms;
using System;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.Text = "[email protected]; [email protected]; [email protected]";
}
private void textBox1_Click(object sender, EventArgs e)
{
int nextSpaceIndex = textBox1.Text.Substring(textBox1.SelectionStart).IndexOf(' ');
int firstSpaceIndex = textBox1.Text.Substring(0, textBox1.SelectionStart).LastIndexOf(' ');
nextSpaceIndex = nextSpaceIndex == -1 ? textBox1.Text.Length : nextSpaceIndex + textBox1.SelectionStart;
firstSpaceIndex = firstSpaceIndex == -1 ? 0 : firstSpaceIndex;
textBox1.SelectionStart = firstSpaceIndex;
textBox1.SelectionLength = nextSpaceIndex - firstSpaceIndex;
}
}
}
This will, when you click on an email address, select the entire email address. I'm not sure if this is the functionality you're going for (it sounds like it is, though), but it'll get you started. If you want to do other things beyond having click functionality, hook into the other events offered by TextBox
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With