How to easily save configuration information such as the position and size of the WinForm control, winform Control

Source: Internet
Author: User

How to easily save configuration information such as the position and size of the WinForm control, winform Control

Because of the different resolutions, screen themes, and font sizes, the display effects of forms vary with machines. The elastic design of forms does not meet various requirements. To ensure satisfactory results in various situations. The various display modes of the form can be changed, and it is very important to save and load the configuration. I tried to write a class under C # To Do This. The purpose is to make it easy to use, as small as possible, load fast, and scalable.

First use:

This class is applicable to the most common requirements, such as the form position and size. And the column width of the table. Design. You can expand it as needed.

Load the configuration information as follows:

private void FrmMain_Load(object sender, EventArgs e){  SetupColumns();   oConfig.Load_Columns_Width(dgv1, "huodan_frmlisthuo_dgv1");  oConfig.SetSaveFlag("huodan_frmlisthuo_dgv1", false);   oConfig.Load_Form_Size(this, "huodan_frmlisthuo_frm");  oConfig.SetSaveFlag("huodan_frmlisthuo_frm", false);}

Save it before closing the form:

private void FrmListHuo_FormClosing(object sender, FormClosingEventArgs e){   oConfig.Save_Columns_Width(dgv1, "huodan_frmlisthuo_dgv1");   oConfig.Save_Form_Size(this, "huodan_frmlisthuo_frm"); }

Not every time the form is closed, it is saved. If necessary, set the Save request:

private void dgv1_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e){ oConfig.SetSaveFlag("huodan_frmlisthuo_dgv1",true);}private void FrmListHuo_ResizeEnd(object sender, EventArgs e){ oConfig.SetSaveFlag("huodan_frmlisthuo_frm", true);}

  

Class content can be downloaded to the blog space (http://www.pudn.com/downloads768/sourcecode/windows/csharp/detail3046853.html), don't speak more, understand Don't speak, don't understand is tired.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.