Hi Michael,
From your description, you find that the tooltip text does not display all the text you included. So you would like to know if there is a mximun length we can
use to set the tooltip display the whole text. Have I understood correctly?
I believe there is no maximum length for the tooltip text. However we can change the tooltip window's width to display the whole text with a reasonable size.
I attached a simple code to do that. Please let me know if it solves your problem. Thanks!
Hope this helps!
Rhett Gong [MSFT]
Microsoft Online Partner Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
Please note: As a workaround a private method reflection is used here. The code works now on current version of .NET Framework, but since there is a private
reflection, it might be changed in the furture version, use it at your own risk.
//=-=-=-=-=-=-=-=-=-=-=-=-=Code Begin=-=-=-=-=-=-=-=-=-=-=-=-=-
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Tooltips
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
[DllImport("user32.dll")]
private extern static int SendMessage(IntPtr hwnd,uint msg, int wParam, int lParam);
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ToolTip myTooltip;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox2;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.HelpProvider helpProvider1;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.textBox1 = new System.Windows.Forms.TextBox();
this.myTooltip = new System.Windows.Forms.ToolTip(this.components);
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(64, 72);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
this.myTooltip.SetToolTip(this.textBox1, "I have a dream, my four little children will live in a nation where theyare not j" +
"udged by the color of their skin,but by the content of there characters. Go back");
//
// button1
//
this.button1.Location = new System.Drawing.Point(272, 80);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(64, 136);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
this.myTooltip.SetToolTip(this.textBox2, @"The ToolTip class can be used in any container. To specify a specific container to use the
ToolTip class within, use the ToolTip constructor. In order for ToolTip text to be displayed when the user moves the mouse cursor over a control, the ToolTip text
to be displayed must be associated with the control within an instance of the ToolTip class. To associate ToolTip text with a control, use the SetToolTip method.
The SetToolTip method can be called more than once for the same control to change the text that is associated with the control. If you want to get the text that
is associated with a control, use the GetToolTip method. To remove all ToolTip text associations with an instance of the ToolTip class, use the RemoveAll
method.");
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(504, 318);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
object o = typeof(ToolTip).InvokeMember
("Handle",BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetProperty,null,myTooltip,null);
IntPtr hwnd = (IntPtr) o;
SendMessage(hwnd,0x0418, 0, 300);
}
}
}