Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows Programming(7)_Controls 1 Standard Controls  Label/LinkLabel  TextBox  Button  Panel / Group Box  CheckBox, Radio Button  List Box, ComboBox.

Similar presentations


Presentation on theme: "Windows Programming(7)_Controls 1 Standard Controls  Label/LinkLabel  TextBox  Button  Panel / Group Box  CheckBox, Radio Button  List Box, ComboBox."— Presentation transcript:

1 Windows Programming(7)_Controls 1 Standard Controls  Label/LinkLabel  TextBox  Button  Panel / Group Box  CheckBox, Radio Button  List Box, ComboBox

2 Windows Programming(7)_Controls 2 Label  고정된 텍스트를 표시  Image 속성을 사용하여 이미지를 표시  네임스페이스 : System.Windows.Forms  어셈블리 : System.Windows.Forms(system.windows.forms.dll)  상속 계층 구조 System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.Label System.Windows.Forms.LinkLabel  주요속성 Text : 레이블의 텍스트 TextAlign : 레이블에서의 텍스트 맞춤 (ContentAlignment.BottomCenter/BottomLeft /BottomRight..) Image : Label 에 표시되는 이미지 BorderStyle : 컨트롤의 테두리 스타일을 (BorderStyle.Fixed3D/FixedSingle/None) Cursor : 마우스 포인터가 컨트롤 위에 있을 때 표시되는 커서 설정

3 Windows Programming(7)_Controls 3 //Label 사용 예 //Label 생성 System.Windows.Forms.Label labelText = new System.Windows.Forms.Label(); System.Windows.Forms.Label labelImage = new System.Windows.Forms.Label(); //labelText 속성설정 ( 테두리, 배경색, 중앙정렬 ) labelText.BackColor = System.Drawing.Color.Yellow; labelText.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; labelText.Name = "labelText"; labelText.Size = new System.Drawing.Size(116, 44); labelText.Text = "label 컨트롤을 확인하는 문서입니다."; labelText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; //labelImage 속성설정 ( 커서모양, 이미지연결 ) labelImage.Cursor = System.Windows.Forms.Cursors.Hand; labelImage.Image = ((System.Drawing.Image)(resources.GetObject("labelImage.Image"))); labelImage.Location = new System.Drawing.Point(25, 82); labelImage.Name = "labelImage"; labelImage.Size = new System.Drawing.Size(102, 46); labelImage.Text = "labelImage"; //labelImage Click 이벤트핸들러 등록 labelImage.Click += new System.EventHandler(labelImage_Click);

4 Windows Programming(7)_Controls 4 LinkLabel  하이퍼링크를 표시할 수 있는 label  LinkArea, Links 속성으로 링크 표시  LinkClicked 이벤트로 링크에 대한 처리  사용 예 LinkLabel linkLabel1 = new LinkLabel() ; linkLabel1.Text = " 새로운폼으로 이동합니다."; linkLabel1.AutoSize = true; // 라벨의 텍스트에서 링크로 처리할 영역 지정 (0 위치에서 크기 4 영역 ) linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(0, 4); // 링크를 클릭했을 때 처리할 이벤트 핸들러 등록 linkLabel1.LinkClicked += new inkLabelLinkClickedEventHandler( linkLabel1_LinkClicked);

5 Windows Programming(7)_Controls 5 // 웹 페이지 링크 사용 예 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { VisitLink(); } catch (Exception ex ) { MessageBox.Show("Unable to open link that was clicked."); } private void VisitLink() { // Change the color of the link text by setting LinkVisited to true. linkLabel1.LinkVisited = true; //Call the Process.Start method to open the default browser with a URL: System.Diagnostics.Process.Start("http://www.microsoft.com"); }

6 Windows Programming(7)_Controls 6 TextBox  텍스트를 입력하고 표시하는 데 사용되는 컨트롤  상속 계층 구조 System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.TextBoxBase System.Windows.Forms.TextBox  주요속성 ReadOnly : true 로 하여 출력전용으로 사용 Multiline,ScrollBars : 여러 줄의 텍스트를 표시하거나 입력 MaxLength : TextBox 에 입력되는 텍스트의 길이를 제한 PasswordChar: 입력문자 표시를 숨김 CharacterCasing : Normal/Upper/Lower 속성값으로 대문자 또는 소문자로 선택 가능 AcceptsTab, AcceptsReturn : 제어키 사용여부  주요이벤트 TextChanged : 사용자가 키를 누를 때마다 발생

7 Windows Programming(7)_Controls 7 //TextBox 사용 예 System.Windows.Forms.TextBox textBox1 = new TextBox(); System.Windows.Forms.TextBox textBox2 = new TextBox(); System.Windows.Forms.TextBox textBox3 = new TextBox(); // textBox1 속성설정 ( single line, 폰트변경, 대문자로 입력 ) textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; textBox1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; textBox1.Font = new System.Drawing.Font(" 굴림 ", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); textBox1.Text = "SINGLE LINE"; textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // textBox2 속성설정 (multi line, backcolor, scrollbar) textBox2.BackColor = System.Drawing.SystemColors.InactiveCaptionText; textBox2.BorderStyle = System.Windows.Forms.BorderStyle.None; textBox2.Multiline = true; textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; textBox2.Text = "multiple line1\r\nmultiple line2\r\nmultiple line3\r\nmultiple line4\r\nmultiple line5"; // textBox3 속성설정 (passwordchar, 최대길이 ) textBox3.MaxLength = 8; textBox3.PasswordChar = '?'; textBox3.TextChanged += new System.EventHandler( textBox3_TextChanged);

8 Windows Programming(7)_Controls 8 Button  사용자로부터 특정 동작을 수행하도록 하는 컨트롤  단추에 포커스가 있는 경우 마우스, Enter 키 또는 스페이스바를 사용 하여 클릭가능  상속 계층 구조 System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ButtonBase System.Windows.Forms.Button  주요이벤트 Click : 사용자가 버튼을 누를 때 발생

9 Windows Programming(7)_Controls 9  주요속성 FlatStyle: 단추의 모양을 변경  Standard : 표준버튼 모양  System : 시스템 버튼 모양  FlatStyle.Flat: 웹 형태의 평면 모양  FlatStyle.Popup : 평면 모양으로 표시되다가 마우스 포인터가 단추 위로 이 동하면 표준 Windows 단추 모양으로 변경  사용예 : btnNewForm.FlatStyle = System.Windows.Forms.FlatStyle.Flat; Parent : 컨트롤의 부모 컨테이너를 가져오거나 설정 FindForm() : 컨트롤이 들어 있는 폼을 검색 Control p = btnParent.Parent; Form f = btnParent.FindForm();

10 Windows Programming(7)_Controls 10 컨트롤의 마우스 이벤트 발생순서  MouseEnter : 마우스 포인터가 컨트롤에 들어가면 발생  MouseMove : 마우스 포인터를 컨트롤 위로 이동하면 발생  MouseHover : 마우스 포인터가 컨트롤 위에 있을 때 발생  MouseDown : 마우스 포인터가 컨트롤 위에 있을 때 마우스 단추를 클릭하 면 발생  MouseWheel : 컨트롤에 포커스가 있을 때 마우스 휠을 움직이면 발생  MouseUp : 마우스 포인터가 컨트롤 위에 있을 때 마우스 단추를 눌렀다 놓 으면 발생  MouseLeave : 마우스 포인터가 컨트롤을 벗어나면 발생

11 Windows Programming(7)_Controls 11 btnParent = new System.Windows.Forms.Button(); btnStyle = new System.Windows.Forms.Button(); btnMouse = new System.Windows.Forms.Button(); // btnStyle 속성설정 ( 배경색, FlatStyle) btnStyle.BackColor = System.Drawing.SystemColors.ButtonShadow; btnStyle.FlatStyle = System.Windows.Forms.FlatStyle.Flat; btnStyle.Text = "FlatStyle"; btnStyle.Click += new System.EventHandler(btnStyle_Click); // btnParent 속성설정 (FlatStyle) btnParent.FlatStyle = System.Windows.Forms.FlatStyle.Popup; btnParent.Text = "PopupStyle"; btnParent.Click += new System.EventHandler(btnParent _Click); // btnMouse 이벤트 핸들러 등록 btnMouse.FlatStyle = System.Windows.Forms.FlatStyle.Flat; btnMouse.Text = "MouseEvent"; btnMouse.MouseLeave += new System.EventHandler( btnMouse_MouseLeave); btnMouse.MouseEnter += new System.EventHandler( btnMouse_MouseEnter);

12 Windows Programming(7)_Controls 12 private void btnStyle_Click(object sender, EventArgs e){ Form1 f = new Form1(); f.ShowDialog(); } private void btnParent_Click(object sender, EventArgs e){ Control p = btnParent.Parent; MessageBox.Show("Parent Type = " + p.GetType() + ", Parent Text = " + p.Text, "btnParent_Click"); } // 마우스포인터가 컨트롤 내에 들어올 때 발생되는 이벤트 처리 private void btnMouse_MouseEnter(object sender, EventArgs e) { Button b = (Button)sender; btncolor = btnMouse.BackColor; b.BackColor = System.Drawing.Color.AliceBlue; } // 마우스포인터가 컨트롤을 벗어날 때 발생되는 이벤트 처리 private void btnMouse_MouseLeave(object sender, EventArgs e) { Button b = (Button)sender; b.BackColor = btncolor ; }

13 Windows Programming(7)_Controls 13 GroupBox  폼에 배치된 컨트롤들을 그룹화하기 위해 사용  관련 있는 컨트롤들을 기능별로 분류하여 시각적으로 표현할 때 사 용  라디오버튼 그룹화에 이용  컨트롤 그룹생성방법 폼에 GroupBox 컨트롤을 배치 그룹 내에 포함할 컨트롤들을 그룹 상자 안에 배치 기존 컨트롤을 그룹 상자에 포함하려면 포함할 모든 컨트롤을 선택하여 클립보드에 잘라 낸 다음 GroupBox 컨트롤을 선택하여 그룹 상자에 붙 여 넣기 또는 그룹 상자에 끌어 오기 그룹 상자의 Text 속성에 적절한 캡션을 설정

14 Windows Programming(7)_Controls 14 /* 실행 중에 GroupBox 를 생성 및 초기화하고 2 개의 라디오버튼을 추가, 그룹박스를 폼의 컨트롤 에 등록 */ private void InitializeMyGroupBox() { GroupBox groupBox1 = new GroupBox(); // 그룹박스 생성 RadioButton radioButton1 = new RadioButton(); // 라디오 버튼 생성 RadioButton radioButton2 = new RadioButton(); // Set the FlatStyle of the GroupBox. groupBox1.FlatStyle = FlatStyle.System; // Add the RadioButtons to the GroupBox. groupBox1.Controls.Add(radioButton1); groupBox1.Controls.Add(radioButton2); // Add the GroupBox to the Form. Controls.Add(groupBox1); }

15 Windows Programming(7)_Controls 15 Panel  컨트롤 그룹화에 이용되는 컨트롤  상속구조 System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ScrollableControl System.Windows.Forms.Panel  ScrollableControl 클래스에서 파생되므로 AutoScroll 속성을 사용하여 Panel 컨트롤에서 스크롤 막대 활성화  캡션지정 을 위한 Text 속성이 없으므로 캡션기능이 필요한 그룹설정 시 GroupBox 컨트롤 사용

16 Windows Programming(7)_Controls 16 //panel 사용 예 System.Windows.Forms.Panel panel1; System.Windows.Forms.Label label1; System.Windows.Forms.Button btnPanel; System.Windows.Forms.CheckBox checkBox4; System.Windows.Forms.CheckBox checkBox5; panel1 = new System.Windows.Forms.Panel(); label1 = new System.Windows.Forms.Label(); btnPanel = new System.Windows.Forms.Button(); checkBox4 = new System.Windows.Forms.CheckBox(); checkBox5 = new System.Windows.Forms.CheckBox(); label1.Text = "label in Panel"; btnPanel.Text = "button In Panel"; btnPanel.Click += new System.EventHandler(this.btnPanel_Click); //panel1 속성 설정 ( 자동스크롤 속성 ) panel1.AutoScroll = true; //panel1 에 그룹화할 컨트롤 추가 panel1.Controls.Add(this.label1); panel1.Controls.Add(this.button1); panel1.Controls.Add(this.checkBox4); panel1.Controls.Add(this.checkBox5); //Panel 내의 모든 컨트롤 확인 void btnPanel_Click(object sender, EventArgs e){ Panel p = ( Panel)btnPanel.Parent; string controls = ""; foreach (Control ct in p.Controls) { controls += ct.Text + ";"; } MessageBox.Show(controls, “Controls in Panel"); }

17 Windows Programming(7)_Controls 17 CheckBox  여러 개의 확인란을 선택할 수 있는 컨트롤  상속구조 System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ButtonBase System.Windows.Forms.CheckBox  주요속성 Appearance : CheckBox 를 일반적인 CheckBox 로 표시할지 또는 단추 모양으로 표시할지 여부를 결정 Checked : true/false CheckState : Checked/ Indeterminate/Unchecked  주요 이벤트 Click : 컨트롤을 클릭하면 Checked 속성이 true 로 설정되고 Click 이벤트 처리 CheckedChanged : Checked 속성의 값이 변경되면 CheckedChanged 이벤트 발 생

18 Windows Programming(7)_Controls 18 //CheckBox 사용 예 System.Windows.Forms.CheckBox checkBox1; System.Windows.Forms.CheckBox checkBox2; System.Windows.Forms.CheckBox checkBox3; checkBox1 = new System.Windows.Forms.CheckBox(); checkBox2 = new System.Windows.Forms.CheckBox(); checkBox3 = new System.Windows.Forms.CheckBox(); // checkBox1 this.checkBox1.Checked = true; this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; // 체크상태 설정 this.checkBox1.Text = "checkBox1"; this.checkBox1.UseVisualStyleBackColor = true; this.checkBox1.CheckedChanged += new System.EventHandler(checkBox_CheckedChanged); // checkBox2 this.checkBox2.Text = "checkBox2"; this.checkBox2.CheckedChanged += new System.EventHandler(checkBox_CheckedChanged); // checkBox3 this.checkBox3.Text = "checkBox3"; this.checkBox3.CheckedChanged += new System.EventHandler(checkBox_CheckedChanged);

19 Windows Programming(7)_Controls 19 //checkBox 이벤트처리 예 private void checkBox_CheckedChanged(object sender, EventArgs e) { CheckBox cb = (CheckBox) sender; MessageBox.Show(cb.Text + ":"+ cb.CheckState, "CheckedChanged Event"); } private void btnCB_Click(object sender, EventArgs e) { string msg=""; foreach (Control ct in gbCheck.Controls ){ CheckBox cb = ct as CheckBox; if (cb != null && cb.Checked == true) msg += cb.Text+";"; } MessageBox.Show(msg, "Checked"); }

20 Windows Programming(7)_Controls 20 Radio Button  사용자가 선택 그룹에서 단일 옵션을 선택해야 할 경우에 사용  주요속성 Checked : true/false CheckState : Checked/ Unchecked AutoCheck : 속성이 true( 기본값 ) 로 설정된 라디오 단추를 선택하면 해 당 그룹의 다른 모든 선택 표시가 자동으로 제거 Text : 라디오버튼의 설명 및 선택키를 표시기능  선택키 : 앰퍼샌드 (&) 와 문자의 조합으로 설정하면 실행 시 Alt 키와 함께 눌러 click 기능 수행  주요이벤트 Click : Checked 속성이 true 로 설정되고 Click 이벤트 처리기가 호출 CheckedChanged : Checked 속성의 값이 변경될 때 발생

21 Windows Programming(7)_Controls 21 //RadioButton 사용 예 System.Windows.Forms.RadioButton radioButton1; System.Windows.Forms.RadioButton radioButton2; System.Windows.Forms.RadioButton radioButton3; // radioButton1 radioButton1.Checked = true; // 초기 체크상태 radioButton1.Text = "radioButton1(&A)“; // 선택키 설정 (Alt+A) // 클릭이벤트 처리기 등록 radioButton1.Click += new System.EventHandler(this.radioButton_Click); // radioButton2 radioButton2.Text = "radioButton2(&B)"; radioButton2.Click += new System.EventHandler(this.radioButton_Click); // radioButton3 radioButton3.Text = "radioButton3(&C)"; radioButton3.Click += new System.EventHandler(this.radioButton_Click); // RadioButton click 이벤트 처리 private void radioButton_Click(object sender, EventArgs e) { RadioButton rb = (RadioButton)sender; MessageBox.Show(rb.Text, "RadioButton Click"); }

22 Windows Programming(7)_Controls 22 ListBox  다수의 항목에서 선택할 수 있는 항목 목록을 표시하는 기 능 ( 단일, 다중 선택 가능 )  상속계층구조 System.Object System.MarshalByRefObject System.ComponentModel.Component System.Windows.Forms.Control System.Windows.Forms.ListControl System.Windows.Forms.ListBox System.Windows.Forms.CheckedListBox

23 Windows Programming(7)_Controls 23  주요속성 SelectionMode : 단일 또는 다중 선택 옵션 MultiColumn : ListBox 의 항목들을 열 형식으로 표시여부 Items : ListBox 의 항목들에 대한 컬렉션  컬렉션의 Add(), AddRange(), Insert(), Remove(), Clear() 등의 메서드로 항목을 추가, 제거 SelectedItem : 현재 선택된 항목의 텍스트 ( 선택된 항목이 없는 경우 null ) SelectedIndex : 현재 선택된 항목의 인덱스 ( 선택된 항목이 없는 경우 –1 ) SelectedItems : 다중 선택된 항목들에 대한 컬렉션 SelectedIndices : 다중 선택된 항목들에 대한 인덱스들에 대한 컬렉션 Sorted : 목록의 내용을 알파벳 순서대로 정렬 선택모드 설명 MultiExtended 여러 항목을 선택할 수 있으며 Shift, Ctrl 및 화살표 키를 사용하여 선택가능 MultiSimple 여러 항목 선택가능 None 항목 선택 불가능 One 단일 선택

24 Windows Programming(7)_Controls 24  주요메서드 public void SetSelected ( int index, bool value )  ListBox 의 지정된 항목을 선택하거나 선택 취소. public bool GetSelected ( int index )  지정된 항목이 선택되어 있는지 여부를 나타내는 값을 반환 public int FindString ( string s ) public int FindString ( string s, int startIndex ) FindStringExact() :  ListBox 에 포함된 항목 검색  주요이벤트 Click : 항목을 클릭할 때 발생 DoubleClick : 항목을 더블 클릭할 때 발생 SelectedValueChanged  ListBox 의 항목선택을 변경하면 SelectedValue 속성이 변경되고 SelectedValueChanged 이벤트 발생 SelectedIndexChanged:  SelectedIndex 속성이 변경될 때 발생  ListBox 의 선택된 인덱스가 변경된 시기를 확인

25 Windows Programming(7)_Controls 25 //ListBox 사용 예 System.Windows.Forms.ListBox listBox1; System.Windows.Forms.ListBox listBox2; // listBox1 // 디자인타임에서 추가된 항목들 listBox1.Items.AddRange(new object[] { " 가을 ", " 겨울 ", " 봄 ", " 여름 "}); listBox1.Sorted = true; // 정렬 // 선택항목이 변경될 때 처리할 이벤트 핸들러 등록 listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); // listBox2 listBox2.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; // 다중선택 // 항목을 더블 클릭할 때 처리할 이벤트 핸들러 등록 listBox2.DoubleClick += new System.EventHandler(this.listBox2_DoubleClick); // 폼이 로드될 때 리스트에 항목 추가 void ListForm_Load(object sender, EventArgs e) { for (int i = 1; i <= 10; i++) { string item = " 항목 " + i; listBox2.Items.Add(item); } } //listBox1 의 항목 선택위치가 변경되면 선택된 항목을 확인 void listBox1_SelectedValueChanged(object sender, EventArgs e) { if (listBox1.SelectedItem != null) MessageBox.Show(listBox1.SelectedItem.ToString(), "SelectedValueChanged");} //listBox2 의 항목을 더블 클릭하면 선택된 항목을 삭제 void listBox2_DoubleClick(object sender, EventArgs e) { listBox2.Items.Remove(listBox2.SelectedItem);} // 선택된 항목을 삭제

26 Windows Programming(7)_Controls 26 // 선택된 항목 확인 private void btnSelected_Click(object sender, EventArgs e) { string list1 = "listBox1 : "; // 단일선택 string list2 = "listBox2 : "; // 다중선택 if (listBox1.SelectedItem != null) list1 += listBox1.SelectedItem.ToString(); foreach (object item in listBox2.SelectedItems) list2 += item.ToString() + " "; MessageBox.Show(list1 + "\n\r" + list2, "Selected Item"); } // 선택 설정 private void btnSelect_Click(object sender, EventArgs e){ listBox1.SetSelected(1, true); // 두번째 선택 listBox2.SetSelected(0, true); // 첫번째 선택 listBox2.SetSelected(3, true); // 네번째 선택 } // 선택취소 private void btnCancel_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex != -1) listBox1.SetSelected(listBox1.SelectedIndex, false); // 선택된 위치를 찾아서 선택취소 for (int i = 0; i < listBox2.Items.Count; i++) // 모든 항목에서 선택된 항목에 대해서만 선택취소 { if (listBox2.GetSelected(i)) // 선택된 항목을 검색 listBox2.SetSelected(i, false); }

27 Windows Programming(7)_Controls 27 // 새로운 항목 추가 void btnAdd_Click(object sender, EventArgs e) { listBox1.Items.Add(" 추가항목 "); } // 새로운 항목 삽입 void button2_Click(object sender, EventArgs e) { if (listBox2.Items.Count > 2) listBox2.Items.Insert(1, " 삽입항목 "); } // 선택추가, listBox2 의 선택된 항목을 listBox1 에 추가 void btnSelAdd_Click(object sender, EventArgs e) { // 선택된 항목들을 얻기 ListBox.SelectedObjectCollection list2Items = listBox2.SelectedItems; // 선택된 항목들의 개수만큼의 크기로 배열 생성 object[] addItems = new object[list2Items.Count]; // 배열로 선택된 항목들을 복사 list2Items.CopyTo(addItems, 0); // 배열을 listBox1 의 항목으로 추가 listBox1.Items.AddRange(addItems); }

28 Windows Programming(7)_Controls 28 // 항목 삭제, 항목을 찾아서 삭제, 특정 항목 삭제 private void btnDel_Click(object sender, EventArgs e) { int idx = listBox1.FindString(" 추가항목 "); if (idx != -1) listBox1.Items.RemoveAt(idx); //” 추가항목 ” 의 위치를 찾아서 삭제 listBox1.Items.Remove(" 삽입항목 "); //" 삽입항목 " 문자열을 가지는 항목 삭제 } //listBox1 의 항목을 전체 삭제 private void btnClear_Click(object sender, EventArgs e) { listBox1.Items.Clear(); }

29 Windows Programming(7)_Controls 29 ComboBox  목록선택과 텍스트 편집기능을 포함한 형태 (ListBox+ TextBox)  주요속성 ComboBoxStyle SelectedIndex, SelectedItem : 선택된 항목의 위치, 항목 확인 및 설정 ComboboxStyle 설명 DropDown 텍스트 부분 편집 가능, 화살표 단추 클릭으로 목록 부분 표시 ( 기본 스타일 ) DropDownList 텍스트 부분을 직접 편집 불가능, 화살표 단추 클릭으로 목록 부 분 표시 Simple 텍스트 부분 편집가능, 전체 목록 표시

30 Windows Programming(7)_Controls 30  주요이벤트 TextChanged  Text 속성 값이 변경되면 발생  리스트의 항목을 선택하거나 텍스트필드에 값을 입력할 때 발생 SelectedIndexChanged  SelectedIndex 속성이 변경될 때 발생 SelectedValueChanged  SelectedValue 속성이 변경되면 발생 SelectionChangeCommitted  선택된 항목이 변경되고 해당 변경 내용이 ComboBox 에 표시될 때 발생

31 Windows Programming(7)_Controls 31 //ComboBox 사용 예 System.Windows.Forms.ComboBox comboBox1; // comboBox1 comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); comboBox1.TextChanged += new System.EventHandler(this.comboBox1_TextChanged); private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { txtOut.Text = comboBox1.SelectedItem + "(" + comboBox1.SelectedIndex + ")"; } private void comboBox1_TextChanged(object sender, EventArgs e) { txtOut.Text = comboBox1.Text; } private void btnAdd_Click(object sender, EventArgs e) { comboBox1.Items.Add(txtIn.Text); } private void ComboBoxForm_Load(object sender, EventArgs e) { System.Object[] ItemObject = new System.Object[10]; for (int i = 0; i <= 9; i++) { ItemObject[i] = "Item" + i; } comboBox1.Items.AddRange(ItemObject); }

32 Windows Programming(7)_Controls 32 연습문제  회원등록 프로그램 작성 등록버튼 : 입력된 항목을 문자열로 결합 하여 리스트에 추가 조회버튼 : 성명을 조회하여 리스트의 해 당위치를 선택 삭제버튼 : 리스트에 선택된 항목을 삭제


Download ppt "Windows Programming(7)_Controls 1 Standard Controls  Label/LinkLabel  TextBox  Button  Panel / Group Box  CheckBox, Radio Button  List Box, ComboBox."

Similar presentations


Ads by Google