2012年1月8日 星期日

VB.net 基本的 對話框 字體 顏色 開啟檔案


Public Class Form1

    Private Sub btn_FontDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_FontDialog.Click
        FontDialog1.ShowColor = True
        FontDialog1.ShowApply = True
        '套用的功能就是 視窗不會關閉 會產生 apply的事件
        '這樣使用者就不會因為按下確定(視窗會關閉)以後 還要在重新 showdailog 一次
        '算是體貼使用者設計
        FontDialog1.ShowDialog()
    End Sub

    Private Sub FontDialog1_Apply(ByVal sender As Object, ByVal e As System.EventArgs) Handles FontDialog1.Apply
        Label1.Font = FontDialog1.Font
        Label1.ForeColor = FontDialog1.Color
    End Sub

    Private Sub btn_ColorDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ColorDialog.Click
        ColorDialog1.FullOpen = True '展開所有功能
        ColorDialog1.ShowDialog()
        Label2.BackColor = ColorDialog1.Color
    End Sub

    Private Sub btn_OpenFileDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_OpenFileDialog.Click
        OpenFileDialog1.Reset()
        OpenFileDialog1.Multiselect = True
        OpenFileDialog1.Title = "來選擇一個或多個檔案吧"
        OpenFileDialog1.FileName = Application.StartupPath + "\test.text"
        OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            ListBox1.Items.Clear()

            For Each myfilename In OpenFileDialog1.FileNames
                ListBox1.Items.Add(myfilename)
            Next
        End If

    End Sub

End Class

沒有留言:

張貼留言