C
C#•15mo ago
Austin9675

Using global variables

I have a quick question, say i have a variable named moneyOwed and i wanted to display that on any single page of the forms instead of being stuck to one page, how would i do that?
2 Replies
wwww
wwww•15mo ago
im not expert in winforms/wpf, but last time i built project usint it, sent data throught constructor. thats might not be se best way, but anyway 🙂 like
using (AddEditForm form = new AddEditForm(SelectById(id)))
{
DialogResult result = form.ShowDialog();
}
using (AddEditForm form = new AddEditForm(SelectById(id)))
{
DialogResult result = form.ShowDialog();
}
public partial class AddEditForm : Form
{
public Patient patient;
public AddEditForm(Patient patient)
{
InitializeComponent();
this.patient = patient;
}
}
public partial class AddEditForm : Form
{
public Patient patient;
public AddEditForm(Patient patient)
{
InitializeComponent();
this.patient = patient;
}
}
smthing like this, but i thinks this way is super bad, u can try it before someone who rly knows help 🙂
Mayor McCheese
Mayor McCheese•15mo ago
If it's winforms it's more complex, I'll try and write up an example in a bit here is a quick sample https://github.com/devdevdeveau/winforms-shared-data-sample it's a bit tightly coupled tbh; but for something simple it's fine.
Want results from more Discord servers?
Add your server