FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HowTo: Dialog invoked from main app?

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Sun Dec 26, 2004 9:22 pm    Post subject: HowTo: Dialog invoked from main app? Reply with quote

What is the preferred way to invoke and use a modal and/or modeless dialog from a main Form application?

I looked over the example code, and client.d uses a dialog. However, my impression is that this isn't necessarily "The DFL Endorsed Way" to use a dialog. I'm hesitant to proceed with this as a template.

I want to have a dialog for setting Search Options (case sensitive, all words, phrase, range, exact words, etc.). It would have controls such as CheckBox, RadioButtons, and/or ComboBoxes. Should such a dialog be a separate Form? How should it be invoked from the main app to be consistent with your 'vision' of how DFL works? How should the main app know whether the dialog was Cancelled or Accepted?

How about use of a modeless dialog with Apply functionality?

Sample code would be appreciated on how you intend for this to work together. I can probably hack something together by trial & error, but would appreciate guidance on "The Preferred DFL Way" to accomplish this.

THANKS!
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Mon Dec 27, 2004 3:28 pm    Post subject: Re: HowTo: Dialog invoked from main app? Reply with quote

Lynn wrote:
What is the preferred way to invoke and use a modal and/or modeless dialog from a main Form application?
You can derive from Form or just use a new Form, really just depends on what you want. Deriving from Form seems to simplify things in the long run. Use showDialog() for a modal dialog and show() otherwise.


Quote:
How should the main app know whether the dialog was Cancelled or Accepted?
Form has a dialogResult property. In some events you can set it to DialogResult.CANCEL or DialogResult.OK, etc. Or add your own variables to check other values.


Quote:
How about use of a modeless dialog with Apply functionality?
Depends on how you implement it.. I'm not sure what to say here.


Quote:
Sample code would be appreciated on how you intend for this to work together.
Code:
private import dfl.all;

class MainForm: Form
{
   this()
   {
      MyModal mm;
      mm = new MyModal;
      mm.showDialog(this);
      if(mm.dialogResult == DialogResult.OK)
         MessageBox.show("You clicked OK!");
      else
         MessageBox.show("You did not click OK");
      mm.dispose(); // Destroy the modal dialog.
   }
}

class MyModal: Form
{
   Button ok, cancel;
   
   this()
   {
      dialogResult = DialogResult.CANCEL;
     
      size = Size(200, 80);
      minimizeBox = false;
      maximizeBox = false;
      icon = null;
      showInTaskbar = false;
      startPosition = FormStartPosition.CENTER_PARENT;
      formBorderStyle = FormBorderStyle.FIXED_DIALOG;
      backColor = Color(0, 0, 0xCC);
     
      ok = new Button;
      ok.text = "OK";
      ok.parent = this;
      ok.click ~= &ok_click;
     
      cancel = new Button;
      cancel.text = "Cancel";
      cancel.left = 80;
      cancel.parent = this;
      cancel.click ~= &cancel_click;
     
      acceptButton = ok; // Enter key.
      cancelButton = cancel; // Esc key.
   }
   
   private void ok_click(Object sender, EventArgs ea)
   {
      dialogResult = DialogResult.OK;
      hide(); // Causes showDialog() to return.
   }
   
   private void cancel_click(Object sender, EventArgs ea)
   {
      hide(); // Causes showDialog() to return.
   }
}


int main()
{
   int result = 0;
   try
   {
      Application.run(new MainForm);
   }
   catch(Object o)
   {
      MessageBox.show(o.toString(), "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.ERROR);
      result = 1;
   }
   return result;
}

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group