In the .Net framework, I am using a large panel in Form1. In this panel, I call up Form3 and in this Form3, I have created a chart control function. How is it that the chart, which has been placed and sized as desired, is visible during testing but not in

Dinant Baan 20 Reputation points
2024-05-02T23:33:52.27+00:00

code

form3test1

first picture = code

second = form3

third = Test run

what i try to do is in Form1, add a panel, and in that panel ill switch forms 2,3 and 4 with buttons
and in form3 i call Control Chart and use enough space as in picture 2

and i must say all is generated bij ChatGPT and Bing Copilot Ai but i hit a roadblock to solve this

does Anyone hit this roadblock to and how to solve this problem?

thnx in advantage Dinant

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,903 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,921 questions
{count} votes

Accepted answer
  1. Hui Liu-MSFT 48,571 Reputation points Microsoft Vendor
    2024-05-03T05:24:10.7666667+00:00

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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