Hi,@Dinant Baan. Welcome to Microsoft Q&A.
As Viorel said, remove the chart control in the Form3 designer. Only create the control in the Form3_Load event you post. I tested the following example and it works great.
Form1.vb.design: There is a panel and two buttons to swap Form2 and Form3 for testing.
Form1.vb:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim form2 As New Form2()
form2.TopLevel = False
form2.FormBorderStyle = FormBorderStyle.None
form2.Dock = DockStyle.Fill
Panel1.Controls.Clear()
Panel1.Controls.Add(form2)
form2.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim form3 As New Form3()
form3.TopLevel = False
form3.FormBorderStyle = FormBorderStyle.None
form3.Dock = DockStyle.Fill
Panel1.Controls.Clear()
Panel1.Controls.Add(form3)
form3.Show()
End Sub
End Class
Form3.vb.design: There is no control.
Form3.vb:
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form3
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim chart1 As New Chart()
chart1.Size = New Size(500, 250)
chart1.Dock = DockStyle.Right
Me.Controls.Add(chart1)
Dim chartArea1 As New ChartArea()
chart1.ChartAreas.Add(chartArea1)
Dim Winst As New Series()
Winst.Name = "Winst"
Winst.ChartType = SeriesChartType.StackedColumn
Winst.Color = Color.Blue
Winst.Points.AddXY(1, 100)
Winst.Points.AddXY(2, 200)
Winst.Points.AddXY(3, 150)
Winst.Points.AddXY(4, 300)
chart1.Series.Add(Winst)
Dim Verlies As New Series()
Verlies.Name = "Verlies"
Verlies.ChartType = SeriesChartType.StackedColumn
Verlies.Color = Color.Red
Verlies.Points.AddXY(1, 120)
Verlies.Points.AddXY(2, 250)
Verlies.Points.AddXY(3, 300)
Verlies.Points.AddXY(4, 350)
chart1.Series.Add(Verlies)
chart1.Titles.Add("Lijingrafiek")
chart1.ChartAreas(0).AxisX.Title = "X-as"
chart1.ChartAreas(0).AxisY.Title = "Y-as"
chartArea1.AxisX.Title = "Categorieen"
chartArea1.AxisY.Title = "Waarden"
End Sub
End Class
If you still have questions, please feel free to share with us more details and steps to reproduce the issue.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.