?? mainform.cs
字號(hào):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DoubleWindows
{
/// <summary>
/// 一家日企的面試題目之四:
/// 設(shè)計(jì)一個(gè)窗口A,在此窗口內(nèi)按快捷鍵F1,彈出另外的窗口B,在B彈出后,兩個(gè)窗
/// 口要左右并排顯示,并撐滿整個(gè)屏幕;用鼠標(biāo)拖動(dòng)兩個(gè)窗口相鄰的邊,兩個(gè)窗口
/// 的大小同時(shí)改變,且相對(duì)位置不變。再按F1,窗口B隱藏,窗口A最大化,如此重復(fù)。
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
/// 必需的設(shè)計(jì)器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public MainForm()
{
//
// Windows 窗體設(shè)計(jì)器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設(shè)計(jì)器生成的代碼
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </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>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </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)
{
//當(dāng)按下F1鍵時(shí),打開或關(guān)閉副窗口,并設(shè)置兩個(gè)窗口的大小。
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)
{
//窗口大小發(fā)生變化時(shí),調(diào)整窗口的大小。
if (viceForm == null || !this.Focused)
return;
viceForm.Width += viceForm.Left - (this.Left + this.Width);
viceForm.Left = this.Left + this.Width;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -