tailieunhanh - Wrox’s Visual Basic 2005 Express Edition Starter Kit phần 4

Ví dụ, tên, ngày sinh, và số điện thoại là tất cả các thuộc tính của một đối tượng Person. Phương pháp - Một chức năng thuộc một đối tượng có thể được gọi bởi các phần khác của chương trình. Thông thường, phương pháp sẽ thực hiện một hành động | Take Control of Your Program Using classes enables you to segregate information and actions into a self-contained unit. This unit can then be used by anything that has access to it. If you keep each class in a separate class module you can then import just the ones you want into each project. For example if you wanted to build another application in the future that used the same Person class as the Personal Organizer application it wouldn t be as easy to use if the Person class was defined in the main form s file because you would need to include the whole thing. It is usually acceptable to keep classes that work together in one physical file. This means you could keep the Person class and the PersonList class in the same file if that fits your own style of organization. You can even define classes within classes if that makes sense to your application s design. Internal classes of this type are normally defined as Private so they can be accessed only within the main class functionality. To add a class file to your project use the Project o Add Class menu command or right-click the project in the Solution Explorer and choose Add o Class from the submenu. Either method will present you with the Add New Item dialog with the empty class template highlighted see Figure 6-1 . Name the class something appropriate to the kind of object you are defining and click Add to add it to the project. Figure 6-1 The new class file will be added to the Solution Explorer window and you ll be able to access the code for it through the context menu or by clicking the View Code button at the top of the Solution Explorer. Selecting the class file will also change the context of the Properties window where you can set a couple of properties that control how the class is built and the name of the file if you wanted to change it later. When you add a class module by default it adds an empty class with the same name and defines it as Public which means any other part of the application can .

TỪ KHÓA LIÊN QUAN