Hi everybody
Following C# program I obtained from a website. What is the significant of the following 4 codes. That means if I comment out this codes program is working well. Please anybody explain.
//this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
//this.ClientSize = new System.Drawing.Size(292, 273);
//this.MaximumSize=new Size(300,300);
//this.MinimumSize=new Size(300,300);
Thank you
using
System;using
System.Drawing;using
System.Collections;using
System.ComponentModel;using
System.Windows.Forms;using
System.Data;public
class Form1 : System.Windows.Forms.Form{
private Button myButton;
public Form1()
{
//this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
//this.ClientSize = new System.Drawing.Size(292, 273);
//this.MaximumSize=new Size(300,300);
//this.MinimumSize=new Size(300,300);
myButton = new Button();
myButton.Text = "www.java2s.com";
myButton.Location = new System.Drawing.Point(64, 32);
myButton.Size = new System.Drawing.Size(150, 50);
Controls.Add(myButton);
}
static void Main()
{
Application.Run(new Form1());
}
}
Posted Apr 9, 2007, 7:36 PM
Maha
Do you know the reason why without these steps program is compiling and executing well.
SimonPosted Apr 9, 2007, 7:19 PM
Firstly, this.MaximumSize is used to set the maximum size of the form, so if you try to resize the form during runtime, you won't be able to make it bigger than 300x300 pixels. Then you have this.MinimumSize which serves the same purpose, but set the minimum form size that you can achieve when resizing it, so 300x300 pixels also in this case. In this case, since your MinimumSize and MaximumSize are the same, your form can't be resized at runtime. On the other hand, this.AutoScaleBaseSize is used for backward compatibility and, as described by MSDN, was used to make controls/text appear correctly on different machines configurations. MSDN defines it as such : "Automatic scaling enables a form and its controls, designed on one machine with a certain display resolution or system font, to be displayed appropriately on another machine with a different display resolution or system font. It assures that the form and its controls will intelligently resize to be consistent with native windows and other applications on both the users' and other developers' machines. The support of the .NET Framework for automatic scaling and visual styles enables .NET Framework applications to maintain a consistent look and feel when compared to native Windows applications on each user's machine." Finally, this.ClientSize is used to set the client size of the form, which is by default the bounds of the form, minus the nonclient elements such as scroll bars, borders, title bars and menus. It is usually automatically set when resizing a form. Hope this helps! SimonPosted Apr 9, 2007, 4:36 PM
Of cause there is no error in the program. It is compiling and executing well. But I couldn’t understand importance of following 4 steps in the program. Because without these steps program is compiling and executing well. If you know please explain.
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.MaximumSize = new Size(300,300);
this.MinimumSize = new Size(300,300);
SimonPosted Apr 9, 2007, 3:06 PM