Results 1 to 8 of 8

Thread: [RESOLVED] [Quick Question] Making controls appear in all forms

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    34

    Resolved [RESOLVED] [Quick Question] Making controls appear in all forms

    Hi,
    I have 2 controls in Menu.vb (First Form).
    In my project, there's a button where I can switch between forms.
    In the Game.vb (Second Form) code, I wanna move those controls to Game.vb (Second Form).
    Thanks

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    34

    Re: [Quick Question] Making controls appear in all forms

    tldr;
    I want to move controls between two forms.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: [Quick Question] Making controls appear in all forms

    You can't.

    Actually, you can, but don't. A control is just an object, so you could technically pass one from one form to another, but controls are a bit odd. For one thing, they have LOTS of events, and you may well be handling some of them, especially since they are buttons. The controls are also found in Controls collections of something on each form. So, to move the controls, you'd have to unhook the event handlers (or else the original form would STILL handle the events, even though the control was now in the other form), remove the controls from whichever Controls collection they were in, then put them in the right Controls collection of the new form, and hook up new event handlers. That's a whole lot of work that could go wrong, and for what?

    It would be far easier to have different controls on each form and leave them there. Just pass any data from one to the other.
    My usual boring signature: Nothing

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: [Quick Question] Making controls appear in all forms

    I agree with Shaggy that what you're suggesting is a bad idea. If you explain why you think it's a good idea, we can probably tell you what you should be doing instead.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    34

    Re: [Quick Question] Making controls appear in all forms

    Yeah, I'm pretty new in VB, so I don't really know what to do.
    Here's a better explanation to my situation:
    A) There're 2 forms: MainMenu and Game.
    B) The User changes the image of the characters.
    C) The User switches to the second Form (Game).
    D) Then I want the characters to appear in the second form with the changes made to them (Same picture/skin).

    Here's a gif explanation: Click me!

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: [Quick Question] Making controls appear in all forms

    So basically you just want the same images to appear in two forms. An Image is not even a control, so there's no issue. You just need to add a PictureBox control to each form and then load both of them with the same data. Exactly how you do that depends on the specifics. If you're using a file, you could just assign the path of that file to the ImageLocation property of both PictureBoxes. If you already have an Image object in the first form then you can pass that to the second form and assign it to the Image property of both PictureBoxes.

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    34

    Re: [Quick Question] Making controls appear in all forms

    "If you already have an Image object in the first form then you can pass that to the second form and assign it to the Image property of both PictureBoxes."
    I don't really know how to pass data between two forms...
    Could you give me a code example please?
    Sorry, but as I said, I'm pretty new

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: [Quick Question] Making controls appear in all forms

    It just so happens that there's a link in my signature below to a three-part blog post I made on the subject.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width