Microsoft
Software
Hardware
Network
Question : How to Display a User Control on Form in CODE
I have created a user control and it is in my TOOLBOX.
I want to display the control at a certain location based on a tree view selection.
I will eventually have MANY user controls that will be displayed to the right of the tree view based on various selections...
How in code can I invoke a user control and display it at a particular location on a form?
This is what I have so far...there are no errors, but the control does not show.
Public Class frmMain
Inherits System.Windows.Forms.Form
'Global User Control
Dim ctrlProjectInfo As ctrlProjectInformation = New ctrlProjectInformation
#Region " Windows Form Designer generated code "
'*************************
********
'User want to exit the application
'*************************
********
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Application.Exit()
End Sub
'*************************
******
'User selects the tree view node
'*************************
******
Private Sub TreeView1_AfterSelect(ByVa
l sender As System.Object, ByVal e As System.Windows.Forms.TreeV
iewEventAr
gs) Handles TreeView1.AfterSelect
If TreeView1.SelectedNode.Tex
t = "Project Information" Then
ctrlProjectInfo.Show() <------------- WANT TO DISPLAY THE USER CONTROL
Else
< ----- WANT TO REMOVE THE USER CONTROL
End If
End Sub
'*************************
'To do when the form loads
'*************************
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ctrlProjectInfo.Location = New Point(248, 48) <------------ SET LOCATION
ComboBox1.SelectedIndex = 0
End Sub
End Class
Answer : How to Display a User Control on Form in CODE
Here's code that works for me:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyControl As New UserControl1
Me.Controls.Add(MyControl)
MyControl.Location = New Point(100, 100)
MyControl.Visible = True
End Sub
Random Solutions
Ms Access to SQL Server DSN or connection string
Deploy a change in registry in a terminal server farm
How would I extract one of each number in an excel column that contains many copies of hundreds of numbers?
reuse code ,forms from other database without copy
How do I reduce the memory iexplore.exe is using, as it can get as high as 260,000k
How to limit rows a user sees after logging to an APEX application
Outlook user can replay to internal email, but not send new email
OUTLOOK 2003 is not working with ISA 2006
Does anyone know of an Microsoft Access Documentation Program?
C# -- DataGridView "AuotSizing" HEIGHT ?