0

I have a visual studio 2005 form application. I also have created a header and source file with gets and sets and private variables for some of the data. How do I pass this data between forms? Ive looked at delegates but am having trouble understanding, is there another way, or some simple sample code on delegates if that is the only way? Thanks.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Radical Edward
0

Edward prefers to pass data between forms using properties. Delegates work more with behavior than data, so they probably aren't a good match for what you want to do, which is something like this very incomplete example:

ref class Form1: Form {
  int _data;
public:
  Form1()
  {
    _data = 123;
  }

  void Run()
  {
    Form2^ form = gcnew Form2();

    form->Data = _data;
    form->Run();
  }
};

ref class Form2: Form {
  int _data;
public:
  property int Data {
    int get() { return _data; }
    void set(int value) { _data = value; }
  }

  void Run()
  {
    MessageBox::Show(String::Format("{0}", _data));
  }
};
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.