private void onTabChange(object sender, EventArgs e) { int tabIndex = graphTabControl.SelectedIndex; if (tabIndex < 0) { return; } GraphPanel gp = graphTabControl.TabPages[graphTabControl.SelectedIndex].Controls[0] as GraphPanel; Graph currentGraph = gp.Graph; app.SetCurrentGraph(currentGraph); selectedItemPropertyGrid.SelectedObject = currentGraph; gp.CurrentTool = currentTool; Console.WriteLine("Changed to " + currentGraph.Name); }