Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

VB.NET Help - Send Back Control To Main Form

I'm using this code to bring one control from form1 to form2:

Code
Me.Controls.Add(Form1.TabControl1)
    Me.Panel1.Size = Form1.TabControl1.Size

    Form1.TabControl1.SelectedTab.Show()

    Form1.TabControl1.Location = Me.Panel1.Location
    Panel1.Hide()

Everything is fine. But the problem is that the tabcontrol permanently disappeared from form1 and I can't send back the tabcontrol. Something like this will work:

Code
Form1.Controls.Add(Me.TabControl1)

But the problem is that the TabControl1 don't exist in form2 until I send it to it.

I don't ask to use the same tabcontrol at the same time on two different times. I just want to send it back to it's original form.

I know that is a variable that keeps track of that tabcontrol. It is form1.tabcontrol, even if it is actually moved to form2 and I tried this code: (But it also doesn't worked...)

Code
Form1.Controls.Add(Form1.TabControl1)

Please help me! :(
Just mirror the control on your second form and add a handler..

EG:

Form1.vb (One button)
Code
Public Class Form1
    Public Sub F2Button1_Click(sender As Object, e As EventArgs)
        Button1_Click(sender, e)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MsgBox("You clicked me!")
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Form2.Show()
    End Sub
End Class

Form2.vb (One button)
Code
Public Class Form2
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
        AddHandler Button1.Click, AddressOf Form1.F2Button1_Click
    End Sub
End Class
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]
(Nov 27, 2015 11:39 AM)Tedd Wrote:  Just mirror the control on your second form and add a handler..

EG:

Form1.vb (One button)
Code
Public Class Form1
    Public Sub F2Button1_Click(sender As Object, e As EventArgs)
        Button1_Click(sender, e)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MsgBox("You clicked me!")
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Form2.Show()
    End Sub
End Class

Form2.vb (One button)
Code
Public Class Form2
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
        AddHandler Button1.Click, AddressOf Form1.F2Button1_Click
    End Sub
End Class

This is not a bad idea. Thank you!

Also I found myself another better way to do it:

Code
Dim Formx As New Form1

I jost got everything from there and it worked like a charm. 🤝


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Ðr1psNov 9, 2015 03:56 PM 19 416 Nov 9, 2015 03:56 PM
Last Post: Ðr1ps
[C#] by ۤMD5Aug 31, 2015 05:52 AM 20 1,111 Aug 31, 2015 05:52 AM
Last Post: Mr Whiskey
[.NET] by xVipXMay 23, 2015 08:08 AM 4 191 May 23, 2015 08:08 AM
Last Post: xVipX