C# tutorial: Dictionary- Make controls fit to the form

Dictionary: Make controls fit to the form

Now if you maximize the form, the items are not smart enough to fit the form. What we want to talk in this page is to help you create a form that its items still stay fit with the form when it is resized for maximum state. To accomplish this task you need the following code that is applied to the Resize event of the form:

private void Dic_Resize(object sender, EventArgs e)
//Adjust listbox and textbox heights when the form resizes
//Dic dictionary = new Dic();

if (this.WindowState == FormWindowState.Maximized)
Lstterms.Height = this.Height;
Txtresult.Height = this.Height;
Txtresult.Width = this.Width ;


Note: If you try to resize the form and the code doesn't do its job you need to add another line of code(as shown below) to the form load event:

 private void Dic_Load(object sender, EventArgs e)
this.Resize+= new EventHandler(Dic_Resize); //add this code


In the next phase, we will talk about cleaning up the objects from the memory when the dictionary is closed.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.