none
need to display groupbox from one form to another RRS feed

  • Question

  • i need to display groupbox of form5 in groupbox of form3 can i get a favour from anyone please!!! i have browsed  every where but i didn't get....please help me..please get me vb.net code for this problem
    • Edited by kavyajaikar Saturday, March 10, 2018 4:37 PM
    Saturday, March 10, 2018 4:36 PM

All replies

  • Can you explain why you want to do this? What is the intended effect in the program? Perhaps what you really need to do is create a custom user control and use two separate instances of it.

    You can move the groupbox from one form to another, but you have to take into consideration any code that works with the controls in that groupbox.  Moving the controls is one thing, but providing code to interact with them on both forms will require more work.

    Assuming Form3 has a reference to Form5 you can simply remove the groupbox from one control collection and add it to the other.

    Private Sub Form3_SomeEvent(sender As Object, e as EventArgs)
       Dim form5GroupBox = form5Instance.GroupBox1
       form5Instance.Controls.Remove(form5GroupBox )
       Me.GroupBox1.Controls.Add(form5GroupBox)
    End Sub


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Saturday, March 10, 2018 4:47 PM
    Moderator
  • Hi

    You will need a better explanation.Do you mean that you want to copy the controls inside a GroupBox on Form5  to a GroupBox on Form3?

    You do know that you can copy/paste controls in the Designer from one Form to another Form don't you?


    Regards Les, Livingston, Scotland

    Saturday, March 10, 2018 4:49 PM
  • EDIT: sorry Reed - didn't see your answer before posting this.

    Hi

    Here is an example of what you *may* be wanting.

    Here, Form2 contains a GroupBox with several controls in it. and Form1 has Button1 on it.

    Running the project opens both Forms, Form1 only has the Button on it and Form2 has the GroupBox1 containing controls.

    Click the Button on Form1 will copy the GrouoBox1 and all the contained controls from Form2 to Form1.

    Run

    After Click Button1

    Form1 code

    ' Form1 with Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	Dim f2 As New Form2
    	f2.Show()
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    	' copy GroupBox1 and all contained controls
    	' from Form2 to Form1
    	Controls.Add(New Form2().GroupBox1)
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    Saturday, March 10, 2018 5:19 PM
  • You can see, Karen made a message about forum etiquette. I've a long time not done it because it seemed pearls before swine. I see others now as well again to help to do it better. 

    Therefore, ask yourself why you use more forms, see you done that by others in this millennium (not about MDI of Dialogs). 

    Create one form with a tabpanel, a slider or even only panels which contains user controls which you show depending on the selection from the menu that is used. 

    A groupbox itself is only a reference and can be referenced from everywhere.  


    Success
    Cor

    Saturday, March 10, 2018 5:23 PM
  • @leshay:

    No worries :)


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Saturday, March 10, 2018 6:31 PM
    Moderator
  • Hello kavyaikar,

    Can you please describe what you want to achieve by splitting up controls between two forms? There may be a better course to take as pointed out by Cor by utilizing TabControl, a TableLayoutPanel or a SplitContainer in tangent with a TabControl or a TableLayoutPanel.

    In addition if you are dealing with data from a database include this information also.

    Thanks


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, March 10, 2018 6:39 PM
    Moderator
  • Are you saying you want a GroupBox on Form5 that has the same controls as a GroupBox on Form3 to follow whatever the controls in a GroupBox on Form3 do and Vice Versa (the controls in a GroupBox on Form3 follow whatever the controls in a GroupBox on Form5 do)?

    Or what exactly is it you want to occur?


    La vida loca

    Sunday, March 11, 2018 11:52 AM