views:

155

answers:

6

Hey,

I need to create a user control in C#.Net, which can be added to the application without being visible - just like the FolderBrowserDialog. It's a new window which I'll be using often so I think this is the right way. The window will be opened by envoking the showDialog-Method as known from the other dialog.

Any Idea? Thanks and regards,

Daniel

+3  A: 

simply set Visible to false or isn't this what you're asking for ?

thelost
no, I need a control which can be added to a form application without having a real control which is added to the current form. Like the FolderBrowserDialog which is added at the bottom of the Visual Studio Window and which can be used as a normal object but without having any control added to the form by default.
dhh
+4  A: 

Since all these "invisible" controls derive from Component class, you should start by reading the MSDN article on it: http://msdn.microsoft.com/en-us/library/system.componentmodel.component.aspx.

Mikhail Orlov
Thanks for all your replies - I'll read more about components in general and then return to asking questions ;-)
dhh
+2  A: 

A UserControl is by definition not a Form; I think what you really want is a Component. That said, couldn't you really just create a new Form class that has the functionality you want? Whenever you want to display it, create a new instance and call ShowDialog. Or, if you want to preserve state, add an instance as a class member to your parent form, call its Show method whenever you want to display it, and add an event handler to its FormClosing event to check:

if (e.CloseReason == CloseReason.UserClosing)

and, if so,

e.Cancel = true;
Hide();

(This last part is to prevent errors if the user closes the form and then tries to display again after it's been disposed.)

Dan Tao
A: 

I think more information may be needed, but if your crating a custom user control, the control should have a .Visible property. The follow is an example of how a button can be located on the form but hidden from a user.

button.Visible = true;  // shows the button
button.Show(); // Shows the button
button.Visible = false; // hides the button
button.Hide(); // Hides the button

While the button may still be on the form/control, it will not be interactible by the user. You can still perform programmatic control on the button, but essentially it is not a user control while it is 'hidden'. If you want there to be a sort of hidden button that the user can click you will need to do other things to obtain this but It doesn't should like that is what you want.

galford13x
A: 
Jim McFetridge
A: 

You can put that control in a Panel. Set the panel height = 0 visible = false when you dont want to show the control. And do the vice versa when you want to show it.

Ram