Getting Started with Windows Forms Watermark Text Provider

2 Nov 20226 minutes to read

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

  1. 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
    <div class="tabs">
       
    <ul class="nav nav-tabs" role="tablist">
       
    <li role="presentation" class=""><a data-target="#dku0vvrz9pc1osnzj6k3q4i6pe130tes-csharp" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="csharp">C#</a></li>
    <li role="presentation" class=""><a data-target="#9x5uow2w2k7fb2mk875z348aunnvtrn0-vbnet" aria-controls="home" role="tab" data-toggle="tab" data-original-lang="vb">VB.NET</a></li>
       
    </ul>
       
    <div class="tab-content">
       
       
       
    <div role="tabpanel" class="tab-pane" id="dku0vvrz9pc1osnzj6k3q4i6pe130tes-csharp" data-original-lang = "csharp" ><div class="highlight"><pre><code class="language-csharp" data-lang="csharp"><span></span><span class="n">BannerTextProvider</span> <span class="n">bannerTextProvider1</span> <span class="p">=</span> <span class="k">new</span> <span class="n">BannerTextProvider</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="n">components</span><span class="p">);</span></code></pre></div>
    </div>
       
       
    <div role="tabpanel" class="tab-pane" id="9x5uow2w2k7fb2mk875z348aunnvtrn0-vbnet" data-original-lang = "vb" ><div class="highlight"><pre><code class="language-vbnet" data-lang="vbnet"><span></span><span class="k">Dim</span> <span class="n">bannerTextProvider</span> <span class="ow">As</span> <span class="n">bannerTextProvider1</span> <span class="o">=</span> <span class="k">New</span> <span class="n">BannerTextProvider</span><span class="p">(</span><span class="k">Me</span><span class="p">.</span><span class="n">components</span><span class="p">)</span></code></pre></div>
    </div>
       
       
    </div>
       
    </div>
    

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.