程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> WinForm ToolTip應用辦法小結

WinForm ToolTip應用辦法小結

編輯:C#入門知識

WinForm ToolTip應用辦法小結。本站提示廣大學習愛好者:(WinForm ToolTip應用辦法小結)文章只能為提供參考,不一定能成為您想要的結果。以下是WinForm ToolTip應用辦法小結正文


本文針對WinForm ToolTip應用辦法停止實例總結,願望對年夜家進修C#法式設計有所贊助。詳細以下:

法式功效代碼以下:

using System.Drawing;
using System.Windows.Forms;

namespace WinFormUtilHelpV2
{
  /// <summary>
  /// 基於.NET 2.0的Tooltip對象類
  /// </summary>
  public static class TooltipToolV2
  {
    /// <summary>
    /// 為控件供給Tooltip
    /// </summary>
    /// <param name="control">控件</param>
    /// <param name="tip">ToolTip</param>
    /// <param name="message">提醒新聞</param>
    public static void ShowTooltip(this Control control, ToolTip tip, string message)
    {
      Point _mousePoint = Control.MousePosition;
      int _x = control.PointToClient(_mousePoint).X;
      int _y = control.PointToClient(_mousePoint).Y;
      tip.Show(message, control, _x, _y);
      tip.Active = true;
    }
    /// <summary>
    /// 為控件供給Tooltip
    /// </summary>
    /// <param name="control">控件</param>
    /// <param name="tip">ToolTip</param>
    /// <param name="message">提醒新聞</param>
    /// <param name="durationTime">堅持提醒的連續時光</param>
    public static void ShowTooltip(this Control control, ToolTip tip, string message, int durationTime)
    {
      Point _mousePoint = Control.MousePosition;
      int _x = control.PointToClient(_mousePoint).X;
      int _y = control.PointToClient(_mousePoint).Y;
      tip.Show(message, control, _x, _y, durationTime);
      tip.Active = true;
    }
    /// <summary>
    /// 為控件供給Tooltip
    /// </summary>
    /// <param name="control">控件</param>
    /// <param name="tip">ToolTip</param>
    /// <param name="message">提醒新聞</param>
    /// <param name="xoffset">程度偏移量</param>
    /// <param name="yoffset">垂直偏移量</param>
    public static void ShowTooltip(this Control control, ToolTip tip, string message, int xoffset, int yoffset)
    {
      Point _mousePoint = Control.MousePosition;
      int _x = control.PointToClient(_mousePoint).X;
      int _y = control.PointToClient(_mousePoint).Y;
      tip.Show(message, control, _x + xoffset, _y + yoffset);
      tip.Active = true;
    }
    /// <summary>
    /// 為控件供給Tooltip
    /// </summary>
    /// <param name="control">控件</param>
    /// <param name="tip">ToolTip</param>
    /// <param name="message">提醒新聞</param>
    /// <param name="xoffset">程度偏移量</param>
    /// <param name="yoffset">垂直偏移量</param>
    /// <param name="durationTime">堅持提醒的連續時光</param>
    public static void ShowTooltip(this Control control, ToolTip tip, string message, int xoffset, int yoffset, int durationTime)
    {
      Point _mousePoint = Control.MousePosition;
      int _x = control.PointToClient(_mousePoint).X;
      int _y = control.PointToClient(_mousePoint).Y;
      tip.Show(message, control, _x + xoffset, _y + yoffset, durationTime);
      tip.Active = true;
    }
  }
}

應用辦法示例:

using System;
using System.Windows.Forms;
using WinFormUtilHelpV2;

namespace TooltipToolV2Test
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
      button1.ShowTooltip(toolTip, "button1_Click");
    }
    private void listBox1_Click(object sender, EventArgs e)
    {
      listBox1.ShowTooltip(toolTip, "listBox1_Click", 500);
    }
  }
}

代碼運轉後果以下:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved