So i have my main form and i open a second form using this code
this->Hide();
Form2^ dlg=gcnew Form2();
dlg->ShowDialog();
how do i go back from the second form to the main one?
In the dialog code set the DialogResult property, this will close the dialog and return to the main form, ShowDialog will return the DialogResult value you set.
Alternatively you can have a button on the dialog that has a DialogResult property set and then clicking the button will close the dialog and return the value associated with the button.
Related
if (IDOK == dlg.DoModal())
{
csFile = dlg.GetPathName();
return (LPCTSTR)csFile;
}
return NULL;
I have a desktop application and in this I have a dialog box. When I click on open button in this dialog box another open dialog box should pop up. Once this open dialogue box is displayed I am able to again go to the previous dialogue box and click on open. So second instance of open dialog box is displayed. I can do this many times. The open dialog box is modal to the whole application and not to the previous dialog box. Can anyone help me with this? As per design once open dialog box is displayed nothing else should be active till this is closed.
The standard wizard-generated constructor for the dialog box contains an optional constructor-parameter where you can specify the parent window:
class CMyOpenDialog : public CDialog
{
// Construction
public:
CMyOpenDialog(CWnd* pParent = NULL); // standard constructor
...
When you invoke this second dialog from your dialog, supply the parent, like
CMyOpenDialogdlg(this);
I design mfc dialog based application in which first i design main parent window containing multiple child windows with tab control,it works fine.After i add one dialog before parent dialog and call parent dialog from it.So call to new dialog insert Back button on parent dialog,it works well,but second time parent dialog failed to open and application close.So how to save state of parent dialog second time initialization.I used methodlogy for above scenario given below:
I call new dialog in OnInitDialog() of parent dialog as DoMOdal() method.
Back button code given below:
void CParent::OnBnClickedBack()
{
UpdateData(TRUE);
NewDlg dlg=new NewDlg();
OnOK();
dlg.DoModal();
}
I have an Edit Box and a Button on a dialog. How can I change the content in the edit box runtime as the button is clicked? I have to read a new record from a file and post it in the Edit Box as the Button is clicked and I am using mfc.
Once you have trapped the button press, in most cases the easiest way to change text in an Edit Control is:
SetDlgItemText(IDC_EDIT_ID, "Desired Text String")
Where IDC_EDIT_ID is the ID of the Edit Control (set in the properties window)
You can set the text of an Edit control (wrapped by the CEdit class in MFC) by calling the SetWindowText method, which it inherits from the CWnd base class.
So then all you need to do is respond to a click event on your button control. You do this by listening for the BN_CLICKED notification from the appropriate button control within your parent window's OnCommand method.
Something like:
BOOL CMyDialog::OnCommand(WPARAM wParam, LPARAM lParam)
{
if (HIWORD(wParam) == BN_CLICKED && LOWORD(lParam) == IDC_MYBUTTON)
{
m_Edit.SetWindowText(TEXT("My string"));
}
return CWnd::OnCommand(wParam, lParam);
}
Obtaining and reading a book on MFC would be very helpful. This is fairly basic stuff, but it's a lot to cover in a single answer if you don't already understand the fundamental concepts.
Using the Class Wizard would make this even easier... Invoke it with the Ctrl+W keys and follow the on-screen instructions. You'll end up with something like:
void CMyDialog::OnMyButton()
{
m_Edit.SetWindowText(TEXT("My string"));
}
I am loading a usercontrol in code-behind as show below
Dim AdjFormctl As UserControl = CType(LoadControl("~/Controls/AdjForm.ascx"), UserControl)
Dim EMPFormType As Type = AdjFormctl.GetType()
Dim EMPPK As PropertyInfo = ABCFormType.GetProperty("employeePK")
AdjFormctl.ID = "ucAdjForm"
EMPPK.SetValue(AdjFormctl, Convert.ToInt32(txtEMPPK.Text), Nothing)
phSettlement.Controls.Add(AdjFormctl)
though it is loading properly. When I hit the submit button that is in the usercontrol it is not going inside the buttonclick event and wiping out the usercontrol from the page.
Please help
Where did you put this code? If you put in the event handler for submit button, the control will ONLY be generated when the submit button is pressed.
It means that you will only see it in the browser when the page comes back after you pressed the button. The html generated as a result of any other action will not have it.
If you want the control to stay you will have to include this code somewhere else i.e. OnLoad event or PreRender event
In my code, I have lines like this:
Builder builder = new Builder();
builder.AddFromFile(gladefile);
FileChooserDialog dialog =
(FileChooserDialog) builder.GetObject("dialog");
dialog.DefaultResponse = ResponseType.Ok;
Is there a way to set the default response in the glade file, rather than doing it manually?
Yes. When you create a GtkFileChooserDialog in Glade, you add the buttons to the dialog's button box. For example, "OK" and "Cancel". To make the "OK" button default, select the "OK" button, go to the "Common" properties, and turn on "Can default" and "Has default".