Cách setting tooltip icon trong window form

Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

  • Article
  • 09/01/2020
  • 2 minutes to read

In this article

You can set a ToolTip string in code or in the Windows Forms Designer in Visual Studio. For more information about the ToolTip component, see ToolTip Component Overview.

  1. Add the control that will display the ToolTip.

  2. Use the SetToolTip method of the ToolTip component.

    ' In this example, Button1 is the control to display the ToolTip.
    ToolTip1.SetToolTip(Button1, "Save changes")
    
    // In this example, button1 is the control to display the ToolTip.
    toolTip1.SetToolTip(button1, "Save changes");
    
    // In this example, button1 is the control to display the ToolTip.
    toolTip1->SetToolTip(button1, "Save changes");
    
  1. In Visual Studio, add a ToolTip component to the form.

  2. Select the control that will display the ToolTip, or add it to the form.

  3. In the Properties window, set the ToolTip on ToolTip1 value to an appropriate string of text.

To remove a ToolTip programmatically

  1. Use the SetToolTip method of the ToolTip component.

    ' In this example, Button1 is the control displaying the ToolTip.
    ToolTip1.SetToolTip(Button1, Nothing)
    
    // In this example, button1 is the control displaying the ToolTip.
    toolTip1.SetToolTip(button1, null);
    
    // In this example, button1 is the control displaying the ToolTip.
    toolTip1->SetToolTip(button1, NULL);
    
  1. In Visual Studio, select the control that is displaying the ToolTip.

  2. In the Properties window, delete the text in the ToolTip on ToolTip1.

See also

  • ToolTip Component Overview
  • How to: Change the Delay of the Windows Forms ToolTip Component
  • ToolTip Component

Feedback

Submit and view feedback for

Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

  • Article
  • 07/26/2022
  • 2 minutes to read

In this article

The Windows Forms ToolTip component displays text when the user points at controls. A ToolTip can be associated with any control. An example use of this control: In order to save space on a form, you can display a small icon on a button and use a ToolTip to explain the button's function.

In This Section

ToolTip Component Overview
Introduces the general concepts of the ToolTip component, which allows users to see text when they point the mouse at a control.

How to: Set ToolTips for Controls on a Windows Form at Design Time
Describes how to set Tooltips in code or in the designer.

How to: Change the Delay of the Windows Forms ToolTip Component
Explains how to set values that control how long a Tooltip takes to appear and the length of time for which it is shown.

Reference

ToolTip class
Provides reference information on the class and its members.

Controls to Use on Windows Forms
Provides a complete list of Windows Forms controls, with links to information on their use.

Control Help Using ToolTips
Discusses Tooltips as a way to make brief, specialized Help messages for individual controls on Windows Forms.

Feedback

Submit and view feedback for

Xin chào các bạn, bài viết hôm nay mình sẽ hướng dẫn các bạn cách show Tooltip tại Control trên winform dùng để Validate dữ liệu khi nhập liệu trong lập trình C#.

[C#] Show Tooltip at Postion control in Winform

Thông thường, khi các bạn thiết kế form nhập liệu.

Nếu người dùng chưa nhập dữ liệu vào ô bắt buộc nhập require hay chưa chọn dữ liệu, cách thông thường chúng ta sẽ focus tới.

Nếu là Textbox thì chúng ta gọi hàm focus() : txtName.focus()

Còn nếu là Combobox hay GridlookupEdit chẳng hạn thì các bạn gọi thêm hàm ShowPopup() để cho ứng dụng mở luôn, để người dùng chọn cho tiện.

Dưới đây là giao diện demo mình sử dụng tooltip vào control khi người dùng chưa nhập liệu đầy đủ vào Form.

Cách setting tooltip icon trong window form

Source code C# tooltip at Postition Winform:

public void ShowToolTip(Control textEdit, LayoutControl layout, string title, string body, int duration = 1200)
        {
            var control = layout.ActiveControl;
            Point point = new Point();
            if (control != null)
            {
                point = Cursor.Position = control.PointToScreen(new Point(20, 10));
            }
            var toolTip = new ToolTip();
            toolTip.AutoPopDelay = 5000;
            toolTip.InitialDelay = 1000;            
            toolTip.ReshowDelay = 500;
            toolTip.ShowAlways = true;
            toolTip.IsBalloon = true;
            toolTip.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
            toolTip.ToolTipTitle =title;
            toolTip.Show(body, layout, textEdit.Location.X, textEdit.Location.Y - 70, duration);
        }

Control này mình đang viết để sử dụng trên thư viện Devexpress.

Và chúng ta gọi khi sử dụng:

ShowToolTip(cb_phongban, layoutControl1, "Thông báo", $"Chọn phòng ban, bạn ơi.");

Trong đó:

cb_phongban là control GridlookupEdit trong bài viết của mình.

Thanks for watching!

THÔNG TIN TÁC GIẢ

Cách setting tooltip icon trong window form
Founder 1151 bài viết 9,802,707

NGUYỄN THẢO

Founder at LaptrinhVB.net

★★★★★

♥ Tình yêu thương chẳng hề hư mất bao giờ. (Cr 13,4)

=========================================================================

My skills includes .NET(C#, VB.NET), DevExpress, Java, Android, PHP,

Python, Sqlserver, Mysql, Reactjs, Dart, Flutter, API services and lot more...

Phone/Zalo/Telegram/WhatsApp: +84.933.913.122

Email: 

Facebook: https://fb.com/Lewandowski28031988

Youtube Channel: https://www.youtube.com/c/CTutorialsTips

Cách setting tooltip icon trong window form
 

Buy me a cup of beer

Cách setting tooltip icon trong window form
       
Cách setting tooltip icon trong window form
Cách setting tooltip icon trong window form

Cách setting tooltip icon trong window form

=========================================================================

BÀI VIẾT LIÊN QUAN

Cách setting tooltip icon trong window form

Đăng bởi: Thảo Meo - Lượt xem: 3644 16:18:33, 06/05/2021EBOOK