0

I have two form: Form1 and Form2. Both of it already have data.

  • After I scan barcode in Form1, Form1 will be hidden, Form2 will show and somethings.

  • After Form2 finish, Form1 will show again and Form2 will be hidden.

It's cycle.

I tried with:

///In Form1
Frm2 Form2 = new Frm2();
Form2.show();
this.Hide();

///In Form2
Frm1 Form1 = new Frm1();
Form1.show();
this.Hide();

But I think it make a new form with no data. So, how can I unhide form1 in form2?

MrAngel
  • 3
  • 3
  • 3
    You're creating new instances of both `Frm1` and `Frm2` every time, do this only once. Also how are you calling this code, please update your post to include further details about implementation. Also FWIW take a look at [Application.OpenForms Property](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.openforms?view=net-5.0) which will return all of the opened forms owned by your application. – Trevor May 11 '21 at 13:36
  • Use Form1.Visible = true (or false). – jdweng May 11 '21 at 13:43
  • You have to add a property on each form to keep a reference of the other Form and call Show on the property instead of creating a new Form (as you do). Using Application.OpenForms could help you too as said by Codexer. – Marco Guignard May 11 '21 at 14:50
  • Does this helps? https://stackoverflow.com/questions/3005732/showing-a-hidden-form – amitklein May 11 '21 at 16:25
  • @amitklein thanks god. Love you <3 – MrAngel May 12 '21 at 13:30
  • but how can we call one hidden form from other form. It's mean: call form1 show from form 2? – MrAngel May 12 '21 at 13:35
  • Why do you need to hide and not close it? if you need some data you can pass it through – amitklein May 12 '21 at 17:58
  • @amitklein i only want unhide it again. after this.hide(). But from other form – MrAngel May 14 '21 at 02:11
  • Oh, yeah, my bad, to call is just pass the instance of the class (form) to the second form and use it there – amitklein May 14 '21 at 07:48
  • @amitklein can you give code for example. I'm beginer. – MrAngel May 16 '21 at 10:11
  • This should help you https://www.c-sharpcorner.com/UploadFile/834980/how-to-pass-data-from-one-form-to-other-form-in-windows-form/ – amitklein May 16 '21 at 20:24
  • @amitklein it can transfer data beetween form. I think my situation very difference. It's raise oen action from other form – MrAngel May 19 '21 at 08:41

0 Answers0