TreeNode.Bounds Property
Gets the bounds of the tree node.
[Visual Basic] Public ReadOnly Property Bounds As Rectangle [C#] public Rectangle Bounds {get;} [C++] public: __property Rectangle get_Bounds(); [JScript] public function get Bounds() : Rectangle;
Property Value
The Rectangle that represents the bounds of the tree node.
Remarks
The coordinates are relative to the upper left corner of the TreeView control.
Example
[Visual Basic, C#, C++] The following example changes the size NodeFont to the specified size and adjusts the ItemHeight of the tree node's parent TreeView contorl. This example assumes you have a Form with a TreeView control with a collection of TreeNode objects, and a ComboBox containing font sizes.
[Visual Basic] Private Sub Button1_Click(sender As Object, e As EventArgs) myTreeView.ItemHeight = 5 myTreeView.SelectedNode.NodeFont = New Font("Arial", 5) ' Get the font size from combobox. Dim selectedString As String = myComboBox.SelectedItem.ToString() Dim myNodeFontSize As Integer = Int32.Parse(selectedString) ' Set the font of root node. myTreeView.SelectedNode.NodeFont = New Font("Arial", myNodeFontSize) Dim i As Integer For i = 0 To (myTreeView.Nodes(0).Nodes.Count) - 1 ' Set the font of child nodes. myTreeView.Nodes(0).Nodes(i).NodeFont = New Font("Arial", _ myNodeFontSize) Next i ' Get the bounds of the tree node. Dim myRectangle As Rectangle = myTreeView.SelectedNode.Bounds Dim myNodeHeight As Integer = myRectangle.Height If myNodeHeight < myNodeFontSize Then myNodeHeight = myNodeFontSize End If myTreeView.ItemHeight = myNodeHeight + 4 End Sub [C#] private void Button1_Click(object sender,EventArgs e) { myTreeView.ItemHeight = 5; myTreeView.SelectedNode.NodeFont = new Font("Arial",5); // Get the font size from combobox. string selectedString = myComboBox.SelectedItem.ToString(); int myNodeFontSize = Int32.Parse(selectedString); // Set the font of root node. myTreeView.SelectedNode.NodeFont = new Font("Arial",myNodeFontSize); for(int i = 0; i < myTreeView.Nodes[0].Nodes.Count; i++) { // Set the font of child nodes. myTreeView.Nodes[0].Nodes[i].NodeFont = new Font("Arial",myNodeFontSize); } // Get the bounds of the tree node. Rectangle myRectangle = myTreeView.SelectedNode.Bounds; int myNodeHeight = myRectangle.Height; if(myNodeHeight < myNodeFontSize) { myNodeHeight = myNodeFontSize; } myTreeView.ItemHeight = myNodeHeight + 4; } [C++] private: void Button1_Click(Object* /*sender*/, EventArgs* /*e*/) { myTreeView->ItemHeight = 5; myTreeView->SelectedNode->NodeFont = new System::Drawing::Font(S"Arial", 5); // Get the font size from combobox. String* selectedString = myComboBox->SelectedItem->ToString(); int myNodeFontSize = Int32::Parse(selectedString); // Set the font of root node. myTreeView->SelectedNode->NodeFont = new System::Drawing::Font(S"Arial", (float)myNodeFontSize); for (int i = 0; i < myTreeView->Nodes->Item[0]->Nodes->Count; i++) { // Set the font of child nodes. myTreeView->Nodes->Item[0]->Nodes->Item[i]->NodeFont = new System::Drawing::Font(S"Arial", (float)myNodeFontSize); } // Get the bounds of the tree node. Rectangle myRectangle = myTreeView->SelectedNode->Bounds; int myNodeHeight = myRectangle.Height; if (myNodeHeight < myNodeFontSize) { myNodeHeight = myNodeFontSize; } myTreeView->ItemHeight = myNodeHeight + 4; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
TreeNode Class | TreeNode Members | System.Windows.Forms Namespace