Share via

Load chart into tabControl in Visual Basic .NET

José Carlos 886 Reputation points
2023-07-07T19:47:59.09+00:00

I have a form with a tabcontrol with two tabPage. Each tabPage has a graphic. I would like that as soon as I load the form, the tabPage1 graphic is loaded automatically.

In the code below, where would the error be, because it does not load graph 1 automatically. It only works if you click on tabPage2 and then go back to tabPage1. There the graph is drawn. I couldn't find the error.

Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
    If TabControl1.SelectedTab Is TabPage1 Then
        ' Load the graphic to TabPage1 tab
        LoadChart1()
    ElseIf TabControl1.SelectedTab Is TabPage2 Then
        ' Load the graphic to TabPage2 tab
        LoadChart2()
    End If
End Sub

Thanks

Developer technologies | VB
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.

0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2023-07-08T02:43:57.8+00:00

Try something like this:

Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load
    LoadCurrentChart()
End Sub

Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
    LoadCurrentChart()
End Sub

Sub LoadCurrentChart()
    If TabControl1.SelectedTab Is TabPage1 Then
        ' Load the graphic to TabPage1 tab
        LoadChart1()
    ElseIf TabControl1.SelectedTab Is TabPage2 Then
        ' Load the graphic to TabPage2 tab
        LoadChart2()
    End If
End Sub

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.