Question

I am creating a windows form application in C# and I have two forms. The main form where the user is going to be working with a graph and another form that contains: series appearance options, axes options, label options, etc... This form appears when the "Tool" button is pressed. From there I intend to let the user modify their graph as they wish. My question is- Is it faster/better to populate the second form when the first form loads or initializes, or should it just do that when the "Tool" button is pressed.

Was it helpful?

Solution

This question is about a difference between eager loading (load data as soon as possible) and lazy loading (load data when it is necessary). I think the decision here should come down to user experience. If the data takes a little while to load and your users will be accessing the properties window frequently then I would suggest eager loading. If on the other hand the loading is quick or this is a feature that is going to be infrequent then I would suggest lazy loading. So, you need to figure out what your users expect. But, if the data for the screen loads quickly then it hardly matters what you load when.

I would also suggest that you rethink your properties window, especially if it is going to be used frequently. The paradigm for this kind of user interface has been to embed a PropertyGrid into the same application window where the bulk of the work is done. Think about Visual Studio for many, many examples and just about any IDE-style application. They do not tend to have "floating" properties windows. The paradigm is that you show the properties of whatever object is currently selected in the IDE to allow quick and easy modification. The separate Tools | Options paradigm is more for application-level settings that are modified much less frequently and are tied to the app at large rather than particular objects that the application manages. Again, Visual Studio is a good example.

OTHER TIPS

In my opinion, it would be better to make a new instance of the second form when you click on the appropriate button. I would think that you should only allocate the memory for the form when you need it.

However, if your forms are quick to load, it should not matter from a user standpoint, as long as you hide the second form until the button is clicked.

Creating several forms at startup isn't very scalable. When you have 20-30 forms it will takes ages to load! Create them as and when they're needed.

// button event in your first form (Form1)
private void firstButton_Click(object sender, EventArgs e)
{
    Form2 form2 = new Form2();
    form2.ShowDialog(); // Shows Form2
}

Should be used, since you might not need the button at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top