⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 网上流传的5个面试题目
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace DoubleWindows
{
	/// <summary>
	/// 一家日企的面试题目之四:
	/// 设计一个窗口A,在此窗口内按快捷键F1,弹出另外的窗口B,在B弹出后,两个窗
	/// 口要左右并排显示,并撑满整个屏幕;用鼠标拖动两个窗口相邻的边,两个窗口
	/// 的大小同时改变,且相对位置不变。再按F1,窗口B隐藏,窗口A最大化,如此重复。
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public MainForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Name = "MainForm";
			this.Text = "窗口A";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.DoubleWindowsForm_KeyDown);
			this.Resize += new System.EventHandler(this.MainForm_Resize);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new MainForm());
		}
		/// <summary>
		/// 副窗口的句柄。
		/// </summary>
		private ViceForm viceForm = null;

		
		public void DoubleWindowsForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			//当按下F1键时,打开或关闭副窗口,并设置两个窗口的大小。
			if (e.KeyCode == Keys.F1)
			{
				if (viceForm == null)
				{
					this.WindowState = FormWindowState.Normal;
					Rectangle rect = Screen.GetWorkingArea(this);
					this.Top = 0;
					this.Left = 0;
					this.Height = rect.Height;
					this.Width = rect.Width / 2;
					viceForm = new ViceForm(this);
					viceForm.Show();
				}
				else
				{
					this.WindowState = FormWindowState.Maximized;
					viceForm.Close();
					viceForm = null;
				}
			}
		}

		private void MainForm_Resize(object sender, System.EventArgs e)
		{
			//窗口大小发生变化时,调整窗口的大小。
			if (viceForm == null || !this.Focused)
				return;
			viceForm.Width += viceForm.Left - (this.Left + this.Width);
			viceForm.Left = this.Left + this.Width;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -