User Control

  • Thread starter Thread starter Martin Hills
  • Start date Start date
M

Martin Hills

Hi again

I have added a user control to a form but don't want it
to run until a user clicks a button. Is this possible
and if so how?

Esentially the aim is to have buttons on the screen and
each button should load a different control. I need to
be able to change from one control at run time and also
close a control when told by the user.

Hope this makes sense and someone can help.

Regards

Martin
 
Martin Hills said:
I have added a user control to a form but don't want it
to run until a user clicks a button. Is this possible
and if so how?

What does "run" a control mean?
Esentially the aim is to have buttons on the screen and
each button should load a different control. I need to
be able to change from one control at run time and also
close a control when told by the user.

Hope this makes sense and someone can help.

I might make sense, but what is your question?
 
Armin Zingler said:
I might make sense, but what is your question?

I should have written:
Is the problem
- to handle an event or
- to create a control or
- to remove it or
- to handle it's events?
 
Are you saying that you don't want it to appear until the user clicks the
button? That's what I'm guessing.

If so, go ahead and place it at design time--but set the visible & enabled
properties to false. Then in the button.onlick event:

myControl.visible = true <=your control will now show up
myControl.enabled = true <=your control will now be enabled here

Just make sure that space is provided for the control.
 
Martin,

This is one way, duplicate for total number of user controls:

Dim objInventoryControl As New InventoryCtl

Private Sub ButtonInventory_Click.........

'remove any existing controls
ClearControls()

'set start up conditions of user control
With objInventoryControl
.Location = New System.Drawing.Point(6, 6)
.Name = "MachineAdd"
.Size = New System.Drawing.Size(Me.Width - 20, Me.Height - 80)
.LabelMachine.Text = ""
.ComboBox1.Visible = False
.LabelModel.Visible = True
.TextBoxModel.Visible = True
.ButtonSave.Text = "SAVE"
.ButtonSave.Enabled = True
'load any start up data
.setStart()
End With
Me.Controls.Add(objInventoryControl)

Me.Refresh()

end sub


Try to reuse controls as much as possible(this one serves three user functions)

Regards

 
Back
Top