View previous topic :: View next topic |
Author |
Message |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Sat Apr 28, 2007 4:42 pm Post subject: Closing a child window after a choice |
|
|
Greetings.
I have this sub,
Code: | final void NewReportForm()
{
Form f;
with(f = new Form)
{
text = "Choose What Report To Create";
startPosition = dfl.form.FormStartPosition.CENTER_PARENT;
with(new Button)
{
text = "Combined";
location = Point(2, 2);
parent = f;
click ~= &CombinedReportClick;
}
with(new Button)
{
text = "TimeUsage";
location = Point(2, 42);
parent = f;
click ~= &TimeUsageReportClick;
}
show();
}
}
|
and it works fine, but I want to close that window after one of the button has been clicked. I tried a few things, but it is not working. I know it's something simple, but what it is? I know it is f.close(), but where do I put it so that it happens after the click?
thanks. |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Sun Apr 29, 2007 12:25 pm Post subject: Re: Closing a child window after a choice |
|
|
Just close the form in the button's click event... (CombinedReportClick or TimeUsageReportClick)
Perhaps you are confused because you no longer have a reference to the form (from what I gather from your snippet). You can either save a reference to it, or pull it from the sender's parent:
Code: | void CombinedReportClick(Control sender, EventArgs ea)
{
(cast(Form)sender.parent).close(); // Close through parent. parent must be the Form.
} |
As a side note, I always thought it'd be cool if D let you specify the context of a delegate literal, instead of always inferring it from the scope. It could let you 'attach' a delegate to your Form inline without actually having to define a member function for it in the class definition. It could simplify a lot of these cases where the delegate is needed beyond the lifetime of the stack frame. If you don't know what I mean you can just ignore this. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Sun Apr 29, 2007 6:16 pm Post subject: Re: Closing a child window after a choice |
|
|
Chris Miller wrote: | Just close the form in the button's click event... (CombinedReportClick or TimeUsageReportClick)
Perhaps you are confused because you no longer have a reference to the form (from what I gather from your snippet). You can either save a reference to it, or pull it from the sender's parent:
Code: | void CombinedReportClick(Control sender, EventArgs ea)
{
(cast(Form)sender.parent).close(); // Close through parent. parent must be the Form.
} |
As a side note, I always thought it'd be cool if D let you specify the context of a delegate literal, instead of always inferring it from the scope. It could let you 'attach' a delegate to your Form inline without actually having to define a member function for it in the class definition. It could simplify a lot of these cases where the delegate is needed beyond the lifetime of the stack frame. If you don't know what I mean you can just ignore this. |
I tried this,
Code: | private void TimeUsageReportClick(Object sender, EventArgs ea)
{
msgBox("TimeUsageReport.");
(cast(Form)sender.parent).close(); // Close through parent. parent must be the Form.
}
|
But it is not working. How do I call it from the parent? I am getting,
Code: | 20:11:06.61>build -I..;c:\dmd\import -version=gui -version=Phobos OpenJobs.d
OpenJobs.d(4040): Error: no property 'parent' for type 'object.Object'
Error: cannot cast int to dfl.form.Form |
Also, I know what you are talking about. I may not understand it as deep as you, but I know what you are saying... |
|
Back to top |
|
|
sleets
Joined: 29 Jun 2007 Posts: 27
|
Posted: Fri Jun 29, 2007 4:46 am Post subject: |
|
|
Code: |
void TimeUsageReportClick(Object sender, EventArgs ea)
// error
|
Code: |
void CombinedReportClick(Control sender, EventArgs ea)
// right
|
|
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Sat Jun 30, 2007 9:47 pm Post subject: |
|
|
This does not work either. |
|
Back to top |
|
|
sleets
Joined: 29 Jun 2007 Posts: 27
|
Posted: Sat Jun 30, 2007 11:27 pm Post subject: |
|
|
Code: |
/*
Generated by Entice Designer
Entice Designer written by Christopher E. Miller
www.dprogramming.com/entice.php
*/
private import dfl.all;
//private import std.c.time;
class XForm{
private:
dfl.form.Form f;
this()
{
with(f = new Form) {
text = "My Form";
clientSize = dfl.drawing.Size(292, 268);
with(new dfl.button.Button){
text = "123";
parent = f;
click ~= delegate void( Control sender, EventArgs ea ){
f.close();
};
}
}
Application.run(f);
}
private void initializeMyForm() {
}
}
int main()
{
int result = 0;
try
{
new XForm();
}
catch(Object o)
{
msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
result = 1;
}
return result;
}
|
this work on my case. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Sun Jul 01, 2007 3:20 pm Post subject: |
|
|
thank you for your help. After seeing your example, I rewrote my program to follow your declarations and I now got it to work...
Thanks.
jose |
|
Back to top |
|
|
|