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