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
5 8258
I think you would have to change the draw mode to owner draw and draw the lines yourself?
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
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
@Plater
Hi Plater,
Thanks for reply.
Here If we have the co-ordinate of points ,line can be drawn by e.Graphics.Drawline().
Gyanendar
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. -
-
private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
-
{
-
bool isOSDrawn = e.DrawDefault;
-
Graphics g = e.Graphics;
-
TreeNode tn = e.Node;
-
Font DrawFont = treeView1.Font;
-
Brush ForeBrush = new SolidBrush(treeView1.ForeColor);
-
Brush BackGroundBrush = new SolidBrush(treeView1.BackColor);
-
Brush TextBackGroundBrush = BackGroundBrush;
-
float baseX = e.Bounds.Left;
-
float baseY = e.Bounds.Top;
-
string stringToDraw = tn.Text;
-
bool hasParent = (tn.Parent != null);
-
bool hasNext = (tn.NextNode != null);
-
bool hasPrev = (tn.PrevNode != null);
-
-
float strX = baseX;
-
float strY = baseY;
-
float adjX = ((tn.Level + 1) * 24);
-
strX += adjX;
-
-
Rectangle UpLine = new Rectangle((int)(strX - 17), (int)(baseY), 2, 8);
-
Rectangle DownLine = new Rectangle((int)(strX - 17), (int)(baseY + 8), 2, 8);
-
Rectangle ChildBox = new Rectangle((int)(baseX - 16 + adjX + 2), (int)(baseY + 2), 12, 12);
-
-
float tailStartX = baseX - 16 + adjX + 2 + 12;
-
float tailStartY = baseY + 8;
-
if (e.Bounds.Width != 0)
-
{
-
if ((e.State & TreeNodeStates.Hot) == TreeNodeStates.Hot)
-
{//Hot tracking
-
DrawFont = new Font(DrawFont, FontStyle.Underline);
-
}
-
if ((e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected)
-
{//change foregroudn/background
-
TextBackGroundBrush = new SolidBrush(SystemColors.InactiveBorder);
-
if (this.ActiveControl == sender)
-
{
-
ForeBrush = new SolidBrush(SystemColors.HighlightText);
-
TextBackGroundBrush = new SolidBrush(SystemColors.Highlight);
-
}
-
}
-
//// Erase previous
-
g.FillRectangle(BackGroundBrush, e.Bounds);
-
SizeF stringSize = g.MeasureString(stringToDraw, DrawFont, (int)(e.Bounds.Width - strX), new StringFormat(StringFormatFlags.NoWrap));
-
//// Draw the "selected" background
-
g.FillRectangle(TextBackGroundBrush, strX, strY, (float)Math.Floor(stringSize.Width), 16F);
-
//// Draw the text
-
g.DrawString(stringToDraw, DrawFont, ForeBrush, strX, strY);
-
-
//// Every node gets a tail sticking out
-
g.FillRectangle(Brushes.Black, strX - 17, tailStartY, 16, 2);
-
///////////////////////////////////////////////////////////////////
-
if (hasPrev || hasParent) g.FillRectangle(Brushes.Black, UpLine);// Draw up line
-
if (hasNext) g.FillRectangle(Brushes.Black, DownLine);// Draw down line
-
//// Draw the "+" box
-
if (tn.Nodes.Count > 0)
-
{
-
g.FillRectangle(BackGroundBrush, ChildBox);
-
if (!tn.IsExpanded) g.FillRectangle(new SolidBrush(Color.Red), ChildBox);
-
g.DrawRectangle(Pens.Black, ChildBox);
-
}
-
}//end of valid draw region
-
}
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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....
|
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...
|
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">...
|
by: Abrams |
last post by:
Thanks a lot.
|
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...
|
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
|
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...
|
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...
|
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
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |