SetToolTip, briefly flashes tooltip when called

G

Guest

Click button in first form, which opens another form. Type in text if
desired then click the OK button here.
The tooltip text for the button on the first form is briefly flashed when
SetToolTip is called. But only if the two buttons are clicked by mouse (not
keypress).
Any idea why the flashing occurs???
Thanks


Example code.
NOTE: can be run using snipper compiler.

using System;
using System.Collections;
using System.Windows.Forms;

public class TestClass : System.Windows.Forms.Form
{
private string[] __TestClassComment = new string[8];
private int __TestClass_Instance = 1;
private System.Windows.Forms.ToolTip toolTip1;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button Commentbutton;
private string __TestClass_ToolTips_CommentButton = "default string";

public static void Main()
{
Application.Run(new TestClass());
}

public TestClass()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.Commentbutton = new System.Windows.Forms.Button();

this.Commentbutton.BackColor = System.Drawing.SystemColors.Control;
this.Commentbutton.Location = new System.Drawing.Point(100,100);
this.Commentbutton.Name = "Commentbutton";
this.Commentbutton.Size = new System.Drawing.Size(50,20);
this.Commentbutton.Text = "Comment";
this.toolTip1.SetToolTip(this.Commentbutton, "Commentbutton.ToolTip");
this.Commentbutton.Click += new
System.EventHandler(this.Commentbutton_Click);

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(360, 318);
this.Controls.Add(this.Commentbutton);
this.Enabled = true;
this.Visible = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
}


protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


private void Commentbutton_Click(object sender, System.EventArgs e)
{
Comment comment = new Comment(this.ParentForm);
comment._CommentText = __TestClassComment[__TestClass_Instance];
comment.ShowDialog();
// update comment to storage and tooltip,
// change button color too
__TestClassComment[__TestClass_Instance] = comment._CommentText;

//
//
//
//
// Here is the SetToolTip where the issue is located.
//
//
//
//
if(__TestClassComment[__TestClass_Instance].Length == 0)
{
Commentbutton.BackColor = System.Drawing.SystemColors.Control;
this.toolTip1.SetToolTip(Commentbutton,
__TestClass_ToolTips_CommentButton);
}
else
{
Commentbutton.BackColor = System.Drawing.Color.Yellow;
this.toolTip1.SetToolTip(Commentbutton,
__TestClassComment[__TestClass_Instance]);
}
comment.Dispose();
}

}



public class Comment : System.Windows.Forms.Form
{
private System.Windows.Forms.Button OKbutton;
private System.Windows.Forms.TextBox CommenttextBox;
private System.ComponentModel.Container components = null;

public Comment(System.Windows.Forms.Form owner)
{
InitializeComponent();
this.Owner = owner;
}


protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

private void InitializeComponent()
{
this.CommenttextBox = new System.Windows.Forms.TextBox();
this.OKbutton = new System.Windows.Forms.Button();
this.SuspendLayout();

this.CommenttextBox.AcceptsReturn = true;
this.CommenttextBox.Dock = System.Windows.Forms.DockStyle.Top;
this.CommenttextBox.Location = new System.Drawing.Point(0, 0);
this.CommenttextBox.Multiline = true;
this.CommenttextBox.Name = "CommenttextBox";
this.CommenttextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.CommenttextBox.Size = new System.Drawing.Size(360, 264);
this.CommenttextBox.TabIndex = 0;
this.CommenttextBox.Text = "";
this.CommenttextBox.WordWrap = false;

this.OKbutton.Location = new System.Drawing.Point(272, 280);
this.OKbutton.Name = "OKbutton";
this.OKbutton.TabIndex = 1;
this.OKbutton.Text = "OK";
this.OKbutton.Click += new System.EventHandler(this.OKbutton_Click);

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(360, 318);
this.ControlBox = false;
this.Controls.Add(this.OKbutton);
this.Controls.Add(this.CommenttextBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Name = "Comment";
this.Text = "Enter Comment";
this.ResumeLayout(false);
}

private void OKbutton_Click(object sender, System.EventArgs e)
{
this.Visible = false;
// replace any TABs with spaces, as tabs cause the tooltip not to be shown
this.CommenttextBox.Text = this.CommenttextBox.Text.Replace("\t"," ");
//note: ampersands "&" will not be shown in tooltip properly
}


public string _CommentText
{
get
{
return this.CommenttextBox.Text;
}
set
{
this.CommenttextBox.Text = value;
}
}

}
 
J

Jeffrey Tan[MSFT]

Hi kenneth,

Thanks for your post.

Yes, I have created a sample project with your full code snippet. However,
it just works well on my side, without any flashed for tooltip. I have
attached my test sample project in this reply for your reference. (You can
get it with OE, not IE)

So, I suspect that your issue is machine-specific or project-specific.
Please follow below 2 steps:
1. Download my attached project and run it to see if this problem existed.
Then we can determine if it is project-specific
2. Move the problem project on another machine to see if this problem
existed, then we can determine if this is machine-specific.

I will wait for your further test result.

Furthermore, after doing some search on internet, I only found the message
below may help you:
http://dotnet247.com/247reference/msgs/53/268825.aspx
Is your problem the same as this one?

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi Jeffrey,

I tried running that project on my computer and another. Both showed the
issue.
When the OK button is clicked by mouse, the tooltip text is briefly flashed
right at the mouse position.
Its strange that it doesn't occur for you.

The message link you found sounds like a different issue. My tooltips pop
up when I hover, its just this extra showing when setting their text that is
troubling.

Thanks for your help,
Ken

BREAKTHROUGH:
-------------------
If I deactivate the tooltip before setting the new text, then reactivate it
afterwards, the issue no longer occurs.
toolTip1.Active = false;
this.toolTip1.SetToolTip(Commentbutton,
__TestClassComment[__TestClass_Instance]);
toolTip1.Active = true;

What is weird is we change some tooltips dynamically in other code, but this
problem doesn't occur there. I guess I should not complain too much, as I do
have a way to alleviate the problem.
 
J

Jeffrey Tan[MSFT]

Hi Ken,

I am glad you fnid a workaround for your issue. Anyway, if you need further
help, please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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