[C++]LAB-13 การเพิ่ม combobox ใน dialog base appication

       แลปที่13นี้จะสร้างโปรแกรม ที่มีการทำงานโดย ให้เรากรอกข้อความลงไปในeditbox หลังจากนั้นกด  ปุ่มbuton Add String ข้อความจะไปถูกเก็บที่ combobox หลังจากเราเลือกข้อความใน combobox แล้วข้อความจะปรากฏที่บริเวณ static text เหมือนกับที่เลือกใน combobox ดังภาพด้านล่าง


  • กรอกข้อความและกดปุ่มAdd String----->ข้อความจะไปอยู่ในcombobox


  • เลือกข้อความที่อยู่ในcombobox-------->จะแสดงข้อความที่static textเหมือนที่เลือกในcombobox

void CLAB13Dlg::OnBnClickedButtonAdd()
{
 // TODO: Add your control notification handler code here
 CString srcText;
 m_editSource.GetWindowText(srcText); //getข้อความจาก editbox
 m_comboBox1.AddString(srcText);   //addข้อความที่getไว้ลงไปใน combobox
}


void CLAB13Dlg::OnCbnSelchangeCombo1()
{
 CString str;
 int idx = m_comboBox1.GetCurSel();  //นำข้อความที่เลือกมาจากcomboboxมาเก็บไว้ที่idx
 if(idx<0)
  return;
 m_comboBox1.GetLBText(idx , str);  //get idx ไปเก็บไว้ที่ str
 m_staticDestination.SetWindowText(str); //ปริ้นstrลง static text

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

VISITOR