ดาวน์โหลดงานนำเสนอ
งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ
ได้พิมพ์โดยKamala Taksin ได้เปลี่ยน 10 ปีที่แล้ว
1
อาจารย์สายสุนีย์ เจริญสุข
2
Writing Windows Applications with Visual Basic
The Windows GUI Text boxes Frame Labels Option buttons Check boxes Command buttons Image Picture box List box Menu bar Drop-down list Command button
3
Graphic User Interface
Graphic User Interface (GUI) comprises Forms Controls Event-driven programming
4
Planning Visual Basic Projects
The three-step process for planning projects Design the user interface Sketch the screens with forms and controls needed Establish the objects' properties Write down the properties for each object Plan the Basic code Write out pseudocode for actions your program will perform
5
Writing Visual Basic Projects
The three-step process for writing projects Design the user interface Create the forms and controls you previously sketched Set the objects' properties Give each object a name and set their properties Write the Basic code Write out Visual Basic code to carry out your application's actions Writing Visual Basic projects is a three step process: Define the interface, set the controls’ properties, and write Visual Basic code. Each Visual Basic project consists of at least two files: a project file and a form file. The project file ends with the extension .VBP, and the form file(s) end with the extension .FRM. Standard code modules are code files that are used by more than one form in a project. They end in .BAS A project file is small and holds the names of all files in the project. A form file holds all the objects on the form as well as the Basic code that is associated with the form. It is an ASCII form you can view with Notepad. It is a good idea to keep each project in its own directory, because it is difficult to tell which files, modules, etc. belong to each project if they are all kept in one directory.
6
Visual Basic Projects Visual Basic projects create several files
Project file: .VBP Holds the names of other files in the project Form files: .FRM Each form is saved as a separate file Form file contains a description of a form's objects and the Basic code attached to a form Standard code module: .BAS (optional) Custom controls: .OCX (optional) Resource File: .res Class Module : .cls
7
The Visual Basic Environment
Form, Project Explorer, Properties, and Form Layout Windows Toolbox Main Visual Basic window Toolbar, Form location & size information Help Design- , Run- , and Break Time Each VB window can be moved, resized, opened, and closed. A. The Form window contains forms that are the user interface. B. The Project Explorer window holds the filenames for the files in your project. C. The Properties Window sets the properties for your project's objects. D. The Form Layout window determines the position of the form on the desktop. E. The Toolbox holds the tools that you use to place controls on a form. A B D E C
8
Set Up Your VB Workspace
Set up Options to reflect these settings: If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
9
Write Code You write code enclosed in event procedures, which respond to typical VB events. Private Sub cmdPush_Click() . . . (your code goes here) End Sub VB automatically supplies the event procedure Sub/End Sub statements Remark statement is any code line beginning with an apostrophe Assignment statement End statement
10
Write Code Object Event Code
If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable. Code
11
ตัวอย่าง
12
Toolbox Pointer PictureBox Label TextBox Frame CommandButton
OptionButton Check Box ComboBox ListBox HScrollBar VScrollBar Timer DriveListBox If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable. DirListBox FileListBox Shape Line Data Image OLE
13
ตาราง Prefix ที่ใช้ก่อนชื่อ Object ใน Control
Combo Box cbo Check Box chk CommandButton cmd Directory ListBox dir Drive ListBox drv File ListBox fil Frame fra Form frm Ole Client Ole Option button Opt Vertical Scrollbar vsb Control Prefix Grid grd Horizontal Scrollbar hsb Image img Lable lbl Line lin List Box lst Menu mnu Picture box Pic Shape Shp Timer tmr Text Box txt
14
Basic Control Label : มีหน้าที่แสดงข้อความที่ผู้ใช้ไม่สามารถแก้ไขได้ มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล AutoSize: ให้ปรับขนาดภาพความยาวของข้อความหรือไม่ Caption: กำหนดข้อความที่จะแสดงผลบนจอภาพ Font: กำหนดชนิด ขนาด และลักษณะพิเศษของตัวอักษร ForeColor: ใช้สำหรับกำหนดสีของตัวอักษร BackColor: ใช้สำหรับกำหนดสีฉากหลัง If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
15
Basic Control Text Box : เป็นControl สำหรับรับหรือแสดงข้อความต่างๆ มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล Enabled: กำหนดให้คอนโทรลทำงานได้หรือไม่ Max Length: กำหนดความยาวสูงสุดของข้อความที่ป้อนได้ Visible: กำหนดให้แสดงผลคอนโทรลนี้ให้เห็นหรือไม่ Text : เก็บข้อความที่แสดงในช่องพิมพ์ของคอนโทรล MultiLine: กำหนดให้คอนโทรลมีหลายบรรทัดได้หรือไม่ If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
16
Basic Control Command Button : เป็นปุ่มคำสั่ง มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล Caption: แสดงข้อความบนปุ่ม Enabled: กำหนดให้คอนโทรลทำงานได้หรือไม่ Picture: ระบุชื่อไฟล์ภาพที่จะนำมาแสดงบนปุ่ม Style : กำหนดการแสดงข้อความและภาพบนปุ่ม ToolTipText: แสดงข้อความอธิบายเมื่อนำเมาส์ไปชี้ If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
17
Basic Control Option Button : สำหรับให้ผู้ใช้เลือกตัวเลือกใดตัวหนึ่งเท่านั้น มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล Caption: กำหนดข้อความที่ต้องการให้แสดง Value : ระบุว่าคอนโทรลนี้ถูกเลือกหรือไม่ If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
18
Basic Control CheckBox : สำหรับให้ผู้ใช้เลือกได้มากกว่า 1 ทางเลือก
มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล Caption: กำหนดข้อความที่ต้องการให้แสดง Value : ระบุว่าคอนโทรลนี้ถูกเลือกหรือไม่แบ่งเป็น 0 = Unchecked ไม่คลิกเลือก 1 = Checked คลิกเลือก 2 = Grayed คลิกเลือกและเป็นสีเทา If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
19
Basic Control Image : สำหรับอ่านไฟล์รูปภาพ มีคุณสมบัติที่สำคัญดังนี้
Name: ชื่อของคอนโทรล Picture : กำหนดไฟล์รูปภาพ Stretch : กำหนดภาพในการย่อขยาย PictureBox : สำหรับอ่านไฟล์รูปภาพ มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล Picture : กำหนดไฟล์รูปภาพ AutoSize: กำหนดภาพแสดงได้ทั้งหมดให้เป็น True If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
20
Basic Control Command Button : เป็นปุ่มคำสั่ง ทดลองเขียนโปรแกรมเพื่อจะได้เข้าใจในส่วนของ Property “Name” เช่น Private Sub cmdShow_Click() cmdShow.Caption = “อาจารย์สายสุนีย์ เจริญสุข” End Sub หมายเหตุ สามารถเปลี่ยนให้แสดงชื่อที่ Form,TextBox, Label เป็นต้นได้ให้นักศึกษาทดลองทำ If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
21
Basic Control ListBox : สำหรับให้ผู้ใช้เลือกเช่นเดียวกับ OptionButton แต่จะมีทางเลือกได้มากเนื่องจากสามารถเพิ่มเติมได้ มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล List : ใช้กำหนดข้อมูลให้กับ ListBox If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
22
Basic Control ComboBox : สำหรับให้ผู้ใช้เลือกซึ่งมีรูปแบบของ TextBox และ ListBox มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล Style : กำหนดรูปแบบการเลือกข้อมูลแบ่งเป็น 0=DropDown Combo คือจะมีรูปแบบทั้ง TextBox และ ListBox 1=Simple Combo คือจะมีรูปแบบ TextBox อย่างเดียว 2=DropDown List คือจะมีรูปแบบ ListBox อย่างเดียว List : ใช้กำหนดข้อมูลให้กับ ComboBox If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
23
Basic Control HScrollBar และ VScrollBar : โดย
มีคุณสมบัติที่สำคัญดังนี้ Min : กำหนดให้ระยะสั้นสุด Max: กำหนดให้ระยะยาวสุด Value : ค่าที่เลื่อน ScrollBar If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
24
Basic Control Line : เป็น Control ที่ใช้วาดเส้น
มีคุณสมบัติที่สำคัญดังนี้ Name: ชื่อของคอนโทรล BorderStyle : ใช้กำหนดรูปแบบเส้น BorderWidth : ความหนาของเส้น If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable. Timer : เป็น Control ที่ไม่ปรากฏบนจอภาพเมื่อทำการ Run โดยทำหน้าที่เป็นตัวจับเวลาเพื่อกำหนดการทำงานของโปรแกรมตามช่วงเวลาที่กำหนด
25
Basic Control Shape: ใช้วาดรูปภาพทางเรขาคณิต โดยกำหนด Property “Shape” มี 6 รูปดังนี้ 0 = Rectangle คือ รูปสี่เหลี่ยมผืนผ้า 1=Square คือ รูปสี่เหลี่ยมจัตุรัส 2=Oval คือ รูปวงรี 3=Circle คือ รูปวงกลม 4=Rounded Rectangle คือ รูปสี่เหลี่ยมผืนผ้าที่มีมุมมน 5=Rounded Square คือ รูปสี่เหลี่ยมจัตุรัสที่มีมุมมน If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
26
Basic Control DriveListBox จะทำหน้าที่เป็น Drop-Down ListBox ที่แสดง Drive ต่างๆ DriveListBox จะทำหน้าที่เป็น Drop-Down ListBox ที่แสดง Drive ต่างๆ If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable. FileListBox ใช้แสดงชื่อ File ใน Directory ที่เลือกไว้ใน DirlistBox
27
Basic Control OLE (Object Linking and Embedding): สำหรับเรียกโปรแกรมอื่นทีทำงานบนระบบปฏิบัติการ Window ทดลองโดยวาด Control “OLE” ลงใน Form เลือก OptionButton “Create from File” คลิกปุ่ม Browse เลือกไฟล์ “Calc” ใน Directory Windows คลิกที่ Check Box “Display As Icon” If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
28
การสร้างเมนู Menu Editor มีส่วนที่น่าสนใจดังนี้
Caption : ใช้สำหรับใส่ข้อความที่จะใช้เป็นเมนู เช่น ข้อความ File,Edit,View เป็นต้น ข้อความใดต้องการขีดเส้นใต้ให้ใส่ “&” นำหน้า Name : ใช้สำหรับกำหนดชื่อให้กับแต่ละเมนูซึ่ง VB ถือว่าแต่ละเมนูคือ 1 Object Shortcut: จะอยู่ในรูปของ Drop-Down List ซึ่งใช้กำหนด Hot Key ให้กับเมนูเช่น Alt-X If the Project Explorer window is not visible, then click the View menu and then select Project Explorer. If the Properties window is not visible, then open the View menu and then select Properties Window. If the toolbox is not visible, then then open the View menu and then select Toolbox. Maximize the form in the center of the VB workspace. Notice that the Visual Basic title bar displays the project and form titles. You can adjust both the size and the location of the windows. You may find that the Form Layout window is not too useful. You can click its close button to provide more space for the Properties window. You will work with and refer to the Properties window a lot, so it is a good idea to enlarge that window as much as is reasonable.
งานนำเสนอที่คล้ายกัน
© 2024 SlidePlayer.in.th Inc.
All rights reserved.