Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a TextBox control in groupbox1 and i want to change the location of the textbox from groupbox1 to groupbox2 in run time at a button click event in Windows Application
how could i do that???

please help
Posted
Updated 21-May-15 0:14am
v3
Comments
Andy Lanng 21-May-15 4:56am    
This is not advisable. ASP would not accept a form submission if the control tree has changed.

I suggest you create two textboxes and make Visible true or false for either at the same time. Visible="False" will mean that no html gets rendered but the control tree is unaffected.
If you need to copy over the text value then do that at the same time as you make their visibility swap
BIBASWAN 21-May-15 5:49am    
sir its not asp its windows application

1 solution

Assuming this is WinForms application (if is not then see the comment from Andy Lanng)

I created a form with two groupboxes, one button and placed a textbox in the first groupbox. All controls were left with their default names.

The following code moves the text box between the groupboxes on the button click
VB
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    If TextBox1.Parent Is GroupBox2 Then
        TextBox1.Parent = GroupBox1
    Else
        TextBox1.Parent = GroupBox2
    End If
End Sub

Note that the test has to use Is instead of = otherwise you will get a compile error
Quote:
Operator '=' is not defined for types 'System.Windows.Forms.Control' and 'System.Windows.Forms.GroupBox'.
 
Share this answer
 
Comments
BIBASWAN 21-May-15 5:50am    
thnx for the solution

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