SLIDE 6 Image file Dialogue
- This is why you use a higher-level API.
- With windows forms and .Net 1.1 this is
really trivial. Follow these simple steps:
- 1. Drag an OpenFileDialog control to anywhere
- n your Form. Notice that it places it in a
special window pane below your design.
- 2. Drag a Button control to the Lab1 tab panel.
This will be used to bring up the dialog.
Image file Dialogue
- Adjust the Button’s properties:
1. Change the text to “Load Texture”
- Adjust the OpenFileDialog’s properties
1. Change the Title to “Select an image file for the texture” 2. In the Filter property add a string to aid in the right file type
- selection. Something like this:
“All files (*.*)|*.*|Jpeg (*.jpg)|*.jpg|Png (*.png)|*.png”. Each pair here has the format (Text string to display | regular expression). Note that adding a space before the asterisk results in a different regular expression. 3. Set the Filter index to 2, such that jpeg is the default format. 4. Set the AddExtension to False. 5. Make sure the Multiselect property is False.
Image file Dialogue
- Okay, we have now defined everything, such
that the constructor is called and the properties are set. Nothing will happen though, we need to add some logic.
- Double click the “Load Texture” button. This
adds some template code and brings up the source code window (Form1.h).
- It also added this line inside the
InitializeComponents:
this->button1->Click += new System::EventHandler(this, button1_Click);
- Add the following line in button1_Click:
this->openFileDialog1->ShowDialog();
Image file Dialogue
- Run and test the program. Clicking on the
button should bring up the openFileDialog.