ComponentFactory / Krypton

Krypton WinForms components for .NET
BSD 3-Clause "New" or "Revised" License
1.86k stars 681 forks source link

Form resize not working properly #230

Open DonB007 opened 2 years ago

DonB007 commented 2 years ago

I have created a windows form application using Krypton toolkit 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 { ///

/// Description of MainForm. /// 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)` How to solve this?