未链接到任何特定控件的工具提示

cks*_*ubs 5 c# tooltip

我正在尝试制作类似拼写检查器的东西,它将列出当前插入符号位置下可能的单词。我想我可以通过创建一个工具提示,根据插入符号的位置移动它,并更改工具提示内的文本来做到这一点。

我有问题。

我正在尝试显示工具提示 tip.Show(form, x, y);

但是,此应用程序是从系统托盘运行的。除此之外它没有GUI元素吗?我用什么作为form参数?的notifyIcon1Form1等不工作。

我将从一个显示静态工具提示的示例开始,该工具提示随鼠标光标或其他东西一起移动。有人可以指出我正确的方向吗?

谢谢

Cor*_*ton 1

我在此线程中发布了一个答案,该答案使用透明的最大化来模拟在屏幕上的任何位置(包括桌面)绘制工具提示。也许它会有所帮助:从仅系统托盘的应用程序创建工具提示

编辑:从链接的帖子中复制代码以便于阅读:-)

在这里,您BringToFront()可以使用在显示之前使用的透明、最大化的表单ToolTip

表格 1 代码:

using System;
using System.Windows.Forms;

namespace SO_ToolTip
{
    public partial class Form1 : Form
    {
        Random _Random = new Random();
        ToolTip _ToolTip = new ToolTip();

        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            BringToFront();
            _ToolTip.Show("Blah blah... Blah blah... Blah blah...", this, _Random.Next(0, Width), _Random.Next(0, Height), 10000);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Form1 设计器代码:这样您就可以看到表单属性:

namespace SO_ToolTip
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            // 
            // timer1
            // 
            this.timer1.Enabled = true;
            this.timer1.Interval = 1000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 264);
            this.ControlBox = false;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.Opacity = 0;
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Timer timer1;

    }
}
Run Code Online (Sandbox Code Playgroud)

更新:使用ControlBox = false;Opacity = 0;表单不仅在视觉上透明,而且不受用户输入的影响。即使在Form1上面的情况下,如果在其区域中单击的最顶部窗口会落入下一个窗口/桌面。就像表格不存在一样。显示工具提示之前需要 BringToFront() ,否则工具提示可能会在其他窗口下绘制,这不是您想要的。