RSS


[ Pobierz całość w formacie PDF ]
.NET Appl i cati on 35Figure 2.11The Hello World application running.Notice that a new window is showing.At the bottom of the screen, an Output win-dow is now open.Figure 2.12 shows this window.Currently, it shows you all thedebug statements.You did not put any debug.print statements into your code, butcertain actions by the complier automatically put comments into the Debug window.Figure 2.12The new Debug window. 03 2203-x CH02 5/25/01 9:58 AM Page 3636 Chapter 2: Your Fi rst VB.NET Appl i cati onBefore moving on, you might want to change the title of the message box.Return tothe one line of code you ve written so far and modify it to look like this:MsgBox( Hello, World , ,  My first VB.NET App )Now that you have added a title to the message box, run the project again, and thetitle of your message box will be My first VB.NET App.If you think it doesn t getany better than this, hang on.Windows Application EnhancementsVisual Studio.NET has added a variety of features to VB.NET to make the IDE morepowerful and to enhance the functionality of Windows forms.There is improved sup-port for features such as building menus, automatically adjusting to changes in thesize of the text to display, better anchoring of controls for resized windows, and amuch-improved mechanism for setting the tab order.Resizing Controls AutomaticallyYou can set certain controls to resize automatically based on what they need to dis-play.This is easy to examine with a simple label.Open the Toolbox and add a labelto your form.Drag it over to the left side of the form, so that it is not in line with thebutton.Now, change some properties of that label.Change the BorderStyle to FixedSingle,and set AutoSize to True.Change the Text property to This is a test.You mighthave noticed that you changed the Text property, and not a Caption property as youdid in VB versions 1 6.Welcome to another one of those little changes that mighttrip you up.Now, modify the code for the button1_Click event.Remove the MsgBox call and addthe following code:label1().Text =  Put your hand on a hot stove  & _ for a minute, and it seems like an hour. & _ Sit with a pretty girl for an hour, and  & _ it seems like a minute.THAT S relativity.Before you run this, realize one more thing about the code.In VB6, it would havebeen legal to say this:Label1 =  Put your hand on a hot stove.This would run just fine in VB6 because the default property of Label1 was theCaption property.Well, in VB.NET, there is no such thing as a default property.Therefore, you always have to specify the property when you write your code. 03 2203-x CH02 5/25/01 9:58 AM Page 37Wi ndows Appl i cati on Enhancements 37Go ahead and run the project.A form will appear that is similar to what you see inFigure 2.13.Now, click Button1 and notice that the text in the label changed, whichis no big surprise.However, notice that the label has grown to try to hold all the text.If you resize the form, you will see that the label has indeed grown to show all thetext.Figure 2.14 shows this to be the case.Figure 2.13A form with a small amount of text in a label.Figure 2.14The same form, showing the label has grown to contain all the text. 03 2203-x CH02 5/25/01 9:58 AM Page 3838 Chapter 2: Your Fi rst VB.NET Appl i cati onIf you re saying that this isn t a big deal, think of the code you had to write before.You had to check the length of the string, but you also had to be aware of what fontwas in use.A group of characters in Arial is not the same length as the same group ofcharacters in Courier.Therefore, resizing could be a hit-or-miss proposition.TheAutoSize property removes that guesswork for you.Anchoring Controls to the Form EdgesHow many times did you create a VB form and set the border style to fixed so thatpeople couldn t resize it? If you placed a series of buttons along the bottom of theform, you didn t want people to resize the form and suddenly have this bottom rowof buttons in the middle of the form.VB.NET allows you to anchor controls to one or more sides.This can allow a controlto move as the form is resized, so that it appears to stay in its proper place.Back on Form1, delete the label you added, and remove the code inside theButton1_Click event procedure.Make the form slightly bigger and move Button1toward the lower-right corner.Now, add a TextBox to the form.Change theTextBox s Multiline property to True and resize the text box so that it fills up mostof the form, except for the bottom portion that now contains the button.Your formshould now look something like the one shown in Figure 2.15.Figure 2.15The form as it looks at design time [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • nvs.xlx.pl