C
C#2y ago
Whiteboy

How do i pass data from one form to another?

eg. i want to click a button in form1 then be able to form2 and see the image of picturebox changed to the one i've chosen
18 Replies
RubyNovaDev
RubyNovaDev2y ago
assuming Form1 knows about Form2 that's easy just set a property on the instance of Form2 from Form1 or pass it in via a method
Whiteboy
Whiteboy2y ago
it's like i have one main form like main menu then 3 forms which have reference of Mainmenu and i want the data from form1 to form2 not from main menu D:
Buddy
Buddy2y ago
Keep the data unaware of the forms, that way you have more control over it.
RubyNovaDev
RubyNovaDev2y ago
ehhh
Buddy
Buddy2y ago
meaning, don't store the data within the forms
RubyNovaDev
RubyNovaDev2y ago
I don't see how this changes anything I just said you can just pass it along like I assume there's some relationship here that'll allow you to pass the information around so fundamentally its just a case of adding APIs that let you do that
Whiteboy
Whiteboy2y ago
im too green for this i guess
Whiteboy
Whiteboy2y ago
RubyNovaDev
RubyNovaDev2y ago
nah you're just overthinking it
Whiteboy
Whiteboy2y ago
Whiteboy
Whiteboy2y ago
and there is the picture box i want to take image from form1 there when i click that button
RubyNovaDev
RubyNovaDev2y ago
how are you getting from one form to the other can't read code in images so you're gonna have to help
Whiteboy
Whiteboy2y ago
i click these buttons on the left
RubyNovaDev
RubyNovaDev2y ago
in code where
Whiteboy
Whiteboy2y ago
private void OpenChildForm(Form childForm, object btnSender)
{
_activeForm?.Close();

_activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
this.panelDesktop.Controls.Add(childForm);
this.panelDesktop.Tag = childForm;
childForm.BringToFront();
childForm.Show();
}
private void OpenChildForm(Form childForm, object btnSender)
{
_activeForm?.Close();

_activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
this.panelDesktop.Controls.Add(childForm);
this.panelDesktop.Tag = childForm;
childForm.BringToFront();
childForm.Show();
}
RubyNovaDev
RubyNovaDev2y ago
so you have the child form you already change stuff on it when the button is clicked from what you're showing me here just give it the image as well? like this looks to only take the base type so obv you're gonna need to do it at a point where you know what form it is you're working with but the gist is the same literally you can just be like
ItemUpgradeMenu menu = new();
menu.PictureOfItem = MyPictureBox.Whatever;
ItemUpgradeMenu menu = new();
menu.PictureOfItem = MyPictureBox.Whatever;
and you done you just need to expose something on your item upgrade menu for taking the picture and then pass it along
Whiteboy
Whiteboy2y ago
okay i'll try this
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts