Visual basic

2007-05-10 9:08 pm
What is the code of open the file menu

that means when we press on open file
and then come out a form ...

what is that source code to call for the form...

回答 (2)

2007-05-10 9:14 pm
✔ 最佳答案
Private Sub Form_Activate()
cdlCommon.CancelError =True
cdlCommon.Flags = cdlOFNHideReadOnly ' Hides read only files
cdlCommon.Filter = "All Files (*.*)|*.*|Text Files" & _
"(*.txt)|*.txt|Gatch Files (*.bat)|*.bat|"
' Specify default filter
cdlCommon.FilterIndex = 2
cdlCommon.ShowOpen
End Sub




you can change the 'txt' or 'bat' according what format of file you wanna open.
and note that u need to click on Projects, Components and scroll to the Microsoft Common Dialog Control 6.0. Place a check mark next to the control, click Apply and OK


Also, it's not a 'form' actually, but it's called a dialog box.
2007-05-10 9:13 pm
使用commondialog控制控便可, 範例如下,
CommonDialog 控制項方法範例
本範例使用 CommonDialog 控制項和 ShowColor、ShowFont、ShowHelp、ShowOpen、ShowPrinter 和 ShowSave 等方法,顯示通用型對話方塊。如果您想測試這個範例,就將程式碼貼上到表單的宣告部份,該表單帶有 CommandButton、OptionButton (設定該選項按鈕的 Index 屬性為 0)、以及 CommonDialog 控制項。按 F5 鍵,為所要的通用型對話方塊選擇選項按鈕,再選取指令按鈕。
 
Private Sub Form_Paint ()
Static FlagFormPainted As Integer
' 當第一次表單重繪時,
If FlagFormPainted <> True Then
For i = 1 To 5
Load Option1(i) ' 給陣列新增 5 個選項按鈕
Option1(i).Top = Option1(i - 1).Top + 350
Option1(i).Visible = True
Next i
Option1(0).Caption = "Open" ' 在每個選項按鈕上放置標題
Option1(1).Caption = "Save"
Option1(2).Caption = "Color"
Option1(3).Caption = "Font"
Option1(4).Caption = "Printer"
Option1(5).Caption = "Help"
Command1.Caption = "Show Dlg" ' 標籤指令按鈕
FlagFormPainted = True ' 表單重繪完畢
End If
End Sub

Private Sub Command1_Click ()
If Option1(0).Value Then ' 如果選擇「開啟舊檔」選項,
CommonDialog1.ShowOpen ' 顯示「開啟舊檔」通用型對話方塊。
ElseIf Option1(1).Value Then ' 否則,
CommonDialog1.ShowSave ' 顯示「另存新檔」通用型對話方塊。
ElseIf Option1(2).Value Then ' 否則,
CommonDialog1.ShowColor ' 顯示「色彩」通用型對話方塊。
ElseIf Option1(3).Value Then ' 否則,
CommonDialog1.Flags = cdlCFBoth ' 在使用ShowFont 方法之前,
' 必須將 cdlCFBoth、
' cdlCFPrinterFonts、
' 或 cdlCFScreenFonts
' 設定給 flags 屬性。
CommonDialog1.ShowFont ' 顯示「字型」通用型對話方塊。
ElseIf Option1(4).Value Then ' 或,
CommonDialog1.ShowPrinter ' 顯示「列印」通用型對話方塊。
ElseIf Option1(5).Value Then ' 或
CommonDialog1.HelpFile = "VB5.hlp"
CommonDialog1.HelpCommand = cdlHelpContents
CommonDialog1.ShowHelp ' 顯示「 Visual Basic 說明目錄主題」。
End If
End Sub


收錄日期: 2021-04-12 19:57:32
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070510000051KK01428

檢視 Wayback Machine 備份