Amitava_Mukherjee
asked on
Tree Node Font or graphics change On Mouse HOver
I want To change the font or graphical display of nodes in a treeview on mouse hover.It means that whenevr user hovers the mouse over each node the node has a different effect and then changes back to its previous font when the mouse shifts to another node and so on.
Thanx in advance.
Thanx in advance.
Is this in a Web or Windows application?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1. Open Visual Studio.NET 2005 editor and create a new C# Windows project
2. Open Form1 in designer mode
3. Drag and drop a TreeView control on the Form1
4. Add few nodes to the TreeView control(use the property Nodes to add nodes)
5. Set the property DrawNode of the TreeView control to OwnerDrawText
6. Set the property HotTracking to true
7. Add the following code to DrawNode event of the TreeView control and execute the project:
2. Open Form1 in designer mode
3. Drag and drop a TreeView control on the Form1
4. Add few nodes to the TreeView control(use the property Nodes to add nodes)
5. Set the property DrawNode of the TreeView control to OwnerDrawText
6. Set the property HotTracking to true
7. Add the following code to DrawNode event of the TreeView control and execute the project:
private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if ((e.State & TreeNodeStates.Hot) != 0)
{
Font f = new Font("Arial", 10);
e.Graphics.DrawString(e.Node.Text, f, Brushes.Red, e.Bounds);
}
else
{
e.DrawDefault = true;
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx For Your help
@sedgwick: In my application i am generating the nodes programatically.Strangely the event u suggested never fires in my application.
@carl_tawn: Ur code was something i was looking for...i kind of modified it to fit into my application.Actually i hav nodes of diffrenet fonts and font styles in my treeview.Here goes my code.:
@sedgwick: In my application i am generating the nodes programatically.Strangely the event u suggested never fires in my application.
@carl_tawn: Ur code was something i was looking for...i kind of modified it to fit into my application.Actually i hav nodes of diffrenet fonts and font styles in my treeview.Here goes my code.:
Private Sub tvLeft_NodeMouseHover(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeNodeMouseHoverEventArgs) Handles tvLeft.NodeMouseHover
If Not ctnPast Is Nothing AndAlso Not ctnPast.Equals(e.Node) Then
ctnPast.NodeFont = New Font(ctnPast.NodeFont.OriginalFontName, ctnPast.NodeFont.Size, sOldStyle)
End If
sOldStyle = e.Node.NodeFont.Style
ctnPast = e.Node
e.Node.NodeFont = New Font(e.Node.NodeFont.OriginalFontName, e.Node.NodeFont.Size, FontStyle.Bold)
End Sub
Dim sOldStyle As New FontStyle
Private ctnPast As TreeNode = Nothing
ASKER
Since my purpose is served am closing the question.thanx again.