Adding Controls At Run-Time [Win #C]

  • Thread starter Thread starter MikeY
  • Start date Start date
M

MikeY

Hi everyone,

I have built a user control "keyboard" and I am trying to figure a way to
add this control at run-time. I have also tried creating a Inherited user
control, which I am able to add this to my form at run-time, but does not
have the functionality of passing the data back to the main form, ie: data
from the keys being pressed (delegate) or being able to close this control
and getting rid of it after it is no longer needed.

my Code that I've been working with is as follows:

HOST.I_Ctrl_KeyBoard myKeyBoard= new HOST.I_Ctrl_KeyBoard();
myKeyBoard.Location = new System.Drawing.Point(275, 305);

myKeyBoard.Parent = this;
myKeyBoard.BringToFront();
myKeyBoard.Show();

Does anyone have a sample syntax or suggestions, tips, links, etc. Anything
is appreciated.

Thanks,

MikeY
 
You need to add the Control to the Controls Collection of whatever Control
you want to host it in, even if that is just the Form itself.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.
 
HOST.I_Ctrl_KeyBoard myKeyBoard= new HOST.I_Ctrl_KeyBoard();
myKeyBoard.Location = new System.Drawing.Point(275, 305);

myKeyBoard.Parent = this;
myKeyBoard.BringToFront();
myKeyBoard.Show();

If this is to be a control on the form you need:
this.Controls.Add ( myKeyBoard) ;
 
Back
Top