多语言展示
当前在线:1030今日阅读:126今日分享:42

vb.net对话框操作实例(二)

Creating a Save dialog that enables you to save filesCreating a Font dialog that enables you to apply the selected font to textCreating a Color dialog that enables you to define and select custom colorsCreating a Print dialog that prints text from your applicationCreating a Browse dialog that enables you to browse for folders
工具/原料

visual studio 2015

THE SAVEDIALOG CONTROL
2

Private Sub btnSave_Click(sender As Object,    e As EventArgs) Handles btnSave.Click    'Set the Save dialog properties    With SaveFileDialog1        .DefaultExt = 'txt'        .FileName = strFileName        .Filter = 'Text Documents (*.txt)|*.txt|All Files (*.*)|*.*'        .FilterIndex = 1        .OverwritePrompt = True        .Title = 'Demo Save File Dialog'    End With     'Show the Save dialog and if the user clicks the Save button,    'save the file   If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then        Try            'Save the file path and name            strFileName = SaveFileDialog1.FileName  My.Computer.FileSystem.WriteAllText(strFileName, txtFile.Text, False)        Catch ex As Exception            MessageBox.Show(ex.Message, My.Application.Info.Title,                MessageBoxButtons.OK, MessageBoxIcon.Error)        End Try    End IfEnd Sub

THE FONTDIALOG CONTROL
1

Property DESCRIPTIONAllowScriptChange Indicates whether the user can change the character set specified in the Script drop-down box to display a character set other than the one currently displayedColor Indicates the selected font colorFont Indicates the selected fontFontMustExist Indicates whether the dialog specifies an error condition if the user attempts to enter a font or style that does not existMaxSize Indicates the maximum size (in points) a user can selectMinSize Indicates the minimum size (in points) a user can selectShowApply Indicates whether the dialog contains an Apply buttonShowColor Indicates whether the dialog displays the color choiceShowEffects Indicates whether the dialog contains controls that allow the user to specify strikethrough, underline, and text color optionsShowHelp Indicates whether the dialog displays a Help button

2

You will be using only one method (ShowDialog) of FontDialog in the following. Other methods available include Reset, which enables you to reset all the properties to their default values.FontDialog1.ShowColor = TrueFontDialog1.ShowDialog()

THE COLORDIALOG CONTROL
1

Property DESCRIPTIONAllowFullOpen Indicates whether users can use the dialog to define custom colorsAnyColor Indicates whether the dialog displays all available colors in the set of basic colorsColor Indicates the color selected by the userCustomColors Indicates the set of custom colors shown in the dialogFullOpen Indicates whether the controls used to create custom colors are visible when the dialog is openedShowHelp Indicates whether a Help button appears in the dialogSolidColorOnly Indicates whether the dialog will restrict users to selecting solid colors only

2

Private Sub btnColor_Click(sender As Object,    e As EventArgs) Handles btnColor.Click    'Show the Color dialog and if the user clicks the OK button,    'update the background color of the form    If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then        Me.BackColor = ColorDialog1.Color    End IfEnd Sub

推荐信息