Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i have created a window form using c#. now the issue that i am facing is that i cannot clear the form.
for instance suppose that my form initially consists of a text box and a submit button. next what
i want to do is that hen the user types a text and presses the submit button. i want the text box and submit button to get cleared and instead another button containing the text submitted to be created.
is it possible to do so? if yes what functions do i have to make use of?
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jul-11 1:22am    
What does it mean "submit button to get cleared"? How come it was dirty?
--SA

If you want another form, then create another form and show it from the first form.

If you need a wizard, then put a panel inside the main form for the content. In that panel, dynamically add an user control for the current page. When the next page need to be displayed remove the existing user control from the panel and add a user control for the next page.

If this is too complicate for you, then uses a tab control instead where each tab represent a page or find a third party tab control/wizard component.

For very simple cases, you might also simply put all controls on the form and adjust the visibility of controls.

This could be combined with layout containers (flow layout or table layout) to make it easier to design it as you would see all controls at design. If table layout is used for that purpose the rows or columns containing items to hide should be autosized.
 
Share this answer
 
Thank you for the replies friend. i have found the solution.
philippe i do not want to make any more new forms. and textbox.clear works for only text boxes. i needed to remove all objects from a form.
to do so i used arrays of different objects to keep account of them. later i used Controls.Remove() to remove elements.

thank you.
 
Share this answer
 
Comments
johannesnestler 18-Jul-11 11:27am    
Just some thoughts:
Maybe this works for you. It's ok to add and remove Controls on the fly (just bad perfomance if you overdo it). But for the requirement you gave us, it sounds strange. Why not just make the "result" Button (???) visible on submit and do the opposite for a "re-submit". If your form realy works in "multiple mode" (or how you would call it :-) - reconsider your design. Maybe you should split functionality in two forms (a submit form, and a result form).
What's wrong with TexBox.Clear? Difficult to look at its help http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.aspx[^]?

Many other controls have something like that, but for a button is sounds absurd.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900