1 / 13

第 8 章 視窗 控制項(二)

第 8 章 視窗 控制項(二). 8-1 訊息與對話方塊. 8-1-1 MsgBox 訊息視窗 8-1-2 InputBox 對話方塊. MsgBox. InputBox. 8-1-1 MsgBox 訊息視窗 - 語法. Visual Basic 的 MsgBox() 函數可以顯示訊息視窗,提供使用者錯誤訊息或是非題的選擇。例如:確認操作,函數的語法如下所示: MsgBox( 提示訊息 , [ 樣式 , 視窗標題 ]) 上述函數參數的最後 2 個是選擇參數,可以不用指定。. 8-1-1 MsgBox 訊息視窗 - 提示訊息參數. 提示訊息參數

denzel
Download Presentation

第 8 章 視窗 控制項(二)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第8章 視窗控制項(二)

  2. 8-1 訊息與對話方塊 • 8-1-1 MsgBox訊息視窗 • 8-1-2 InputBox對話方塊 MsgBox InputBox

  3. 8-1-1 MsgBox訊息視窗-語法 • Visual Basic的MsgBox()函數可以顯示訊息視窗,提供使用者錯誤訊息或是非題的選擇。例如:確認操作,函數的語法如下所示: MsgBox(提示訊息, [樣式, 視窗標題]) • 上述函數參數的最後2個是選擇參數,可以不用指定。

  4. 8-1-1 MsgBox訊息視窗-提示訊息參數 提示訊息參數 • 顯示在訊息視窗的資訊字串,MsgBox()函數至少需要提供此參數。

  5. 8-1-1 MsgBox訊息視窗-樣式參數

  6. 8-1-1 MsgBox訊息視窗-視窗標題參數 視窗標題參數 • 顯示在訊息視窗上方標題列的字串,如果沒有指定,預設是專案名稱。

  7. 8-1-1 MsgBox訊息視窗-範例 • 訊息視窗MsgBox函數的使用範例,如下所示: ret = MsgBox(txtPrompt.Text, msgStyle, _ txtTitle.Text) • 第1個參數是文字方塊內容,第2個參數msgStyle顯示樣式的整數值,使用的是列舉常數,如果不只一個(按鈕、圖示、預設按鈕只能各選一),請使用加法來計算樣式值,如下所示: msgStyle = MsgBoxStyle.OKCancel + _ MsgBoxStyle.Question + _ MsgBoxStyle.DefaultButton2

  8. 8-1-1 MsgBox訊息視窗-傳回值 • MsgBox()函數如果有傳回值,傳回值是按下哪一個按鈕,屬於MsgBoxResult列舉常數,如下表所示:

  9. 8-1-1 MsgBox訊息視窗-Visual Basic專案 msgStyle = MsgBoxStyle.OkCancel + _ MsgBoxStyle.Question + _ MsgBoxStyle.DefaultButton2 ret = MsgBox(txtPrompt.Text, msgStyle, txtTitle.Text) If ret = MsgBoxResult.Ok Then End ' 結束程式

  10. 8-1-2 InputBox對話方塊-語法 • InputBox對話方塊不同於MsgBox訊息視窗是一種「是非」選擇,它可以彈出對話方塊,讓使用者輸入資料,在功能上如同單行文字方塊控制項。 • InputBox()函數的語法如下所示: InputBox(提示訊息, [標題文字, 預設值, 位置x, 位置y]) • 上述函數的最後4個參數是選擇參數,可以不用指定。

  11. 8-1-2 InputBox對話方塊-參數 • 提示訊息:顯示在對話方塊的字串,InputBox()函數至少需要提供此參數。 • 標題文字:顯示在標題列的文字內容。 • 預設值:輸入資料的預設值。 • 位置x、位置y:對話方塊在螢幕上顯示的位置,沒有指定,預設值是桌面正中央。

  12. 8-1-2 InputBox對話方塊-範例 • InputBox()函數的使用範例,如下所示: strValue = InputBox("請輸入金額?", _ "輸入金額") • 上述程式碼的InputBox()函數只有前2個參數,傳回值是使用者輸入的資料,按下「確定」鈕傳回輸入字串,「取消」鈕傳回空字串。

  13. 8-1-2 InputBox對話方塊-Visual Basic專案 strValue = InputBox("請輸入金額?", "輸入金額") txtAmount.Text = strValue ' 輸入的金額 ' 計算利息 interest = CDbl(strValue) * CDbl(txtRate.Text) / 100.0 txtResult.Text = interest

More Related