Reputation: 215
I'm working on a Windows Forms applications, and thus far everything seems pretty simple. I currently have a form that takes some user input and displays it in graph in the current form.
I want to modify this application so that the main form only takes input, and after the "go" button is pressed, the taken data is graphed, but this time in a new form that should open up. If the user were to input some new info into the main form, then press "go" yet another form should pop up with the graph for the newly inputed data, and so on. So multiple forms with different graphs can be open at once.
I'm not sure how to modify my application to achieve this. I created a new form class and added a graph control and all other controls and design I want these new graph forms to have, but when I'm trying to plot the data from the original main form, I'm not sure how i can access the new graph form's graph control values... I set the modifiers to public, but I can't seem to get it to work.
Is there a way to more simply plot the data from one form into a new object of the graph form I created?
Upvotes: 3
Views: 3410
Reputation: 38079
Create a new Form to be your Graphing Form. Then add properties to that form that represent your data. You can even pass that data into the constructor of the form. For example, if I had a Graph Title and a list of integers for my graph data, my form might look like this:
public partial class GraphForm : Form
{
public string GraphTitle { get; set; }
public List<int> GraphData { get; set; }
public GraphForm(string graphTitle, List<int> graphData )
{
InitializeComponent();
GraphTitle = graphTitle;
GraphData = graphData;
}
private void GraphForm_Load(object sender, EventArgs e)
{
// Do the plotting here.
}
}
Now when the user clicks the Go
button, you can create a new form and pass in the data it needs at that time:
private void goButton_Click(object sender, EventArgs e)
{
GraphForm form = new GraphForm("Title", new List<int>() {1,2,3} );
form.Show();
}
Upvotes: 2