Cynthia
10-03-2003, 11:39 PM
I want to bring up an openDialog in v7.0 Fortran .Net.
How do I do this.? I am able to drag an openFIleDialog onto the Form but I can't figure out to connect it and get it to post ??
Cheers,
Cynthia
tzeis
10-06-2003, 09:30 PM
When you drag the OpenFileDialog control onto a form, the Windows designer adds a declaration for the .NET Framework OpenFileDialog class called "openFileDialog1", and it allocates an instance of the class. This is helpful, because by dragging the control onto the form, you have created the dialog, and it is ready to use, but it is not displayed.
You can set various characteristics for the Open File dialog by highlighting it in the design view, and changing values in the Properties window.
At the point you want to display the dialog, you invoke the ShowDialog method. This method returns a variable of type DialogResult, so you will need to declare a variable with this name. For example, suppose that you want to display the Open File dialog when a button is clicked. After you drag the button onto the form, double click on the button, and this code should appear in the code view:
subroutine button1_Click(this, sender, e)
class(Form1) :: this
class(System%Object),target :: sender
class(System%EventArgs),target :: e
end subroutine
To display the dialog, you need to add a declaration for a DialogResult variable:
type(DialogResult) :: openfileresult
and invoke the ShowDialog Method:
openfileresult = this%openFileDialog1%ShowDialog()
so the entire subroutine should look like this:
subroutine button1_Click(this, sender, e)
class(Form1) :: this
class(System%Object),target :: sender
class(System%EventArgs),target :: e
type(DialogResult) :: openfileresult
openfileresult = this%openFileDialog1%ShowDialog()
end subroutine
At this point, if you run the application, and click the button, the Open File dialog should appear. In order to process the results of the dialog, you have a couple of options. In the button_click procedure, you can evaluate the openfileresult variable to see if the Open File dialog concluded successfully, and perform whatever actions are required. If you want to dispense with evaluating the result, and only respond if there is a successful resolution to the dialog, in the design view, double click on the Open File dialog that you dragged onto the form. In the code view, you should see something like this:
subroutine openFileDialog1_FileOk(this, sender, e)
class(Form1) :: this
class(System%Object),target :: sender
class(System%ComponentModel%CancelEventArgs), target :: e
end subroutine
This method will only be invoked if the "Open" button was pressed in the Open File dialog. If the dialog was cancelled, this method will not be invoked.
Once a successful outcome is achieved, you can use the FileName property of the OpenFileDialog class to retrieve the filename selected in the dialog. In the example that we are using, you might have code like this:
character(len=256) :: filename
...
filename = string(this%openFileDialog1%FileName)
...
For more information about the Open File dialog, use the index in Visual Studio to look up OpenFileDialog Class. This gives a complete description of the properties and methods belonging to the class. Check out the DialogResult Enumeration to check for various return values of the ShowDialog method.
Let me know if any parts of this aren't clear, or if you want any more information.
vBulletin® v3.6.8, Copyright ©2000-2012, Jelsoft Enterprises Ltd.