Getting Started with Windows Forms Watermark Text Provider (BannerText)

This section briefly describes how to create a new Windows Forms project in Visual Studio and add BannerTextProvider with its basic functionalities.

Assembly deployment

Refer to the control dependencies section to get the list of assemblies or the details of NuGet package that needs to be added as reference to use the control in any application.

Refer to this documentation to find more details about installing nuget packages in a Windows Forms application.

Creating Application with BannerTextProvider

Create new Windows Forms Project in Visual Studio to display watermark for editor controls using BannerTextProvider control.

Adding BannerTextProvider control via designer

1) Create a new Windows Forms application using Visual Studio.

2) Add the the BannerTextProvider control to an application by dragging it from the toolbox to Form designer window. The dependent assemblies will be added automatically.

Drag and drop BannerTextProvider from toolbox

3) Drag the required control from toolbox and add to the form. For example, you can choose TextBoxExt control and get an extender provider property as illustrated in the following sample.

BannerTextProvider in Properties window of TextBoxExt control

BannerTextProvider added to TextBoxExt control

Adding BannerTextProvider control via code

In order to add BannerTextProvider control manually, do the below steps,

1) Add the required assembly references to the project.

2) Add the required namespace and create the BannerTextProvider control instance then add it to the Form.

using Syncfusion.Windows.Forms;
Imports Syncfusion.Windows.Forms
BannerTextProvider bannerTextProvider1 = new BannerTextProvider(this.components);
Dim bannerTextProvider As bannerTextProvider1 = New BannerTextProvider(Me.components)

Assigning banner text to a control

1) Add the control to which you want to set BannerText in the form. For example, you can choose TextBoxExt and add it to the form.

TextBoxExt textBoxExt = new TextBoxExt()
{
    Size = new Size(150, 50),
    Location = new Point(50, 50)
};

this.Controls.Add(textBoxExt);
Dim textBoxExt As TextBoxExt = New TextBoxExt() With 
{
    .Size = New Size(150, 50),
    .Location = New Point(50, 50)
}

Me.Controls.Add(textBoxExt)

2) Assign the banner text to the control.

BannerTextInfo bannerTextInfo = new BannerTextInfo()
{
    Text = "Type here...",
    Visible = true,
};

bannerTextProvider1.SetBannerText(textBoxExt, bannerTextInfo);
Dim bannerTextInfo As BannerTextInfo = New BannerTextInfo() With 
{
    .Text = "Type here...",
    .Visible = True
}

bannerTextProvider1.SetBannerText(textBoxExt, bannerTextInfo)

NOTE

Make sure to clear the default value of the Text property of the control before setting the banner text.

The Visible property allows you to customize visibility of BannerTextProvider control. Text and Color properties allows you to set the watermark text and it’s fore color. The Font property allows to customize the Font of watermark.

The rendering mode for disappearing the banner text can be customized by using Mode property using the following values,

  • FocusMode - The banner text disappears when the control gets focus.
  • EditMode - The banner text disappears only when the control is in Edit mode or when the associated text box is not empty.
bannerTextProvider1.SetBannerText(textBoxExt, new Syncfusion.Windows.Forms.BannerTextInfo("Type here...", true, new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Italic), System.Drawing.Color.RoyalBlue, Syncfusion.Windows.Forms.BannerTextMode.EditMode));
bannerTextProvider1.SetBannerText(textBoxExt, New Syncfusion.Windows.Forms.BannerTextInfo("Type here...", True, New System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Italic), System.Drawing.Color.RoyalBlue, Syncfusion.Windows.Forms.BannerTextMode.EditMode))

Windows Forms BannerTextProvider showing bannertext to TextBoxExt control

Controls which supports BannerText

BannerTextProvider feature can only be used for the following controls only.