<address id="xpjh9"><listing id="xpjh9"><meter id="xpjh9"></meter></listing></address>

<address id="xpjh9"><address id="xpjh9"><listing id="xpjh9"></listing></address></address>
<noframes id="xpjh9">
<noframes id="xpjh9">

<address id="xpjh9"><address id="xpjh9"><listing id="xpjh9"></listing></address></address>
    <form id="xpjh9"></form><address id="xpjh9"><listing id="xpjh9"><menuitem id="xpjh9"></menuitem></listing></address>

      <noframes id="xpjh9">
      VB.net 2010 視頻教程 VB.net 2010 視頻教程 VB.net 2010 視頻教程
      SQL Server 2008 視頻教程 c#入門經典教程 Visual Basic從門到精通視頻教程
      當前位置:
      首頁 > 編程開發 > .net教程 >
      • vb.net教程之程序對話框

      • 2015-01-18 12:57 來源:未知
      程序對話框(相關vb.net教程)
      有關對話框的一組控件:
      打開文件對話框openfiledialog:
      保存文件對話框savefiledialog:
      顏色對話框colordialog:
      字體對話框fontdialog:
      常用屬性:
      Name:控件名。
      Filename:對話框中所選擇的文件名
      Filenames:允許選擇多個文件時,所選擇的文件名數組。當multiselect為真時才可用。
      Multiselect:彈出的選擇文件對話框中,允許不允許選擇多個。
      Filter:顯示的文件類型,它由“說明|*.類型”構成,一般放在窗體的load事件中。
      DefaultExt:保存文件時默認擴展名,字符串,一般放在窗體的load事件中。
      Color:對話框選定的顏色。
      Font: 對話框選定的字體。
      常用方法:
      Showdialog:用以彈出對話框。
      應用實例:制作一個圖片瀏覽器
      見,圖片瀏覽器1
      程序為:
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Dim ss As String
              Op.ShowDialog()
              ss = Op.FileName
              PictureBox1.Image = Image.FromFile(ss)
       
          End Sub
       
          Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
              Op.Filter = "*.jpg|*.jpg|*.bmp|*.bmp"
          End Sub
      應用實例:制作一個可同時打開多個文件的圖片瀏覽器,并能進行上下翻閱瀏覽。
      見,可上下翻閱的圖片瀏覽器,程序為:
      Public Class Form1
          Dim i As Integer
          Dim j As Integer
          Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              OpenF.Filter = "jpg file|*.jpg|bmp file|*.bmp|gif file|*.gif"
              'OpenF.DefaultExt = "bmp"
              OpenF.Multiselect = True
          End Sub
       
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              OpenF.ShowDialog()
              PictureBox1.Image = Image.FromFile(OpenF.FileName)
              i = UBound(OpenF.FileNames)
              MsgBox("選擇的文件數為:" & Str(i + 1), 32, "提示")
          End Sub
       
          Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
              j = j + 1
              If j >= i Then
                  j = i
                  Button2.Enabled = False
                  Button3.Enabled = True
              End If
              PictureBox1.Image = Image.FromFile(OpenF.FileNames(j))
          End Sub
       
          Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
              j = j - 1
              If j <= 0 Then
                  j = 0
                  Button3.Enabled = False
                  Button2.Enabled = True
              End If
              PictureBox1.Image = Image.FromFile(OpenF.FileNames(j))
          End Sub
       
          Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
              End
          End Sub
      End Class
      應用實例:通過顏色,字體對話框設置文本框中的字體,字號,字的顏色。
      見,通用對話框綜合實例[實驗報告33 ]
      程序為:
      Public Class Form1
          Dim ss As String
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              o.ShowDialog()
              ss = o.FileName
              P.Image = Image.FromFile(ss)
          End Sub
       
          Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
              C.ShowDialog()
              L.ForeColor = C.Color
          End Sub
       
          Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
              F.ShowDialog()
              L.Font = F.Font
          End Sub
       
          Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
              End
          End Sub
       
          Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
              S.ShowDialog()
              ss = S.FileName
              ss = MsgBox("如果要真正的保存一個文件," & Chr(13) & Chr(13) & "還需要文件操作控件", 16, "注意!")
          End Sub
       
          Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
              S.Filter = ("文本文件(*.txt)|*.txt")
              S.DefaultExt = "txt"
              o.Filter = ("圖形文件*.jpg|*.jpg|*.bmp|*.bmp")
              o.DefaultExt = "jpg"
          End Sub
      End Class
      練習:試開發一個記事本軟件。
      見,小小記事本,程序為:
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              ColorDialog1.ShowDialog()
              TextBox1.ForeColor = ColorDialog1.Color
          End Sub
       
          Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
              FontDialog1.ShowDialog()
              TextBox1.Font = FontDialog1.Font
          End Sub
       
          Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
              Dim n As Integer
              Dim f As String
              SaveFileDialog1.ShowDialog()
              f = SaveFileDialog1.FileName
              n = FreeFile()
              FileOpen(n, f, OpenMode.Output)
              Print(n, TextBox1.Text)
              FileClose(n)
          End Sub
       
          Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              OpenFileDialog1.Filter = "文本文件|*.txt"
              SaveFileDialog1.Filter = "文本文件|*.txt"
              OpenFileDialog1.DefaultExt = "txt"
              SaveFileDialog1.DefaultExt = "txt"
          End Sub
       
          Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
              Dim fn As Integer
              Dim s As String = ""
              OpenFileDialog1.FileName = ""
              If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                  fn = FreeFile()
                  FileOpen(fn, OpenFileDialog1.FileName, OpenMode.Input)
                  Do While Not EOF(fn)
                      s = s + LineInput(fn) + vbCrLf
                  Loop
                  FileClose(fn)
                  TextBox1.Text = s
              End If
          End Sub
       
          Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
              End
      End Sub
      相關教程
      江苏快3 泰兴 | 汕头 | 楚雄 | 张家口 | 仁寿 | 宁夏银川 | 大同 | 乌兰察布 | 基隆 | 项城 | 长兴 | 霍邱 | 青海西宁 | 汝州 | 云南昆明 | 昭通 | 阿坝 | 莱州 | 东营 | 巴音郭楞 | 福建福州 | 阿拉善盟 | 曲靖 | 毕节 | 白山 | 高雄 | 鹤壁 | 玉环 | 高密 | 如皋 | 嘉善 | 广州 | 黄山 | 天水 | 忻州 | 溧阳 | 鹤岗 | 潜江 | 宁德 | 长葛 | 莆田 | 枣阳 | 广汉 | 泗洪 | 天长 | 白沙 | 沧州 | 安徽合肥 | 湘潭 | 梅州 | 沭阳 | 通化 | 渭南 | 山西太原 | 玉林 | 池州 | 黄南 | 温岭 | 驻马店 | 诸暨 | 潍坊 | 唐山 | 偃师 | 百色 | 邳州 | 葫芦岛 | 绵阳 | 广汉 | 永康 | 广西南宁 | 丹东 | 湖北武汉 | 燕郊 | 永州 | 宜昌 | 章丘 | 果洛 | 湘潭 | 图木舒克 | 兴化 | 清远 | 桂林 | 云浮 | 日喀则 | 黄南 | 南安 | 庄河 | 改则 | 雅安 | 青海西宁 | 阿里 | 海北 | 阿里 | 江苏苏州 | 湖南长沙 | 商丘 | 吉林长春 | 阳泉 | 深圳 | 普洱 | 湛江 | 陇南 | 六盘水 | 铜仁 | 芜湖 | 景德镇 | 乌海 | 邯郸 | 蓬莱 | 通辽 | 库尔勒 | 泰州 | 天水 |