DriveListBox Control, DirListBox Control, and FileListBox Control CommonDialog Control 1 2 DriveListBox Control disk drive Important Properties object.drive [= drive] Drive Floppy disks "a:" or "b:", and so on Fixed media "c: [volume id]" Network connections "x: \\server\share" Change DirListBox Control Important Properties object.path [= pathname] Path Change 1
FileListBox Control object.path [= pathname] Path Important Properties Path object.file [= pathname] object.pattern [= value] File1.Pattern="*.txt" File1.Pattern="*.com;*.bat" File Pattern Form_Load : Archive, Hidden, Normal, System object.archive [= boolean] object.hidden [= boolean] object.normal [= boolean] object.system [= boolean] Form_Load File1.Hidden= Click 2
Project properties Object Property Setting Form1 Form1 Label1 AutoSize BackStyle DriveListBox1 Drive1 DirListBox1 Dir1 FileListBox1 File1 Image1 CommandButton1 Poject code Stretch Private Sub Command1_Click() Image1.Picture = LoadPicture() Label1. = "" Label1 فزاغ يصبح الشزيط بحجم الكلمت شفاف يعكس لىن الخلفيت ورائه 0 Image1 لتأخذ الصىرة حجم االطار الذي يحىيها Command1 Delete Picture Private Sub Dir1_Change() File1.Path = Dir1.Path set file path Private Sub Drive1_Change() Dir1.Path = Drive1.Drive set directory path 3
Private Sub File1_Click() Path = File1.Path If Right$(Path, 1) <> "\" Then Path = Path + "\" Label1. = Path + File1.filename Image1.Picture = LoadPicture(Label1.) A=Path + File1.filename Image1.Picture = LoadPicture(A) Private Sub Form_Load() File1.Pattern = "*.bmp" CommonDialog Components Microsoft common dialog 5.0 Ctrl+T Components Project ToolBox ShowSave ShowPrinter ShowOpen ShowFont CommonDialog Control ShowHelp ShowColor Method ShowOpen ShowSave ShowColor ShowFont ShowPrinter ShowHelp Dialog Displayed Show Open Dialog Box Show Save As Dialog Box Show Color Dialog Box Show Font Dialog Box Show Print or Print Options Dialog Box Invokes the Windows Help Engine 4
Important Properties object.cancelerror [= boolean] The settings for boolean are: False Setting Description An error is generated. (Default) No error is generated. CancelError DialogTitle object.filter [= description1 filter1 description2 filter2...] CommonDialog1.Filter="Text (*.txt) *.txt Pictures (*.bmp;*.ico) *.bmp;*.ico" Filter Filter FilterIndex object.filterindex [= number] CommonDialog1.FilterIndex=0 256 32 1 MaxFileSize File FileTitle ShowColor Color ShowPrinter FromPage, ToPage object.frompage [= number] object.topage [= number] ShowPrinter Copy ShowFont ShowPrinter Max, Min object.min [= points] object.max [= points] object.min [= number ] object.max [= number ] 5
CommonDialog ShowColor ShowOpen Project properties Object Property Setting Form1 Form1 Label1 Label1 فزاغ AutoSize يصبح الشزيط بحجم الكلمت BackStyle شفاف يعكس لىن الخلفيت ورائه 0 CommonDialog1 CancelError cmd1 CommandButton1 Command1 Open CommandButton2 Command2 Image1 Stretch 6 Color Image1 لتأخذ الصىرة حجم االطار الذي يحىيها
Poject code Private Sub command1_click() On Error GoTo errorf2 cmd1.filename = "" cmd1.filter = "BMP Files (*.bmp) *.bmp" cmd1.filterindex = 0 cmd1.showopen On Error GoTo 0 dir Filter If Dir(cmd1.filename) = "" Then disable the error MsgBox "File not Exist", vbcritical + vbmsgboxright, "Error" Exit Sub End If Label1. = cmd1.filename Image1.Picture=LoadPicture(cmd1.filename) errorf2: Private Sub command2_click() On Error GoTo aa cmd1.showcolor On Error GoTo 0 Form1.BackColor = cmd1.color aa: 7
Sequential File Binary File Random File 1 2 3 Sequential File Project properties Object Property Setting Form1 Form1 Sequential File Text Box1 Text MultiLine Text1 فزاغ ScrollBars 3 Both Text Box2 Text MultiLine ScrollBars CommandButton1 CommandButton2 Poject code Private Sub Command1_Click() filenum = FreeFile Open "example.txt" For Output As filenum Print #filenum, Text1.Text Close filenum Private Sub Command2_Click() filenum = FreeFile Open "example.txt" For Input As filenum Text2.Text = Input$(LOF(filenum) - 2, filenum) 8 Text2 فزاغ 3 Both Command1 Save Command2 Load "example.txt" "example.txt"
Close filenum CommonDialog Project properties Object Property Setting Form1 Form1 CommonDialog1 CancelError Cmd1 Image1 CommandButton1 CommandButton2 Poject code Stretch Picture Private Sub Command1_Click() On Error GoTo errof2 cmd1.filename = "" cmd1.filter = "Bmp Files (*.bmp) *.bmp" cmd1.filterindex = 0 cmd1.showopen On Error GoTo 0 If Dir(cmd1.filename) = "" Then MsgBox "File not exist", vbcritical, "Error" Exit Sub End If Image1.Picture = LoadPicture(cmd1.filename) errof2: Image1 Command1 Load Picture Command2 Delete Picture 9
Private Sub Command2_Click() Image1.Picture = LoadPicture() CommonDialog CommonDialog Project properties Object Property Setting Form1 Form1 CommonDialog1 CancelError Cmd1 TextBox1 Text MultiLine ScrollBars Text1 3 Both TextBox2 Text MultiLine ScrollBars Text2 3 Both CommandButton1 Command1 Save CommandButton2 Command2 Load Label1 Autosize Label1 Label2 Autosize Label2 Poject code Private Sub Command1_Click() On Error GoTo errof1 cmd1.filename = "" cmd1.filter = "Text Files (*.txt) *.txt" cmd1.filterindex = 0 cmd1.showsave On Error GoTo 0 If Dir(cmd1.filename) <> "" Then قا "Overwrite") y = MsgBox("Overwrite File", vbquestion + vbyesno, If y = vbno Then Exit Sub End If ف ي حال ة وجوده ساب save file Label1. = "Saved file name:" + cmd1.filename filenum = FreeFile Open cmd1.filename For Output As filenum Print #filenum, Text1.Text Close filenum 0
errof1: Private Sub Command2_Click() On Error GoTo errof2 cmd1.filename = "" cmd1.filter = "Text Files (*.txt) *.txt" cmd1.filterindex = 0 cmd1.showopen On Error GoTo 0 If Dir(cmd1.filename) = "" Then ف ي حال ة عدم وجوده "error" MsgBox "File not exist", vbcritical, Exit Sub End If Load file Label2. = "Loaded file name:" + cmd1.filename filenum = FreeFile Open cmd1.filename For Input As filenum Text2.Text = Input$(LOF(filenum) - 2, filenum) Close filenum Text2.Text = Text2.Text + "good bye" errof2: 1
2