tailieunhanh - C# .NET Web Developer's Guide phần 3

Bạn cần phải đặt catch khối nhắm mục tiêu đến trường hợp ngoại lệ cụ thể trước khi một khối catch ngoại lệ chung, hoặc mô hình xử lý ngoại lệ Bạn có thể an toàn chạy mã trong các CLR bằng cách tạo ra các chương trình xử lý các trường hợp ngoại lệ. | 142 Chapter 4 Windows Forms Let s start the walkthrough by creating a new Windows Forms project. From the main menu choose File New Project click Visual C Projects and choose the Windows Application template see Figure . Change the project name to SimpleApp and click OK. Figure Creating a New Windows Forms Project Adding Controls Once we ve created the project Visual Studio opens the main form Forml in the Designer the visual editor for our C form class. Basically a form created in Visual Studio is just a C file defining a class based on containing code to add and configure the controls created Studio is a two-way tool meaning that we can work with the same code either visually using the Designer or programmatically in the Code Editor . Let s use the Designer to add a few controls to can add controls and components from the toolbox window and then configure them using the Properties window. 1. From the toolbox add a Label control to the form. By default Visual Studio will name the control Labell. 2. From the Properties Window F4 change labelTs Text property to Favorite CD and change its AutoSize property to True see Figure . This tells the control to size itself according to the metrics of the font and width of the text. Windows Forms Chapter 4 143 Figure Adding and Configuring a Label Control 3. Now add a TextBox from the toolbox onto the form and position it below the label. Enlarge it horizontally and clear its Text property. 4. Add another label to the form setting its Text property to Favorite Style and AutoSize property to True. 5. Add a ComboBox and position it below the Favorite Style label. Clear its Text property. 6. Select the combo s Items property and then click the ellipses on the right to open the String Collection Editor. Type in a few styles of music each on a separate line as shown in Figure . 7. Click OK and then press F5 to save compile and run the .

TỪ KHÓA LIÊN QUAN