we've encountered a small issue while using the LightningChart library. Some googling brought me the answer, and i would like to share this with you.
The scenario is as following:
We have 2 forms. Form 1 contains a button, which opens form 2. Form 2 has a plain LightningChart on it. From the viewmodel (MVP) a Font is set to the y-axis of the chart.
When closing the 2nd form, and reopening again from form 1, an error occurs, see the end of the post. It seems the Chart is disposing the Font, which though is still used in our ViewModel.
Once we open the form 2 for the second time and try to set the Font, it is disposed (probably this happens in the chart dispose somewhere), and the error occurs.
Hereby some code we have isolated in a seperated project:
- a new Font is declared in form 1 as following;
Code: Select all
Font = new Font("Segoe UI", 8f, FontStyle.Regular);
- the font from form 1 is used for the y-axis of the chart and set as following:
Code: Select all
Chart.ViewXY.YAxes[0].LabelsFont = Form1.Font;
Code: Select all
Chart.ViewXY.YAxes[0].LabelsFont = Form1.Font.Clone();
Hereby the error which occurs when setting the disposed font to the y-axis:
Code: Select all
at System.Drawing.Font.GetHeight(Graphics graphics)
at System.Drawing.Font.GetHeight()
at System.Drawing.Font.get_Height()
at Arction.WinForms.Charting.Axes.AxisY.DOC(Boolean A)
at Arction.WinForms.Charting.Axes.AxisBase.set_LabelsFont(Font value)
at WindowsFormsAppArctionTryout.Form2.SetFont(Font font) in c:\users\rribbe\source\repos\WindowsFormsAppArctionTryout\WindowsFormsAppArctionTryout\Form2.cs:line 25
at WindowsFormsAppArctionTryout.Form1.buttonOpenForm2_Click(Object sender, EventArgs e) in c:\users\rribbe\source\repos\WindowsFormsAppArctionTryout\WindowsFormsAppArctionTryout\Form1.cs:line 33
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsAppArctionTryout.Program.Main() in c:\users\rribbe\source\repos\WindowsFormsAppArctionTryout\WindowsFormsAppArctionTryout\Program.cs:line 19