92. MenuStrip / ContextMenuStrip / StatusStrip / 모달 폼 / 모달리스 폼
==> Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace MyWinForms
{
static class Program
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
==============================================================================================
==> MainForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyWinForms
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void 끝내기ToolStripMenuItem_Click(object sender, EventArgs e)
{
// 현재 프로그램 종료
Application.Exit();
}
private void miAbout_Click(object sender, EventArgs e)
{
// 모달 폼 : 현재 창을 닫아야지만, 메인으로 이동 가능
FrmAbout fa = new FrmAbout();
fa.ShowDialog();
}
private void miButton_Click(object sender, EventArgs e)
{
// 모달리스 폼 : 독립적인 하나의 폼
MyWinForms.Controls.FrmButton fb = new MyWinForms.Controls.FrmButton();
fb.MdiParent = this; // MDI 컨테이너를 현재 폼(메인)으로 설정
fb.Show();
}
private void mnuHelp_Load(object sender, EventArgs e)
{
}
#region 컨텍스트메뉴
private void cmsAbout_Click(object sender, EventArgs e)
{
//FrmAbout fa = new FrmAbout();
//fa.ShowDailog();
miAbout_Click(null, null); // 재 사용
}
private void cmsExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
#endregion
}
}
==============================================================================================
==> FrmAbout.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyWinForms
{
public partial class FrmAbout : Form
{
public FrmAbout()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
// 현재 폼 닫기
this.Close();
}
private void lblTitle_Click(object sender, EventArgs e)
{
}
}
}
==============================================================================================
==> FrmButton.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyWinForms.Controls
{
public partial class FrmButton : Form
{
public FrmButton()
{
InitializeComponent();
}
}
}
< 실행결과 >
==> 모달 폼
==> 모달리스 폼
==> 컨텍스트메뉴