Controls in C#winform program are proportionally zoomed (mainly for the main program to load subprograms)

        The proportional scaling here applies to the loading of multiple sub-forms in the main form, or a main program references another sub-program dll, such proportional scaling, which is not proportional in the actual sense, but is equivalent to re- Load the subform, but the data in the subform cannot be changed.

        The main form and sub-form loading are not introduced, but the dll of the main program loading sub-program is directly introduced. The main form and the sub-form are similar.

        First create a main program. The main program is treated as a shell. Simply put a few containers in it. I will put a panel here and set the Dock of the panel to Fill.

       

        Create a subroutine. The subroutine can create a class library program, and the generated is a dll. The subroutine can be added with some controls at will, mainly to make the main program call and load into the main program, and the window will be maximized in the load event. In order to achieve the so-called proportional zoom, the Dock event of the control in the subform is modified, and the anchor is used for anchoring, the subform is loaded in singleton mode here.

public partial class SubForm : Form
	{
		public static SubForm subForm;

		public static SubForm GetInstance()
		{
			if(subForm == null || subForm.IsDisposed)
			{
				subForm = new SubForm();
			}
			return subForm;
		}

		private SubForm()
		{
			InitializeComponent();
		}

		private void SubForm_Load(object sender, EventArgs e)
		{
			this.WindowState = FormWindowState.Maximized;
		}
	}

        Generate the subroutine, then put the dll in the subroutine into the bin directory of the main program, and then load the subroutine in the load event of the main program:

private void Form1_Load(object sender, EventArgs e)
		{
			SubForm subForm = SubForm.GetInstance();
			subForm.FormBorderStyle = FormBorderStyle.None;
			subForm.TopLevel = false;
			subForm.Parent = null;
			subForm.Parent = panel1;
			subForm.Dock = DockStyle.Fill;
			subForm.Show();
		}

        Earlier, a panel container was added to the main program window. To achieve proportional scaling, load the subprogram in the sizeChanged event of the panel:

private void panel1_SizeChanged(object sender, EventArgs e)
		{
			SubForm subForm = SubForm.GetInstance();
			subForm.FormBorderStyle = FormBorderStyle.None;
			subForm.TopLevel = false;
			subForm.Parent = null;
			subForm.Parent = panel1;
			subForm.Dock = DockStyle.Fill;
			subForm.Show();
		}

        Start the program, you can achieve the scaling, there should be other methods, but this method can be used at present, other methods have not been studied yet.

Guess you like

Origin blog.csdn.net/qq_41061437/article/details/108865916