+ 1
Passing array to anothe form
Public struct pesanan { Public string nama Public int harga } Public static pesanan[ ] p = new pesanan[0] Btn1_click { Array.resize(ref p, p.count() + 1) P[p.getupperbound(0)].nama = txtnama1.text P[p.getupperbound(0)].harga = txtharga1.text for (int i = 0; i <= p.GetUpperBound(0); i++) { lstpesanan.Items.Add(p[i].nama.PadRight(50 - p[i].nama.Length) + p[i].harga.ToString("Rp #,##0.00").PadRight(15) + p[i].qty.ToString().PadRight(5) + p[i].total.ToString() } } How to passing this value to label in another form? Please help me I'm using c# winform
3 ответов
+ 2
In addition to John.
Please have a look a this link.
https://www.codeproject.com/Articles/14122/Passing-Data-Between-Forms
Option 1 is the option that John suggest.
Option 2 is very bad software design please do not use it.
Option 3 is a really good option
Option 4 is a good option more advanced though.
+ 1
To pass data to the other form you need to create an instance of it in the class that will invoke it. You then create a constructor that takes the array in the form that you want to pass the data to and have that constructor update a property in the new form. if you are updating a control in the new form you will want to ensure that its a thread safe operation. You can google "Updating control in windows forms thread safe (or wpf)". hope this helps!