Getting error in implementing form resize in a winform app using krypton toolkit..

don bradman 621 Reputation points
2022-01-06T09:09:42.547+00:00

I have created a windows form application using Krypton toolkit Krypton which has its controls like combo box, datagridview, buttons etc. I basically want the controls to resize accordingly when the main form is resized so that no control gets hidden or unreadable etc.

using ComponentFactory.Krypton.Toolkit;
using System.Globalization;
using System.IO;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Wiz
{
 /// <summary>
 /// Description of MainForm.
 /// </summary>
 public partial class MainForm : KryptonForm
 {
 private float firstWidth;
 private float firstHeight;

 public MainForm()
 {

 InitializeComponent();

 }

 void KryptonButton4Click(object sender, EventArgs e)
 {
 Application.Exit();
 }
 void MainFormLoad(object sender, EventArgs e)
 {
 firstWidth = this.Size.Width;
 firstHeight = this.Size.Height;
 }
 void KryptonButton1Click(object sender, EventArgs e)
 {

 }
 void KryptonButton2Click(object sender, EventArgs e)
 {

 }
 void KryptonDataGridView1SelectionChanged(object sender, EventArgs e)
 {

 }
 void KryptonDataGridView2SelectionChanged(object sender, EventArgs e)
 {

 }
 void KryptonButton6Click(object sender, EventArgs e)
 {

 }
 void KryptonButton5Click(object sender, EventArgs e)
 {

 }
 void KryptonButton3Click(object sender, EventArgs e)
 {

 }

 private void MainForm_SizeChanged(object sender, EventArgs e)
 {
 float size1 = this.Size.Width /  firstWidth;
 float size2 = this.Size.Height / firstHeight;

 SizeF scale = new SizeF(size1, size2);
 firstWidth = this.Size.Width;
 firstHeight = this.Size.Height;

 foreach (Control control in this.Controls)
 {

 control.Font = new System.Drawing.Font(control.Font.FontFamily, control.Font.Size* ((size1+ size2)/2));

 control.Scale(scale);


 }

 }
 }
}

Now, when I run the app I get the below error:

************** Exception Text **************
System.ArgumentException: Value of 'Infinity' is not valid for 'emSize'. 'emSize' should be greater than 0 and less than or equal to System.Single.MaxValue.
Parameter name: emSize
   at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
   at System.Drawing.Font..ctor(FontFamily family, Single emSize)
   at Wizderm_Forwarding_New.MainForm.MainFormSizeChanged(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
   at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
   at System.Windows.Forms.Control.UpdateBounds()
   at System.Windows.Forms.Control.WmCreate(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmCreate(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at ComponentFactory.Krypton.Toolkit.VisualForm.WndProc(Message& m) in D:\Github\Krypton\Source\Krypton Components\ComponentFactory.Krypton.Toolkit\Controls Visuals\VisualForm.cs:line 1076
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I cannot figure out how to solve this. Can anyone help?

Developer technologies Windows Forms
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2022-01-07T01:36:44.307+00:00

    @don bradman , We noted that krypton toolkit is a 3rd party product and it is not supported in Micrsoft Q&A. You can ask the question in Github-issues

    0 comments No comments

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.