If you uncheck the Enable application framework field on that same properties form, the Startup Form list changes to include any class in your application with a compatible Main routine. If you want to add a custom Main routine to your form, or to some other non-Form class in your application, that's no problem. Visual Basic will write a simple Main routine on your behalf that will display the indicated form. But wait, you haven't added a Main method to any of your forms? No problem. It includes a list of all forms just choose the one you want. You indicate which form's Main routine is used through the Startup Form field. NET application begins, the Framework calls a method named Main somewhere in your code. The startup options for a Windows Forms application (The project properties window appears when you select the Project Properties menu command in Visual Studio, or when you double-click on the "My Project" item in the Solution Explorer.)įigure 7-3. NET know which of your forms should appear first when your program first runs? You indicate the starting location through the project's properties, via the Startup Form field on the Application tab (see Figure 7-3). Check out the routine periodically to see how it changes. Any custom design-time changes made to Form1's user interface, such as adding child controls, are added to the InitializeComponent procedure automatically as you use Visual Studio. This project's initial form, Form1, inherits from that base form, receiving all of Form's functionality and default settings. _ Private Sub InitializeComponent() components = New () Me.AutoScaleMode = _ .Font Me.Text = "Form1" End Sub End ClassĪll of the code that implements a form's behavior appears in the Form class in the namespace. Partial Public Class Form1 Inherits 'Required by the Windows Form Designer Private components As 'NOTE: The following procedure is required by 'the Windows Form Designer 'It can be modified using the Windows Form Designer. Some of the most interesting code is in the "" file, slightly edited here. If you click on the "Show All Files" button in the Solution Explorer panel (described way back in Chapter 1, Figure 1-13) and open the various files in the project, you can see the code for yourself. At this point, Visual Studio has already added about 250 lines of source code to your application. The new project has a single form ("Form1") all ready for you to use. Give the project any name you want in the Name field, and then click OK. The New Project form appears, as shown in Figure 7-2.įigure 7-2. Start Visual Studio and select New Project. Designing Windows Forms ApplicationsĬreating a Windows Forms application in Visual Basic is easy. I'll list the specific controls a little later in this chapter, and indicate which ones are not user interface controls. These controlssuch as the "Timer" controlinclude no user interface experience, but do provide a programming experience that is similar to that of the visible controls. NET (and also with the older Visual Basic) don't actually implement on-screen window elements. Both forms and controls derive from the common class, which abstracts the core Windows "window" functionality. If you don't believe me, check out the classes for the various forms and controls in. NET, as in older versions of Visual Basic, windows are grouped into "Forms" and "Controls." But they are still all windows, built from the same core components. You could commandeer any of these components and control the whole ball of wax yourself, but you'll soon find out that the Windows Forms development process is so pleasant, you will work hard to forget what "message pump" even means. The message pump is found in the .Run method. Each window-specific class includes a WndProc method that you can override and craft yourself. If you really want to, you can still access the message pump and the various WndProc routines. Many of these classes implement specific types of windows, such as ordinary main windows, buttons, text boxes, drop-down combo box lists, and so on. All of its classes appear in the namespace. It bundles up all this power and simplicity in a technology called Windows Forms. NET Framework uses a system that is quite similar to that of older Visual Basic implementations, having the WndProc call custom event handlers written by you. Microsoft did try to mask some of the tedium with a variety of technologies, including "Message Crackers" and "MFC." It was Visual Basic that finally succeeded in burying the complexity under a programmer-friendly logical system. Take it from someone who used to write Windows applications in the 'C' language: Writing message pumps and window procedures isn't a lot of fun.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |