473,783 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView DrawNode problem


I have overridden the default DrawNode (OwnerDrawText mode) to allow me to
draw an extra icon at the front of the text block, while still using the
built-in icon list for another icon. The problem I am having is that when a
node is selected it snips the text to the length of the text minus the
length of the extra icon.

Is there a way to redefine the selection box size for each node?

The DrawNode code is as follows :

private void tvParts_DrawNod e(object sender, DrawTreeNodeEve ntArgs e)
{
Brush fontbrush;
Icon ic;
Font font;

if (ilItemTypeIcon s.Images.Contai nsKey((e.Node as
itemTreeNode).i temtype_name))
ic = Icon.FromHandle (((Bitmap)ilIte mTypeIcons.Imag es[(e.Node as
itemTreeNode).i temtype_name]).GetHicon());
else
ic =
Icon.FromHandle (((Bitmap)ilIte mTypeIcons.Imag es["Default"]).GetHicon());

if ((e.State & TreeNodeStates. Selected) == TreeNodeStates. Selected)
fontbrush = System.Drawing. Brushes.White;
else
fontbrush = System.Drawing. Brushes.Black;

font = e.Node.NodeFont ;
if (font == null)
font = e.Node.TreeView .Font;

e.Graphics.Draw Icon(ic, e.Bounds.X, e.Bounds.Y);
e.Graphics.Draw String(e.Node.T ext, font, fontbrush, ic.Width +
e.Bounds.X, e.Bounds.Y);

}
--

"I have nothing but the greatest respect for other peoples' crackpot
beliefs".
-- Sam the Eagle.

Jun 28 '06 #1
3 11636
I think your problem is with the override of Graphics.DrawSt ring you're
using. It would appear that since you only passing an x and y location it
uses the current clip region to clip the text.

Try calculating a rectangle and using the DrawString override that takes a
rectangle rather than an x and y.

See the example with the TreeView.DrawNo de Event [1] docs on msdn for an
example of calculating that bounds rectangle.

[1]
http://msdn2.microsoft.com/en-us/lib....drawnode.aspx
--
http://www.peterRitchie.com/
"John" wrote:

I have overridden the default DrawNode (OwnerDrawText mode) to allow me to
draw an extra icon at the front of the text block, while still using the
built-in icon list for another icon. The problem I am having is that when a
node is selected it snips the text to the length of the text minus the
length of the extra icon.

Is there a way to redefine the selection box size for each node?

The DrawNode code is as follows :

private void tvParts_DrawNod e(object sender, DrawTreeNodeEve ntArgs e)
{
Brush fontbrush;
Icon ic;
Font font;

if (ilItemTypeIcon s.Images.Contai nsKey((e.Node as
itemTreeNode).i temtype_name))
ic = Icon.FromHandle (((Bitmap)ilIte mTypeIcons.Imag es[(e.Node as
itemTreeNode).i temtype_name]).GetHicon());
else
ic =
Icon.FromHandle (((Bitmap)ilIte mTypeIcons.Imag es["Default"]).GetHicon());

if ((e.State & TreeNodeStates. Selected) == TreeNodeStates. Selected)
fontbrush = System.Drawing. Brushes.White;
else
fontbrush = System.Drawing. Brushes.Black;

font = e.Node.NodeFont ;
if (font == null)
font = e.Node.TreeView .Font;

e.Graphics.Draw Icon(ic, e.Bounds.X, e.Bounds.Y);
e.Graphics.Draw String(e.Node.T ext, font, fontbrush, ic.Width +
e.Bounds.X, e.Bounds.Y);

}
--

"I have nothing but the greatest respect for other peoples' crackpot
beliefs".
-- Sam the Eagle.

Jun 29 '06 #2
How about using a StateImageList instead? That way you can have two images
for every node

/claes

"John" <ju**@junk.co m> wrote in message
news:e7******** **@perki.connec t.com.au...

I have overridden the default DrawNode (OwnerDrawText mode) to allow me to
draw an extra icon at the front of the text block, while still using the
built-in icon list for another icon. The problem I am having is that when
a node is selected it snips the text to the length of the text minus the
length of the extra icon.

Is there a way to redefine the selection box size for each node?

The DrawNode code is as follows :

private void tvParts_DrawNod e(object sender, DrawTreeNodeEve ntArgs e)
{
Brush fontbrush;
Icon ic;
Font font;

if (ilItemTypeIcon s.Images.Contai nsKey((e.Node as
itemTreeNode).i temtype_name))
ic = Icon.FromHandle (((Bitmap)ilIte mTypeIcons.Imag es[(e.Node as
itemTreeNode).i temtype_name]).GetHicon());
else
ic =
Icon.FromHandle (((Bitmap)ilIte mTypeIcons.Imag es["Default"]).GetHicon());

if ((e.State & TreeNodeStates. Selected) == TreeNodeStates. Selected)
fontbrush = System.Drawing. Brushes.White;
else
fontbrush = System.Drawing. Brushes.Black;

font = e.Node.NodeFont ;
if (font == null)
font = e.Node.TreeView .Font;

e.Graphics.Draw Icon(ic, e.Bounds.X, e.Bounds.Y);
e.Graphics.Draw String(e.Node.T ext, font, fontbrush, ic.Width +
e.Bounds.X, e.Bounds.Y);

}
--

"I have nothing but the greatest respect for other peoples' crackpot
beliefs".
-- Sam the Eagle.

Jun 29 '06 #3

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
How about using a StateImageList instead? That way you can have two images
for every node


That might be the cleaner solution, thanks.
Jun 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
6835
by: Evan Kontos | last post by:
I am trying to implement a Treeview w/an XML file and I even copied and pasted examples from MSDN but can't get them to work. Any suggestions welcome. XML File <TREENODES> <TREENODE TEXT="Document-1"> <TREENODE TEXT="Folder-1" EXPANDED="true"> <TREENODE TEXT="Document-2" />
4
2862
by: Jeff Beem | last post by:
I have a class that inherits from TreeView. The treeview has tooltips for the nodes but they're showing up behind the form. Has anyone seen this? Are there any known fixes? Thanks in advance, Jeff Beem
3
3472
by: pamelafluente | last post by:
Hi I have some instances of a class: Class Myobject Public Color As Color Public Label As String End Class I need to show these instances on a treeview (which has checked boxes)
8
12776
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
8
5636
by: Jon Slaughter | last post by:
I'm trying to override the default paiting of a treeview but I get bad results: My code(well, atleast this is the most simple that reproduces the result) is this private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e) { e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black, e.Bounds.Left, e.Bounds.Top); }
1
21628
by: watsod1 | last post by:
Hello, This is my first post, Hello to all. This also a test post to make sure that I am doing the right thing and following rules etc. I have been searching for a way to make the treeview display multiple lines of text on each treeview node (treenode). After searching for answers and not finding any, I stumbled on the solution in the msdn help files (search for TreeView.DrawNode Event). It has source code that shows how to display...
0
946
by: NickP | last post by:
Hi there, I am owner drawing a treeview control and appear to be having some problems. If I click on items then dont always select, more than often they don't, but if I set focus to the control and use the cursor keeps to scroll through the list, each item selects as expected. Sometimes the control does not refresh correctly, like when expanding a
1
3603
by: Nikron | last post by:
Hi, I'm having an issue with the ASP.NET 2.0 Treeview control and persisting its' state accross requests. My Control is embedded within a master page and is used for site navigation. My problem is that the user wants to know which page they are currently on and therefore I need to highlight the selected node. The problem is I lose state whenever the user selects a node and is redirected to another page. Thanks in advance
18
15379
by: =?Utf-8?B?TGkgV2VuZw==?= | last post by:
Hi, Is there a way for TreeView to have multiple selections? But I am not talking about its checked boxes. I want a way similar to ListView with MultiSelect = True. So I can use or key and click to make multiple selections. Then when I simply click one item, all previous selections are gone. Thanks in advance.
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10081
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.