ownerdrawn treenodes
-
Hi, While drawing treenodes, I'm having difficulties drawing the the boxes with pluses and minuses for node expansion. And also, I'm unable to simulate the hottracking action for each node when mousing over. Can you please help? thank you
-
Hi, While drawing treenodes, I'm having difficulties drawing the the boxes with pluses and minuses for node expansion. And also, I'm unable to simulate the hottracking action for each node when mousing over. Can you please help? thank you
You need to elaborate your scenario to understand the problem u r facing :doh:
-
Hi, While drawing treenodes, I'm having difficulties drawing the the boxes with pluses and minuses for node expansion. And also, I'm unable to simulate the hottracking action for each node when mousing over. Can you please help? thank you
Maybe this code should help you to understand... : protected override void OnDrawNode(DrawTreeNodeEventArgs e) .... if ((e.Node != null) && (e.Node is MyTreeNode)) { MyTreeNode myTreeNode = e.Node as MyTreeNode; Rectangle bounds = e.Bounds; if (myTreeNode.CHECKBOX == true) { ControlPaint.DrawCheckBox(e.Graphics, bounds.Left, bounds.Top, 16, 16, ButtonState.Checked); bounds = Rectangle.Inflate(bounds, 16, 0); } // Draw the background and node text for a selected node. if ((e.State & TreeNodeStates.Selected) != 0) { // Draw the background of the selected node. The NodeBounds // method makes the highlight rectangle large enough to // include the text of a node tag, if one is present. e.Graphics.FillRectangle(Brushes.BlueViolet, bounds); // Retrieve the node font. If the node font has not been set, // use the TreeView font. Font nodeFont = e.Node.NodeFont; if (nodeFont == null) nodeFont = this.Font; // Draw the node text. e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(bounds, 2, 0)); } // Use the default background and node text. else { e.DrawDefault = true; } // If a node tag is present, draw its string representation // to the right of the label text. //e.Graphics.DrawString(e.Node.Tag.ToString(), this.Font, // Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top); // If the node has focus, draw the focus rectangle large, making // it large enough to include the text of the node tag, if present. if ((e.State & TreeNodeStates.Focused) != 0) { using (Pen focusPen = new Pen(Color.Black)) { focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; Rectangle focusBounds = bounds; focusBounds.Size = new Size(focusBounds.Width - 1, focusBounds.Height - 1); e.Graphics.Dr
-
Maybe this code should help you to understand... : protected override void OnDrawNode(DrawTreeNodeEventArgs e) .... if ((e.Node != null) && (e.Node is MyTreeNode)) { MyTreeNode myTreeNode = e.Node as MyTreeNode; Rectangle bounds = e.Bounds; if (myTreeNode.CHECKBOX == true) { ControlPaint.DrawCheckBox(e.Graphics, bounds.Left, bounds.Top, 16, 16, ButtonState.Checked); bounds = Rectangle.Inflate(bounds, 16, 0); } // Draw the background and node text for a selected node. if ((e.State & TreeNodeStates.Selected) != 0) { // Draw the background of the selected node. The NodeBounds // method makes the highlight rectangle large enough to // include the text of a node tag, if one is present. e.Graphics.FillRectangle(Brushes.BlueViolet, bounds); // Retrieve the node font. If the node font has not been set, // use the TreeView font. Font nodeFont = e.Node.NodeFont; if (nodeFont == null) nodeFont = this.Font; // Draw the node text. e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(bounds, 2, 0)); } // Use the default background and node text. else { e.DrawDefault = true; } // If a node tag is present, draw its string representation // to the right of the label text. //e.Graphics.DrawString(e.Node.Tag.ToString(), this.Font, // Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top); // If the node has focus, draw the focus rectangle large, making // it large enough to include the text of the node tag, if present. if ((e.State & TreeNodeStates.Focused) != 0) { using (Pen focusPen = new Pen(Color.Black)) { focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; Rectangle focusBounds = bounds; focusBounds.Size = new Size(focusBounds.Width - 1, focusBounds.Height - 1); e.Graphics.Dr
thanks. So I guess if I want those boxes with plus/minus to the left of the node for expansion and contraction, I need to draw them myself.
-
thanks. So I guess if I want those boxes with plus/minus to the left of the node for expansion and contraction, I need to draw them myself.
xilefxilef wrote:
I need to draw them myself
That's what 'OwnerDrawm' is all about ;)
Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)