473,320 Members | 2,027 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,320 software developers and data experts.

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_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
Brush fontbrush;
Icon ic;
Font font;

if (ilItemTypeIcons.Images.ContainsKey((e.Node as
itemTreeNode).itemtype_name))
ic = Icon.FromHandle(((Bitmap)ilItemTypeIcons.Images[(e.Node as
itemTreeNode).itemtype_name]).GetHicon());
else
ic =
Icon.FromHandle(((Bitmap)ilItemTypeIcons.Images["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.DrawIcon(ic, e.Bounds.X, e.Bounds.Y);
e.Graphics.DrawString(e.Node.Text, 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 11564
I think your problem is with the override of Graphics.DrawString 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.DrawNode 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_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
Brush fontbrush;
Icon ic;
Font font;

if (ilItemTypeIcons.Images.ContainsKey((e.Node as
itemTreeNode).itemtype_name))
ic = Icon.FromHandle(((Bitmap)ilItemTypeIcons.Images[(e.Node as
itemTreeNode).itemtype_name]).GetHicon());
else
ic =
Icon.FromHandle(((Bitmap)ilItemTypeIcons.Images["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.DrawIcon(ic, e.Bounds.X, e.Bounds.Y);
e.Graphics.DrawString(e.Node.Text, 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.com> wrote in message
news:e7**********@perki.connect.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_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
Brush fontbrush;
Icon ic;
Font font;

if (ilItemTypeIcons.Images.ContainsKey((e.Node as
itemTreeNode).itemtype_name))
ic = Icon.FromHandle(((Bitmap)ilItemTypeIcons.Images[(e.Node as
itemTreeNode).itemtype_name]).GetHicon());
else
ic =
Icon.FromHandle(((Bitmap)ilItemTypeIcons.Images["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.DrawIcon(ic, e.Bounds.X, e.Bounds.Y);
e.Graphics.DrawString(e.Node.Text, 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****************@TK2MSFTNGP03.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
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...
4
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,...
3
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
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...
8
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...
1
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...
0
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...
1
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...
18
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.