Presentation is loading. Please wait.

Presentation is loading. Please wait.

Menus and Dialogs.

Similar presentations


Presentation on theme: "Menus and Dialogs."— Presentation transcript:

1 Menus and Dialogs

2 Assignment Overview Read 305-336
Exercise 1: You may use 3 colors for the background of your form instead of 3 message boxes. Exercise 2: Use menus to open Dialog Boxes. Each dialog box has pages dedicated to its operation. You may need to refer back to the RichTextBox control.

3 Menus Menus are a control Name them something meaningful:
i.e menuFileOpen, menuFileSave, menuColor, menuColorRed They will NOT show on your form, they show in an area below it. You simply click on the form and fill in the blanks Add ShortCut Keys in consistent windows style (i.e. Ctrl-S is save). They are in the properties. Add Accellerator Keys as well (i.e. E&xit) The Click event drives them

4 Dialog Boxes Open Save Folder Color Font Print

5 Open If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
This both opens the box and returns the result. DialogResult.OK is nomenclature that is easy for us to understand, but the computer knows it as a constant (the number 1). DialogResult.Cancel is 2. We don’t use it here, but generally would have to account for that choice. In short, the code just means this: If someone clicked the affirmative answer on the open dialog box, then…

6 Filters – Include them At that point you put the typical code that opens the item you wish to open. The book shows how to open a picture, but in earlier chapters it showed how to open an RTF file. Add a filter by adding a line like this to all your file dialogs: OpenFileDialog1.Filter = "RTF Files (*.rtf)|*.rtf|All Files (*.*)|*.*“ That vertical I-like character is the “pipe” character, off to the right of the alphanumeric keyboard. It acts here as a separator. When do you add the filter, before or after the dialog opens?

7 FileName property To load the file, you do it just as you did with the Rich Text Box previously. But the argument, which is the filename you are opening, is this: OpenFileDialog1.FileName In other words the FileName property is the dialog box’s property representing the file name you chose.

8 SAVE With saving we also need to select if someone clicked OK for saving, as we just did to open the file Of course we don’t want to save if they clicked cancel! At the appropriate place you simply save your RTF file as we did in previous days.

9 Font You show the dialog box just as you did any of the others.
RichTextBox1.ForeColor = FontDialog1.Color This takes the property of the color of the font in your dialog box and assigns it to the Rich Text Box ForeColor (font’s color)

10 Color ColorDialog1.Color is the color Property of the ColorDialog1 control.


Download ppt "Menus and Dialogs."

Similar presentations


Ads by Google