|
-
Dec 22nd, 2007, 03:19 AM
#1
Thread Starter
Frenzied Member
[2.0] Show another form as a dialog (or show a dialog)
Problem 1:
I am wanting to make my own dialog, but I did not see the option in the 'New Item' list in VS C#, so I made a windows form, and set the same settings as a dialog box would normally have, but I can't do myDialogForm.ShowDialog();
it doesn't have the parameters...
Problem 2:
I can't access any variables from Form1, to myDialogForm,
Any Idea's?
Thanks
Last edited by Icyculyr; Dec 23rd, 2007 at 02:00 AM.
-
Dec 22nd, 2007, 06:28 AM
#2
Re: [2.0] Show another form as a dialog (or show a dialog)
1. There is no Dialog item template in C#. VB and C# have completely separate templates because, of course, they must each be implemented in a different language. Some are the same and some not.
That said, the Dialog template is simply an inherited Form with a few properties set and a few controls added. It would take about 2 minutes to replicate that yourself.
Also, C# doesn't have those stupid default instances that they should never have introduced in VB. In VB you can do this:which will display the default instance. That's a language feature, not a Framework feature, and one that I recommend not using. I would recommend always treating forms as normal objects:
vb.net Code:
Dim dialogue As New SomeForm
dialogue.ShowDialogue()
In C# the first pattern is not an option because default instances don't exist so you have to use the second pattern. The fact that you didn't know this is an example of why default instances should not exist.
2. A dialogue should never need to access its caller. The caller creates the dialogue, sets the appropriate properties to pass data in, displays the dialogue, then gets the appropriate properties to pull data out.
-
Dec 22nd, 2007, 05:52 PM
#3
Thread Starter
Frenzied Member
Re: [2.0] Show another form as a dialog (or show a dialog)
sets the appropriate properties to pass data in
hmm? I don't know how to do that...
What I did do (before anyone replied) was pattern 2...
I need to set a value or two on Form1 to 'true, or false' based on what the dialog result of the form is, I suppose I could use the Dialog Result stuff, but I don't need to do I? since all my functions for myDialog are held in my Form1 code:P
-
Dec 22nd, 2007, 09:20 PM
#4
Re: [2.0] Show another form as a dialog (or show a dialog)
Why is it that so many people are determined to treat forms differently to other objects. They are not different. They are exactly the same. Are you really telling me that you don't know how to create an object and set some of its properties? Maybe you don't know how to declare the properties you need in your dialogue class, but I doubt that too. Have you made it this far without ever having declared a property? I'm very surprised if you have, but then I've been surprised before.
As for that second paragraph, I'm afraid I really don't know what you're saying. Look, the steps are simple:
1. Create the dialogue.
2. Set its properties (if and only if you need to pass data in).
3. Call ShowDialog.
4. Get the result of ShowDialog to determine what happened in the dialogue.
5. Get property values from the dialogue (if and only if you need to get data out).
Now, the way you get ShowDialog to return the value you want is to set the dialogue's DialogResult property. You don't call Close or anything else. You just set the DialogResult property and that will dismiss the dialogue. You would usually do this on the Click of a Button, like an OK or Cancel button.
The code would look something like this:
CSharp Code:
using (SomeForm dialogue = new SomeForm)
{
// Pass data in.
dialogue.SomeProperty = someValue;
if (dialogue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Get data out.
someOtheValue = dialogue.SomeOtherProperty;
}
}
Obviously it's up to you to declare the SomeProperty and SomeOtherProperty properties in the form, as it is always your responsibility to declare the members of your classes.
-
Dec 23rd, 2007, 12:37 AM
#5
Thread Starter
Frenzied Member
Re: [2.0] Show another form as a dialog (or show a dialog)
I see what you mean by the properties ^_^..
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|