Tooltip not related to any particular control

I'm trying to do something like a spellcheck, which will list possible words at the current position of the carriage. I thought I would do this by creating a tooltip, moving it to fit the caret, and changing the text inside the tooltip.

I have a problem's.

I am trying to show a tooltip with tip.Show(form, x, y);

However, this application is launched from systray. There are no GUI elements from this? What am I using as a form parameter? notifyIcon1 , Form1 , etc. does not work.

I would start with an example that showed a static tooltip that moved with my mouse cursor or something like that. Can someone point me in the right direction?

thanks

+4
source share
4 answers

I posted a response in this thread that uses transparent, maximized to simulate drawing a tooltip anywhere on the screen, including the desktop. Perhaps this will help: Create a tooltip from a system tray application

Edit: I copied the code from the linked message for readability :-)

Here you are , use a transparent, maximized form in which you BringToFront() before showing the ToolTip

Form Code:

 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); } } } 

Constructor Code Form1:. You can see the properties of the forms:

 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; } } 

Update: With ControlBox = false; and Opacity = 0; the form is not only visually transparent, but also immune to user input. This happens even when Form1 higher, if the top window, clicking on it, gets into the next window / desktop. As if the form was not there. BringToFront () is required before showing the tooltip, because otherwise the tooltip could be drawn under other windows, which you don't need.

+1
source

You may be able to do this, but without using the tooltip class, as this is quite limiting, there is a fantastic tooltip helper called VXPLib using html formatting (which, I suppose, would give your word list with an edge - say, in different colors) . VXPLib is a COM object (written in C ++), but accessible from the .NET language, and there is a shell that can do this for you along with code samples. I tried them and they actually work and make them look good. See here for more details.

Hope this helps, Regards, Tom.

+1
source

If the application does not have a graphical interface, then in which application should you perform spell checking?

If you integrate the application with another existing application (not even .NET applications), you need to get the descriptor (HWND) of the other application and convert it to System.Windows.Forms.IWin32Window . After that, you can use this descriptor as form in the ToolTip.Show method.

Here is the code you need:

 using System.Diagnostics; //... public class MyWindow : System.Windows.Forms.IWin32Window { private IntPtr _hwnd; public IntPtr Handle { get { return _hwnd; } } public MyWindow(IntPtr handle) { _hwnd = handle; } //... public static MyWindow GetWindowFromName(string processName) { Process[] procs = Process.GetProcessesByName(processName); if (procs.Length != 0) { return new MyWindow(procs[0].MainWindowHandle); } else { throw new ApplicationException(String.Format("{0} is not running", processName)); } } } //... tip.Show("this worked...", MyWindow.GetWindowFromName("Notepad"), 0, 0, 2000); 
+1
source

I was working on creating a tooltip that is β€œnot related to any particular control” because I wanted to replace one of my AutoHotkey scripts that uses the ToolTip command.

I have a code stored at: https://bitbucket.org/tahir-hassan/dotnettooltip

All you do is create an instance of the control, set the displayed text, set the coordinates and call the Show method:

 var tooltip = new ToolTipLib.ToolTip() { Text = "this is a nice toolTip", LocationX = 100, LocationY = 200 }; tooltip.Show(); 
0
source

Source: https://habr.com/ru/post/1300354/


All Articles