See the StringFormat class (the defaults should do, but you can create your own) and the Graphics.DrawString method, which you can use in the OnPaint method override (always override methods instead of handling events in derived classes, but make sure to call the base class's method in most cases):
protectedoverridevoid OnPaint(PaintEventArgs e)
RectangleF rectF = GetRectFBoundsForControl(); // Made-up method to// get the bounds in which text can be drawn.
e.Graphics.DrawString("Some multi-line text",
StringFormat.GenericDefault); // Or create your own
Otherwise, you can always just P/Invoke DrawText, define the DT_CALCRECT and DT_WORDBREAK constants (or enum values) based on the preproc def values, and call the method using the control's HDC, which you can get during the Paint event (override OnPaint when deriving from Control instead):
ShaneStump wrote: I want it to return the # height of the string if wrapping occurs (if the string requres 5 lines, I want the returned height to be for the 5 lines). I am probably NOT using the right method.
Hmm, the MeasureString method is overloaded, and if you know the maximum width in pixels that your control will represent (I don't know if you will know this?) then you can make a call as such which will take into account wrapping.
private SizeF MyMeasureMethod(PaintEventArgs e)
string s = "Nick";
Font f = new Font("Arial", 12);
int width = 300;
SizeF strSize = new SizeF();
strSize = e.Graphics.MeasureString(s, f, width);
How does one programmatically "select" a node in a TreeView.
IE: the user clicks a button which spawns a child process, the output of which is displayed in a TextBox. Each time the user clicks that button, a new process is kicked off and I attach a new node to the TreeView to represent said process. If the user clicks on any given node, that node's associated process output TextBox is brought to the foreground - whre you can watch the output.
Adding the node to the TreeView is straightforward, but hilighting it or "selecting" it programmatically is not so easy.
Active and Selected are two completely different things. Active just means that the node has the focus, such as what it gains when you right-click the node. Selected means that the node has been left-clicked at some point. To select a node programmatically, just use the following:
After doing this - indeed the "selected" image appears to the left of the tree node (from the ImageList index used when creating the node) but, the actual text of the node is not "highlighted. IE: the folder opens, but the folder name is not highlighted.
This is even more obvious when working with a ListView. I've selected a particular ListViewItem, but no rectangular, reverse color block around the text of the item appears onscreen.
Maybe I am doing something wrong - or missing something? Without the highlighted text, its not really obvious which element has been selected.
Out of curiousity, does the rectangular marquee (the dotted lines) around the text appear? If so, the TreeView no longer seems to have the focus. Set TreeView.HideSelection to false and see if the rectangular selection region is at least gray (or whatever the default system color for inactive selected text is).
Which is why I've been trying to get Catalyst to understand that in a separate thread. I mean, if you can't even understand environment variables, why would anyway think to tackle COM? That's like trying to climb Everest or K2 without making it up the front steps to the lobby (if it has one?)!
If you want to do things this way, you must create an IDL file (don't use headers and don't worry about compiling to a DLL) and import additional IDL files when necessary. Interface documentation should list what IDL file they are found in. If not, check for a similar IDL file that matches the name of the header file (filename.h to filename.idl).