Search code examples
c#.netvb.netmailmerge

.net textbox with user added fields


I would like to create a control class that would allow the user to type text like a normal text box. However, it should have a "mail merge field" functionality that would allow the user to insert a field from a list. This field would then be identified at a later stage for population. E.g.

Your order was processed by sales_person and will be sent on date.

In the above example, the user typed "Your order was processed by " and selected sales_person from a list of fields. This list would be another control, such as a list box, so this control class would have something like an insertField method that could be called.

At a later stage, that field would be populated so it would have to be identifiable in the code. Also, the user should be able to save and retrieve this phrase with its fields.

This UI is very similar to the building of a mail merge document in MS Word.

Can anyone offer advice and/or resources to achieve this. I'd rather build my own control than use a third party, but I need guidance.

Thanks very much.


Solution

  • Try to use System.Windows.Forms.RichTextBox, it will allow you to markup the placeholders by using the Find() function, and then change SelectionFont, SelectionColor or SelectionBackColor