Introduction
The post explains how to share and exchange data between two or more Forms in Window Forms Application.
Background
When I began to use the C# programming language, I encountered some problems with data share in different Forms. I had tried to use text file, *.ini file and XML file, but as you know, it is inefficient to access the disk frequently. So I attempted other methods. This is why I wrote this post.
Using the Code
The code in this article was developed in C# using Visual Studio 2010 Ultimate.
The main code snippet is as follows:
FormMainFrame m_formMainFrame;
m_formMainFrame = (FormMainFrame)Application.OpenForms[0];
if (m_formMainFrame.Form2 != null)
{
MessageBox.Show(m_formMainFrame.Form2.LabelTest.Text);
}
History
- 4th March, 2013: Initial version