Page 75 - Open Soource Technologies 304.indd
P. 75

Unit 3: Understanding Controls and Control Events




               Place the code TextBox1.Text=”Welcome to Forms” in the Click event of the Button and run the
               application. When you click the Button the output “Welcome to Forms” is displayed in the
               TextBox.
               Alternatively, you can also use the  MsgBox or  MessageBox functions to display text when
               you click on the Button. To do that place a Button on the form and double-click on that to
               open it’s event. Write this line of code, MsgBox(“Welcome to Forms”) or MessageBox.
               Show(“Welcome to Forms”).
               It looks like this in code.

                 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
                 As _
                 System.EventArgs) Handles Button1.Click
                 MsgBox(“Welcome to Forms”)
                 End Sub
                 or
                 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
                 As _
                 System.EventArgs) Handles Button1.Click
                 MessageBox.Show(“Welcome to Forms”)
                 End Sub

               When you run the form and click the Button, a small message box displays, “Welcome to Forms”.
               The image below displays that.
























                                                   Figure 3.21

                              Make sure that the new filename has the extension "vb".





                                      LOVELY PROFESSIONAL UNIVERSITY                         69
   70   71   72   73   74   75   76   77   78   79   80