At it's simplest, instantiate an instance of the WatermarkInputPromptManager, and add a valid BaseEdit control with a prompt.
private WatermarkInputPromptManager watermarkManager;
public TestForm()
{
InitializeComponent();
watermarkManager = new WatermarkInputPromptManager();
watermarkManager.Add(textEdit, "Required");
}
This will place the word "Required" into the TextEdit control as an input prompt. The input prompt will be in SystemColors.GrayText. The normal text will be shown in SystemColors.ControlText.
To modify the default colors instantiate an instance of WatermarkInputPromptManager with the new default colors
watermarkManager = new WatermarkInputPromptManager(Color.Plum, Color.Empty);
This will make the input prompt color Plum and leave the control text color SystemColors.ControlText. Passing Color.Empty into either of the two parameters will keep the standard default color.
To change the default behavior of logging, localization and configuration you can set the IServicesHelper to your own implementation.
watermarkManager = new WatermarkInputPromptManager(new MyCustomServicesHelper());
The WatermarkInputPromptManager default behavior is to ignore BaseEdit descendants which are invalid. However, if you want to throw an exception instead, you can set the property ThrowExceptionWhenAddingInvalidControl to true. This would be appropriate during debug mode to prevent a developer from adding an inappropriate BaseEdit descendant.
You can also change the colors of individual controls added to the WatermarkInputPromptManager.
watermarkManager = new WatermarkInputPromptManager();
// use the default colors
watermarkManager.Add(buttonEdit, "Required");
// use custom colors for this one control
watermarkManager.Add(textEdit, "Required", Color.Plum, Color.Red);
Notes:
- Adding controls to the WatermarkInputPromptManager should be done after InitializeComponent() but before the form has been shown.
- If you change the default colors programmatically after the form has been shown, the controls will not reflect this change until the control Enter and Leave events have been called.
- The BaseEdit ControlCustomDisplayText event is not fired if the control is attached to a DxValidationProvider. The proper behavior can be forced by setting the AllowWatermarksWithDxValidationProviderKludge property to true.