How do I programatically select a Tab Page?

There are a couple of ways you could do select a tab page programmatically: [C#] //Select the second Tab Page this.tabControl.SelectedTab = this.tabPage2 or //Select Second Tab this.tabControl.SelectedIndex= 1; [VB.NET] ’Select the second Tab Page Me.tabControl.SelectedTab = Me.tabPage2 or ’Select Second Tab Me.tabControl.SelectedIndex= 1

How do I prevent a user from moving a form at run time?

The following code snippet (posted in the Windows Forms FAQ forums) shows how you can prevent a user from moving a form at run time: [C#] protected override void WndProc(ref Message m) { const int WM_NCLBUTTONDOWN = 161; const int WM_SYSCOMMAND = 274; const int HTCAPTION = 2; const int SC_MOVE = 61456; if((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE)) { return; } if((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION)) { return; } base.WndProc (ref m); } [VB.NET] Protected Overrides Sub WndProc(ByRef m As Message) const Integer WM_NCLBUTTONDOWN = 161 const Integer WM_SYSCOMMAND = 274 const Integer HTCAPTION = 2 const Integer SC_MOVE = 61456 If (m.Msg = WM_SYSCOMMAND) &&(m.WParam.ToInt32() = SC_MOVE) Then Return End If If (m.Msg = WM_NCLBUTTONDOWN) &&(m.WParam.ToInt32() = HTCAPTION) Then Return End If MyBase.WndProc( m) End Sub

How can I clone/copy all the nodes from one TreeView Control to another?

The following code snippet demonstrates how you can clone or copy all the nodes in TreeView1 to TreeView2 by clicking on Button1. [C#] private void IterateTreeNodes (TreeNode originalNode, TreeNode rootNode) { foreach( TreeNode childNode in originalNode.Nodes) { TreeNode newNode = new TreeNode(childNode.Text); newNode.Tag = childNode.Tag; this.treeView2.SelectedNode = rootNode; this.treeView2.SelectedNode.Nodes.Add(newNode); IterateTreeNodes(childNode, newNode); } } //Button Click code private void button1_Click(object sender, System.EventArgs e) { foreach( TreeNode originalNode in this.treeView1.Nodes) { TreeNode newNode = new TreeNode(originalNode.Text); newNode.Tag = originalNode.Tag; this.treeView2.Nodes.Add(newNode); IterateTreeNodes(originalNode, newNode); } } [VB.NET] Private Sub IterateTreeNodes(ByVal originalNode As TreeNode, ByVal rootNode As TreeNode) Dim childNode As TreeNode For Each childNode In originalNode.Nodes Dim NewNode As TreeNode = New TreeNode(childNode.Text) NewNode.Tag = childNode.Tag Me.treeView2.SelectedNode = rootNode Me.treeView2.SelectedNode.Nodes.Add(NewNode) IterateTreeNodes(childNode, NewNode) Next End Sub ’Button Click code Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim originalNode As TreeNode For Each originalNode In Me.treeView1.Nodes Dim NewNode As TreeNode = New TreeNode(originalNode.Text) NewNode.Tag = originalNode.Tag Me.treeView2.Nodes.Add(NewNode) IterateTreeNodes(originalNode, NewNode) Next End Sub