99. 콤보박스(ComboBox)와 리스트박스(LIstBox)
.NET프로그래밍/WinForm 2009. 8. 24. 10:36 |
==> MainForm.cs
private void miComboListBox_Click(object sender, EventArgs e)
{
MyWinForms.Controls.FrmComboListBox clb = new MyWinForms.Controls.FrmComboListBox();
clb.MdiParent = this;
clb.Show();
}
==============================================================================================
==> FrmComboListBox.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 FrmComboListBox : Form
{
public FrmComboListBox()
{
InitializeComponent();
}
private void FrmComboListBox_Load(object sender, EventArgs e)
{
// 동적으로 아이콘의 종류를 리스트박스에 초기화
lstIcon.Items.Add(MessageBoxIcon.Error.ToString());
lstIcon.Items.Add(MessageBoxIcon.Information.ToString());
lstIcon.Items.Add(MessageBoxIcon.Question.ToString());
lstIcon.Items.Add(MessageBoxIcon.Warning.ToString());
}
private void btnOK_Click(object sender, EventArgs e)
{
if (lstButton.SelectedIndex != -1 && lstIcon.SelectedIndex != -1)
{
string btn = lstButton.Items[lstButton.SelectedIndex].ToString();
string icon = lstIcon.Items[lstIcon.SelectedIndex].ToString();
// Process
MessageBox.Show(
String.Format("버튼 : {0}, 아이콘 : {1}", btn, icon));
}
else
{
DialogResult result = MessageBox.Show(
"콤보박스와 리스트박스를 선택하시오."
,"제목"
, MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
{
lblResult.Text = "확인 클릭";
}
else if (result == DialogResult.Cancel)
{
lblResult.Text = "취소 클릭";
}
}
}
}
}
< 실행결과 >
==> 콤보박스와 리스트박스 둘 중 하나라도 선택되지 않은 후 확인버튼을 눌렀을 때 화면
==> 바로 위에서 확인 또는 취소버튼을 누르면 폼 왼쪽 아래쪽에 "확인 클릭" 또는 "취소 클릭" 텍스트가 나온다.
==> 콤보박스와 리스트박스 둘 다 선택한 후 확인버튼을 눌렀을 때의 화면
'.NET프로그래밍 > WinForm' 카테고리의 다른 글
101. DialogResult (부모폼과 자식폼의 값 전달) (0) | 2009.08.24 |
---|---|
100. 그룹박스(GrouBox) (0) | 2009.08.24 |
98. 메시지박스(MessageBox) (0) | 2009.08.24 |
97. 링크레이블(LinkLabel) (0) | 2009.08.24 |
96. 마스크(Mask) / 리치(Rich) / 읽기전용(ReadOnly) 텍스트박스(TextBox) (0) | 2009.08.24 |