Problem in the size of the form and controls at the time of execution

I have created a form in the form of image 1, but at the time of execution, the distance between the controls increases and the size of the form also increases. What is the problem?
Image 2 is at runtime.

I have also used TableLayoutPanel to place the controls in the form and the sizes are according to picture 3.

I have used the Telerik (Version 2023.1.117) library.

What should I do so that the size of the form and the distance of the controls and the size of the controls are the same as the Design environment?

Image1:

enter image description here

Image2:

enter image description here

Image3:

enter image description here

public BaseForm()
{
   InitializeComponent();
   ThemeName = "Fluent";     
   Font = new Font("IRANSans", 15 , GraphicsUnit.Pixel);
   AutoScaleMode = AutoScaleMode.Inherit;
   FormBorderStyle = FormBorderStyle.FixedDialog;
   MaximizeBox = false;
   StartPosition = FormStartPosition.CenterScreen;
   AutoSizeMode = AutoSizeMode.GrowAndShrink;
   Width = 477;
   Height = 418;
}

  • Problems might be. Looking at a different desktop zoom at runtime then at design time. So you might have ignored that a desktop may have its individual zoom setting different from 100% and your setting in the forms constructor isn’t presumably used. The designer executes/changes the InitializeComponent and ignores the things you do in the constructor. And additionally at runtime the things you did in the constructor will be overriden by the stuff in InitializeCompoment. Doing some things in the designer and some things in code will get you in trouble (atleast in getting the design correct).

    – 




  • I put these form settings after InitializeComponent(); I have put it, but the distances are still the same.@Ralf

    – 

  • Your application is not DPiAware, so you’re most probably targeting .NET Framework. See How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)? and High DPI support in Windows Forms — If you have never handled a DpiAware application, as Visual Studio suggests with the usual warning banner, design your app at 100% scale — Note that VS has options to scale its UI Font, too, in case it gets too small for you

    – 




Leave a Comment