-
Jun 22nd, 2018, 09:07 AM
#1
Thread Starter
Member
[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
-
Jun 22nd, 2018, 09:08 AM
#2
Thread Starter
Member
Re: [Quick Question] Making controls appear in all forms
tldr;
I want to move controls between two forms.
-
Jun 22nd, 2018, 09:14 AM
#3
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
-
Jun 22nd, 2018, 09:26 AM
#4
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.
-
Jun 22nd, 2018, 09:42 AM
#5
Thread Starter
Member
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!
-
Jun 22nd, 2018, 09:56 AM
#6
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.
-
Jun 22nd, 2018, 10:00 AM
#7
Thread Starter
Member
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
-
Jun 22nd, 2018, 10:13 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|