|
I want to create my own tooltips for nodes in a treeview, but when I create my own tooltip and use it I still get the treeviews default tooltip. Is there any way to turn off the treeview's default tooltips? I have actually tried this on the ListView as well, getting the same results.
| | MigrationUser 1 Wednesday, February 05, 2003 12:07 PM | Can't say I've ever done it, but what about just changing the tooltip's text for the treeview in the mousemove event. you can take the coordinates of the mouse and use them to find out what node you're over in your treeview...or something along those lines | | MigrationUser 1 Wednesday, February 05, 2003 6:37 PM | My problem is I can't find a way to get to the treeview's tooltip. | | MigrationUser 1 Thursday, February 06, 2003 10:34 AM | MyToolTip.SetToolTip(Me.MyTreeView, "This is a TreeView")
| | MigrationUser 1 Thursday, February 06, 2003 12:12 PM | It doesn't work. Below is some sample code, when I run this application I get two tooltip windows.
public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TreeView treeView1; private System.Windows.Forms.ToolTip toolTip1; private System.ComponentModel.IContainer components; private System.Windows.Forms.ListView listView1; private System.Windows.Forms.ColumnHeader columnHeader1; private int oldNodeIndex = -1;
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.toolTip1.InitialDelay = 300; //half a second delay this.toolTip1.ReshowDelay = 0;
// // 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(); System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { "This is a test to see what happens"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)))); System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] { "this is another test to sys teeh"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)))); this.treeView1 = new System.Windows.Forms.TreeView(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.listView1 = new System.Windows.Forms.ListView(); this.columnHeader1 = new System.Windows.Forms.ColumnHeader(); this.SuspendLayout(); // // treeView1 // this.treeView1.FullRowSelect = true; this.treeView1.ImageIndex = -1; this.treeView1.Location = new System.Drawing.Point(40, 20); this.treeView1.Name = "treeView1"; this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { new System.Windows.Forms.TreeNode("TestNode", new System.Windows.Forms.TreeNode[] { new System.Windows.Forms.TreeNode("My test is very large text"),new System.Windows.Forms.TreeNode("This is testing large text")})}); this.treeView1.Scrollable = false; this.treeView1.SelectedImageIndex = -1; this.treeView1.ShowLines = false; this.treeView1.ShowPlusMinus = false; this.treeView1.ShowRootLines = false; this.treeView1.Size = new System.Drawing.Size(100, 200); this.treeView1.TabIndex = 0; this.treeView1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.treeView1_MouseMove); // // listView1 // this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {this.columnHeader1}); this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {listViewItem1,listViewItem2}); this.listView1.LabelWrap = false; this.listView1.Location = new System.Drawing.Point(160, 20); this.listView1.Name = "listView1"; this.listView1.Size = new System.Drawing.Size(80, 200); this.listView1.TabIndex = 1; this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.listView1, this.treeView1}); 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 treeView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { TreeNode tn = this.treeView1.GetNodeAt(e.X, e.Y); if(tn != null)
{
int currentNodeIndex = tn.Index;
if(currentNodeIndex != oldNodeIndex) {
oldNodeIndex = currentNodeIndex;
if(this.toolTip1 != null && this.toolTip1.Active)
this.toolTip1.Active = false; //turn it off
this.toolTip1.SetToolTip(this.treeView1, string.Format("tooltip: node {0}", oldNodeIndex));
this.toolTip1.Active = true; //make it active so it can show }
} }
| | MigrationUser 1 Thursday, February 06, 2003 12:36 PM | Ok, I was playing around with it just to see if I could get it working for an app I have a treeview in and I can't get it to work either.
I think what would be better to use those is the MouseHover Event. It get's the same way the ToolTip does, whenever you move the mouse over the control and stop moving for a short period of time.
Here's my code (that doesn't work mind you)
Private Sub TreeView_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvMain.MouseHover With CType(sender, TreeView) Dim CurrentNode As TreeNode = .GetNodeAt(.MousePosition) If CurrentNode Is Nothing Then ttMain.Active = False Else ttMain.SetToolTip(CType(sender, TreeView), CurrentNode.Text) ttMain.Active = True End If End With End Sub
Private Sub TreeView_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvMain.MouseLeave ttMain.Active = True End Sub
Sorry it's in VB, that's what this project is in and I don't have time to translate it ;)
Now what's really tripping me up is the the MousePosition of the TreeView is totally screwy. My TreeView is returning it's MousePosition 7, 1082 when i rollover the very first node. There's no way that's right. the x position should be around the same as the y position. What's up with that? Anyone know if I'm doing something wrong or if it's a bug or what? If I use e.X and e.Y in the MouseUp Event (I use that for right clicking to get a menu) it works just fine and doesn't return crazy numbers like MousePosition does. Anybody know what's going on with that?
Sorry for not answering your question, Chad...I think we'll figure it out :) | | MigrationUser 1 Thursday, February 06, 2003 1:55 PM | Most of what has been posted is correct. I'm just clearing up the question of the MousePosition issue. The MousePosition return screen coordinates not client coordinates, so all you need to do is change them to reference the Tree or Listview's coordinates and away you go, see below.
Private Sub TreeView1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.MouseHover Dim loPoint As Point = TreeView1.MousePosition Dim loNode As TreeNode = TreeView1.GetNodeAt(TreeView1.PointToClient(loPoint)) End Sub
Hope this helps.
There are a couple of posts in another forum here for more info, just search for PointToScreen.
Regards Allan | | MigrationUser 1 Sunday, May 18, 2003 3:27 AM |
|