473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Change Treeview Link line style

Hi All,
Can it be possible to change the Treeview link line(line connecting parent & Child node) style.Default its coming as dotted line .I want to make it solid line.
I am using WIN-FORM.
Please suggest.

-Gyanendar
May 11 '10 #1
5 8258
Plater
7,872 Expert 4TB
I think you would have to change the draw mode to owner draw and draw the lines yourself?
May 11 '10 #2
If i draw line by myself ,how i'll find the exact path along which line would be drawn? We can hide the treeview link and need to get the exact co-ordinate of the point of Parent & Child
May 11 '10 #3
Plater
7,872 Expert 4TB
Well getting one is easy with the DrawNode event.
Hmm I think I have an idea on how to draw the lines, i'll get back to you
May 11 '10 #4
@Plater
Hi Plater,
Thanks for reply.
Here If we have the co-ordinate of points ,line can be drawn by e.Graphics.Drawline().

Gyanendar
May 13 '10 #5
Plater
7,872 Expert 4TB
Yeah I did the whole thing(sort of). I don't generally do the project, but this one caught my interest.

I do a few silly things to highlight what is going on, but it could certainly be adapted as needed.

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
  3. {
  4.   bool isOSDrawn = e.DrawDefault;
  5.   Graphics g = e.Graphics;
  6.   TreeNode tn = e.Node;
  7.   Font DrawFont = treeView1.Font;
  8.   Brush ForeBrush = new SolidBrush(treeView1.ForeColor);
  9.   Brush BackGroundBrush = new SolidBrush(treeView1.BackColor);
  10.   Brush TextBackGroundBrush = BackGroundBrush;
  11.   float baseX = e.Bounds.Left;
  12.   float baseY = e.Bounds.Top;
  13.   string stringToDraw = tn.Text;
  14.   bool hasParent = (tn.Parent != null);
  15.   bool hasNext = (tn.NextNode != null);
  16.   bool hasPrev = (tn.PrevNode != null);
  17.  
  18.   float strX = baseX;
  19.   float strY = baseY;
  20.   float adjX = ((tn.Level + 1) * 24);
  21.   strX += adjX;
  22.  
  23.   Rectangle UpLine = new Rectangle((int)(strX - 17), (int)(baseY), 2, 8);
  24.   Rectangle DownLine = new Rectangle((int)(strX - 17), (int)(baseY + 8), 2, 8);
  25.   Rectangle ChildBox = new Rectangle((int)(baseX - 16 + adjX + 2), (int)(baseY + 2), 12, 12);
  26.  
  27.   float tailStartX = baseX - 16 + adjX + 2 + 12;
  28.   float tailStartY = baseY + 8;
  29.   if (e.Bounds.Width != 0)
  30.   {
  31.       if ((e.State & TreeNodeStates.Hot) == TreeNodeStates.Hot)
  32.       {//Hot tracking
  33.           DrawFont = new Font(DrawFont, FontStyle.Underline);
  34.       }
  35.       if ((e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected)
  36.       {//change foregroudn/background
  37.       TextBackGroundBrush = new SolidBrush(SystemColors.InactiveBorder);
  38.       if (this.ActiveControl == sender)
  39.       {
  40.         ForeBrush = new SolidBrush(SystemColors.HighlightText);
  41.         TextBackGroundBrush = new SolidBrush(SystemColors.Highlight);
  42.       }
  43.       }
  44.       //// Erase previous
  45.       g.FillRectangle(BackGroundBrush, e.Bounds);
  46.       SizeF stringSize = g.MeasureString(stringToDraw, DrawFont, (int)(e.Bounds.Width - strX), new StringFormat(StringFormatFlags.NoWrap));
  47.       //// Draw the "selected" background
  48.       g.FillRectangle(TextBackGroundBrush, strX, strY, (float)Math.Floor(stringSize.Width), 16F);
  49.       //// Draw the text
  50.       g.DrawString(stringToDraw, DrawFont, ForeBrush, strX, strY);
  51.  
  52.       //// Every node gets a tail sticking out
  53.       g.FillRectangle(Brushes.Black, strX - 17, tailStartY, 16, 2);
  54.       ///////////////////////////////////////////////////////////////////
  55.       if (hasPrev || hasParent) g.FillRectangle(Brushes.Black, UpLine);// Draw up line
  56.       if (hasNext) g.FillRectangle(Brushes.Black, DownLine);// Draw down line
  57.       //// Draw the "+" box
  58.       if (tn.Nodes.Count > 0)
  59.       {
  60.       g.FillRectangle(BackGroundBrush, ChildBox);
  61.       if (!tn.IsExpanded) g.FillRectangle(new SolidBrush(Color.Red), ChildBox);
  62.       g.DrawRectangle(Pens.Black, ChildBox);
  63.       }
  64.   }//end of valid draw region
  65. }
  66.  
  67.  
May 17 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Csaba2000 | last post by:
I have set onmousedown to change the cursor, but this setting is ignored (IE 5.5; NN 6.1 on Win 2K Pro) until the mouse is either moved or the mouse button is released. On Opera 7.01, the setting...
1
by: Bart | last post by:
Hi, When changing line style from solid to broken the result is devastating on speed. Something that used to take a fraction of a second to draw takes about a minute when line style is changed....
1
by: Anthony Boudouvas | last post by:
Hi to all, i have a treeview that i put some nodes in it with their repsective images. If i try to change the image and set it to some other ImageList index, nothing happens. The code i use...
2
by: Amir Eshterayeh | last post by:
Dear Friends I want to change the name of my css file dynamically so as Mr. Jos Branders helped me, I can change the <head> tag into an HTML control like this: <head id="myhead" runat="server">...
3
by: Fuzzyman | last post by:
Hello all, I'm using a website creation tool (called `rest2web <http://www.voidspace.org.uk/python/rest2web/>`_) that lets me store my content in a text based format ( `ReStructuredText...
0
by: karanovicm | last post by:
Hi I'm looking for "simple" toolbar with line style, line color line width controls Any sugestion are velcome Marinko
22
by: subashinicse | last post by:
hi to everybody, am new to this forum.. am working with J2ee,i have a jsp page where i have some links,i want to change the link color when it is active,and it has to turn back to original color...
0
by: prakashsakthivel | last post by:
Hi Members, "=win|L!'FR0010415,'" Syntex: "=Applicationname|Topic!item" Now I want to change DDE Link to OLE Link What are syntax available.. could you please anybody tell diff between DDE...
3
by: gyanendar | last post by:
Hi All, Is it possible to label (with some text) the link between two node of Treeview? Please suggest the way . Regards, Gyanendar
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.