question

donbradman-4481 avatar image
2 Votes"
donbradman-4481 asked JackJJun-MSFT answered

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

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?

dotnet-csharpwindows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JackJJun-MSFT avatar image
0 Votes"
JackJJun-MSFT answered

@donbradman-4481, 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




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.