Hi guys, I'm trying to make some textboxes be cleared in my Windows Form with a single button click, but I seem to have some problems. I tried the code below for the button but it keeps giving me a "error C2228: left of '.text' must have class/struct/union" problem.
1 2 3 4
void CzebraDlg::OnBnClickedClearimagedatabase()
{
IDC_Box01.text=""; //The textbox ID is IDC_Box01
}
The editor code when I double click the textbox I want to clear is below
1 2 3 4 5 6 7 8 9
void CzebraDlg::OnEnChangeBox01()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
I have about 20 or so boxes (IDC_Box01-20) to clear with the same button in a single click, so using the above format might be a little tedious, but I want to try and get the basic clearing of a textbox working in the first place before I complicate things.
I'm using MFC to build the form. Can anyone help? Thanks for any help in advance.
You should first create a variable for your textbox and you cannot access i using its resource ID. If you are using VC++, there is a wizard to do so. Hmmm, right click on the button in form design and you'll find it.
Hi there, I did as you said and used to wizard. It seems to have created a "CEdit m_Box01Ctl" in the header file linked to my Form dialog (code below).
void CzebraDlg::OnBnClickedClearimagedatabase()
{
m_Box01Ctl.text=""; //The textbox ID is IDC_Box01
}
But it gives me a "error C2039: 'text' : is not a member of 'CEdit'". Do you know the command I need to control the box and empty it?
Also, another problem I have, is that I want to make a radio button not selected by default when I start the program. I realise that the first of my radio buttons is always selected when I start the program but I want it to only be selected when I click it. Thanks a lot for the reply and any help in advance.
Usually when you type '.' after "m_Box01Ctl" IDE pops up a list of members which you can select one of them. Remember C++ is case sensitive so "text" is different from "Text". Use MSDN to study member variables.
In this case use SetWindowText() and GetWindowText().