Problem drawing the right font in an owner draw TreeView

  • Thread starter Richard Lewis Haggard
  • Start date
R

Richard Lewis Haggard

I have a TreeView control that is marked as DrawMode: OwnerDrawText and has
inline LabelEdit set to true. The problem is that the text that I'm getting
from the node to draw is not the same font that is being used by the edit or
the same font that is being used by inline editing. When I do the
DrawString, I'm using the font that is in the node so it is unclear to me
why the node's text is too big to fit in its bounds or why the displayed
text is larger than the same text in the node's inline edit box. Ideas?
 
R

Richard Lewis Haggard

And what font would that be? I'm already using the one that is associated
with control itself and that is where my confusion is coming from in that
there appears to be a discrepancy between the font that is supplied by the
control and the one that is used by the in place edit.
 
G

Guest

If you're already using the font, that means the underlying Windows control
that .NET uses doesn't support changing the font for the edit box.

You would have to handle the BeforeLabelEdit, set the
NodeLabelEditEventArgs.CancelEdit to false and do whatever you want for
editing...

I think this example does something like that:
http://www.codeproject.com/cs/miscc...sp?df=100&forumid=224195&exp=0&select=1952320

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
 
R

Richard Lewis Haggard

Thanks for the pointer. Rather than build another user control to handle
editing, I side stepped the issue by doing this:
During owner draw, I ignore the width of the passed in bounds rectangle.
Instead, I get the parent tree view's right edge and use that to generate a
DrawString rectangle. I also set the draw string's format value so that it
doesn't clip or wrap. The two togehter allow my own text to draw without
being clipped or trying to wrap.
I don't explicitly make the display font the same as the edit font. These
are allowed to be different. However, I do catch the before edit event and
use that to make sure that the TreeNode's display text is removed from the
screen, thus removing the stale text scraps that would otherwise be
displayed on the row at the same time that the smaller edit window is
active.

Again, thanks for the ideas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top