請問Edit Control的問題?

sheuchorngren 2009-09-09 04:09:25
不好意思!我是新手!

Q1.請問如何在Edit Control預覽Combo box/Listbox已點選部份?

MSDN我是線上查詢....已知好像使用SetCurSel()的函數,取得listbox項目,但是是用SetDlgItemText在Edit顯示?

抱歉,因為我還只會把Edit Box的值顯示在listbox...

Q2.請問如何在Edit Control預覽Radio box已點選部份?
...全文
255 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sheuchorngren 2009-09-14
  • 打赏
  • 举报
回复
請問
雖然我已經用OnBnClickedRadio(Radio點擊事件)處理1個Radio Button,
但是如果有六個以上就很麻煩了
請問是否有更好的解決方式?

//預覽Radio Button→Static(其中1個)
void CCtestDlg::OnBnClickedRadioXX()
{
// TODO: 在此加入控制項告知處理常式程式碼
((CButton *)GetDlgItem(IDC_RADIOXX))->GetCheck();
m_staticXX.SetWindowText("文字");//編輯框中顯示列表框選中內容
}

原來參考之前問的checkbox的問題,發現無法應用於radio button...
=====================

虽然我已经用OnBnClickedRadio(Radio点击事件)处理1个Radio Button,
但是如果有六个以上就很麻烦了
请问是否有更好的解决方式?

//预览Radio Button→Static(其中1个)
void CCtestDlg::OnBnClickedRadioXX()
{
// TODO: 在此加入控制项告知处理常式程式码
((CButton *)GetDlgItem(IDC_RADIOXX))->GetCheck();
m_staticXX.SetWindowText("文字");//编辑框中显示列表框选中内容
}

原来参考之前问的checkbox的问题,发现无法应用于radio button...
sheuchorngren 2009-09-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 muzizongheng 的回复:]
都给你解释了,,,,,,,,,郁闷!
[/Quote]

抱歉,muzizongheng前輩您的代碼無法實現

以下為我的代碼

\\初始化

BOOL CCtestDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// 將 "關於..." 功能表加入系統功能表。

// IDM_ABOUTBOX 必須在系統命令範圍之中。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);




CComboBox* pComboxA=(CComboBox*)GetDlgItem(IDC_COMBO1);
pComboxA->InsertString(0,"2001");
pComboxA->InsertString(1,"2002");
pComboxA->InsertString(2,"2003");
pComboxA->InsertString(3,"2004");
pComboxA->InsertString(4,"2005");
pComboxA->InsertString(5,"2006");
pComboxA->InsertString(6,"2007");
pComboxA->InsertString(7,"2008");
pComboxA->InsertString(8,"2009");
pComboxA->InsertString(9,"2010");



CListBox* pListD=(CListBox*)GetDlgItem(IDC_LIST4);
pListD->InsertString(0,"2001");
pListD->InsertString(1,"2002");
pListD->InsertString(2,"2003");
pListD->InsertString(3,"2004");
pListD->InsertString(4,"2005");
pListD->InsertString(5,"2006");
pListD->InsertString(6,"2007");
pListD->InsertString(7,"2008");
pListD->InsertString(8,"2009");
pListD->InsertString(9,"2010");


CComboBox* pComboxB=(CComboBox*)GetDlgItem(IDC_COMBO2);
pComboxB->InsertString(0,"2001");
pComboxB->InsertString(1,"2002");
pComboxB->InsertString(2,"2003");
pComboxB->InsertString(3,"2004");
pComboxB->InsertString(4,"2005");
pComboxB->InsertString(5,"2006");
pComboxB->InsertString(6,"2007");
pComboxB->InsertString(7,"2008");
pComboxB->InsertString(8,"2009");
pComboxB->InsertString(9,"2010");


CListBox* pListE=(CListBox*)GetDlgItem(IDC_LIST5);
pListE->InsertString(0,"2001");
pListE->InsertString(1,"2002");
pListE->InsertString(2,"2003");
pListE->InsertString(3,"2004");
pListE->InsertString(4,"2005");
pListE->InsertString(5,"2006");
pListE->InsertString(6,"2007");
pListE->InsertString(7,"2008");
pListE->InsertString(8,"2009");
pListE->InsertString(9,"2010");

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// 設定此對話方塊的圖示。當應用程式的主視窗不是對話方塊時,
// 框架會自動從事此作業
SetIcon(m_hIcon, TRUE); // 設定大圖示
SetIcon(m_hIcon, FALSE); // 設定小圖示

// TODO: 在此加入額外的初始設定


return TRUE; // 傳回 TRUE,除非您對控制項設定焦點
}


//預覽選擇(Combox→Edit)
void CCtestDlg::OnCbnSelchangeCombo1()
{
CString strchoose1;//字符串變量用來存放列表框中選中的字符串
m_combox1.GetLBText(m_combox1.GetCurSel(), strchoose1);
// m_combox1為列表框添加的成員變量,m_edit2為編輯框添加的成員變量
m_edit2.SetWindowText(strchoose1);//編輯框中顯示列表框選中內容
}

//預覽選擇(Combox→Static)

void CCtestDlg::OnCbnSelchangeCombo2()
{
CString strchoose2;//字符串變量用來存放列表框中選中的字符串
m_combox2.GetLBText(m_combox2.GetCurSel(), strchoose2);
// m_combox1為列表框添加的成員變量,m_edit2為編輯框添加的成員變量
m_static1.SetWindowText(strchoose2);
}

//預覽選擇(Listbox→Edit)

void CCtestDlg::OnLbnSelchangeList4()
{
CString strchoose4;
m_listbox4.GetText(m_listbox4.GetCurSel(),strchoose4);
m_edit3.SetWindowText(strchoose4);
}


//預覽選擇(Listbox→Static)

void CCtestDlg::OnLbnSelchangeList5()
{
CString strchoose5;
m_listbox5.GetText(m_listbox5.GetCurSel(),strchoose5);
m_static2.SetWindowText(strchoose5);
}
muzizongheng 2009-09-11
  • 打赏
  • 举报
回复
都给你解释了,,,,,,,,,郁闷!
sheuchorngren 2009-09-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 youyifang 的回复:]
预览?如何预览,显示文字吗?
[/Quote]

是的...

先輩若幫忙改寫或解釋...小弟一樣奉送分數!
sheuchorngren 2009-09-09
  • 打赏
  • 举报
回复
liuharris 前輩

這段代碼已經OK了?
可以解釋 "更仔細一點"嗎?

如果我不使用成員變量,而是使用CComboBox?

因為是初學者想多了解不懂的地方...
liuharris 2009-09-09
  • 打赏
  • 举报
回复
CString strchoose;//字符串变量用来存放列表框中选中的字符串
m_choose.GetLBText(m_choose.GetCurSel(), strchoose);
// m_choose为列表框添加的成员变量,m_keycode为编辑框添加的成员变量
m_keycode.SetWindowText(strchoose);//编辑框中显示列表框选中内容
muzizongheng 2009-09-09
  • 打赏
  • 举报
回复
A1:
在ComboBox的SelectChangeTab事件里 直接先调用ComboBox的GetWindowText, 然后调用edit的SetWindowText方法.

A2:
同理, 在RadioBox的点击事件里, 调用radiobox的GetWindowText, 然后调用edit的SetWindowText();
youyifang 2009-09-09
  • 打赏
  • 举报
回复
预览?如何预览,显示文字吗?

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧