ToolTipText length

G

Guest

The length of the ToolTipText in my TabPage ToolTipText does not seem to display all the text I included in the ToolTipText property. Is there a maximum length? Can this value be changed

(Repeat the above quickly for yuks, but please still answer the post!

Michael
 
R

Rhett Gong [MSFT]

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

Guest

Difficult for me to decipher in c#. It's not clear to me which is typical code and which are the changes needed to change the ToolTipText length. Do you have a version in VB

Michael
 
R

Rhett Gong [MSFT]

Hi Michael,
The key changes in C# is listed below:
//....in the begin of public class Form1 : System.Windows.Forms.Form
[DllImport("user32.dll")]
private extern static int SendMessage(IntPtr hwnd,uint msg, int wParam, int lParam);
//.....
//....you can set the long tooltip text using the following method
this.myTooltip.SetToolTip(this.textBox1, @"set long tooltip text here");
//.....
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);
}

Here is the VB version. Hope this helps!
'......in public form1
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer,
ByVal lParam As Integer) As Integer
'.......
'....... add tooltip to the textbox
Me.ToolTip1.SetToolTip(Me.TextBox1, "set long tooltip text here")
'......add a button and let tooltip show with the fixed width
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As Type = GetType(ToolTip)
Dim obj As [Object] = t.InvokeMember("Handle", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or
Reflection.BindingFlags.GetProperty, Nothing, Me.ToolTip1, Nothing)
Dim hwnd As IntPtr = CType(obj, IntPtr)
SendMessage(hwnd, 1048, 0, 300)
End Sub

Please let me know if you could make this work. Thanks!

Have a nice day!
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top