3

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.

John Steed
  • 599
  • 1
  • 12
  • 31
  • Build a UI control that formats text is not easy. – paparazzo Oct 17 '12 at 19:41
  • Is this a web control or a winforms control? – Heather Oct 17 '12 at 23:19
  • It is a winforms control. Please note, the purpose of the control is to allow a field to be inserted as a placeholder which will be populated by data from a db. In every other respect, it will be identical to a textbox. Thanks. – John Steed Oct 18 '12 at 14:50

1 Answers1

1

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

  • Thanks Igal. In addition to visually indicating to the user that the word is a placeholder, the placeholder needs to be identified by code so that it can be replaced with data. For example, I want to aim for something like: myTextBox.field("sales_person").value = "Some Name" – John Steed Oct 18 '12 at 18:00
  • Define that a field placeholder starts with a unique char like @fieldname or any other markup system I used several times %fieldname%, then you can simply iterate throughout the text and use String.Replace for each field defined by the user. – Igal Berezovsky Oct 18 '12 at 23:00
  • Thanks Igal. That has given me plenty of ideas. – John Steed Oct 20 '12 at 14:20