Intro to Visual Studio.Net for Domino Designers Hands on Labs

Document Sample
Intro to Visual Studio.Net for Domino Designers Hands on Labs Powered By Docstoc
					Microsoft
Microsoft
Contents

Exercise 1 - Getting Started.......................................................................................................................... 3

Exercise 2 - Controls as Objects .................................................................................................................. 9

Exercise 3 - Some More .NET Objects ........................................................................................................ 12

Exercise 4 - Breakpoint............................................................................................................................... 15

Exercise 5 - Optional .................................................................................................................................. 17




Visual Studio Hands on Labs                                                                                                                     Page 2
Exercise 1 - Getting Started



1.      Start Visual Studio by clicking Start-Microsoft Visual Studio 2005-Microsoft Visual Studio 2005




2.      Select Project next to Create.




3.      In the New Project Dialog, select “Visual Basic” as the Project type

4.      In the New Project Dialog, pick “Window Application” as the Template

5.      In the New Project Dialog, enter “My Windows Application” in the Name field

Visual Studio Hands on Labs                                                                        Page 3
6.     In the New Project Dialog, click “OK”




7.     When Form1 appears, expand its size by dragging its lower right corner.




Visual Studio Hands on Labs                                                      Page 4
8.     Open the tool box, locate and drag 2 buttons, 2 textboxes, and a data picker control onto the
       form. It should look something like this:




9.     Select Button1 and locate its Text Property in the Properties window.

10.    Change the Text property value from Button1 to Go.




11.    Button1 now has the label text of “Go”. Double click the Go button to see the code for the click
       event.

Visual Studio Hands on Labs                                                                      Page 5
12.    We will be entering code in the Button1_Click Sub. When entering code, please type it (not cut
       and paste) to see auto-complete options. Enter the code:



MsgBox(DateTimePicker1.Text)


13.    Then click on the triangle    to start the debugger.




Visual Studio Hands on Labs                                                                     Page 6
14.    The result when you click the Go button is a message box:




15.    Change the Date picker value and try the button again.

16.    Close the Form1 window to end the debugging session.

17.    Now comment out your MsgBox line of code with a “ ’ ” just like in LotusScript.

18.    Enter a new line of code:

Visual Studio Hands on Labs                                                              Page 7
        MessageBox.Show(

19.    Notice how auto-complete helps you type. Once you type the (, a dialog box appears to show
       you the many ways you can use the MessageBox.Show method. Try clicking on the down
       triangle   to see some of the ways to use this method.

20.    When you are done looking, go back to number one and enter DateTimePicker1.Text

       So our code line looks like MessageBox.Show(DateTimePicker1.Text)




1.     Again run the debugger to test your project.



MessageBox is part of the .NET framework.




Visual Studio Hands on Labs                                                                  Page 8
Exercise 2 - Controls as Objects



The .NET framework gives you abundant objects to work with not unlike the Domino Objects
you use with LotusScript.

1.      Back in the code window, change the Form1 events pull down from “(Declorations)” to “New”.
        A code stub appears.

2.      After the comment for initialization, add these two lines of code:

        TextBox1.Text = Button2.Location.X.ToString

        TextBox2.Text = Button2.Location.Y.ToString




3.      Back in our Button1_Click code add:



Button2.Left = Convert.ToInt16(TextBox1.Text)
Visual Studio Hands on Labs                                                                  Page 9
Button2.Top = Convert.ToInt16(TextBox2.Text)




4.     Debug your applications

5.     Push the Go button then change the values in text box 1 and 2 to see what happens.

6.     Try the values seen below:




Visual Studio Hands on Labs                                                                 Page 10
7.     Close the Form1 window to stop debugging.



As you can see, the controls are objects we can manipulate through their Methods and
Properties with code.




Visual Studio Hands on Labs                                                            Page 11
Exercise 3 - Some More .NET Objects



1.     Go back to our Button1_Click code and comment out the 2 lines of code we just added.

2.     Add the following lines of code:

            Dim myvalue As New Random

            Dim h As Int16 = Me.Size.Height

            Dim w As Int16 = Me.Size.Width

            Button2.Left = myvalue.Next(w)

            Button2.Top = myvalue.Next(h)




Dim myvalue As New Random

This code creates an object called myvalue from the class “Random”. This is just like when you
create a Notes Session [Dim s As New NotesSession] with LotusScript. In that case you are
creating an object called s form the class NotesSession. As you know, when you have your

Visual Studio Hands on Labs                                                                   Page 12
Session object, you have access to all its Methods and Properties. The same applies here. The
myvalue object has all the Methods and Properties of the “Random” class.



Dim h As Int16 = Me.Size.Height

Dim w As Int16 = Me.Size.Width

These 2 lines of code collect the height and width of the Form1 window. “Me” refers to the
current class the code is running in, in this case Form1.

Button2.Left = myvalue.Next(w)

Button2.Top = myvalue.Next(h)

Here we are setting the X/Y location of Button2. We use the “Next” Method of the Random
class instance object called myvalue. The parameter is the maximum value to return. By
setting the size of our form in the maximum random value parameter, we keep the button on
the form.

3.     Debug your application

4.     Push the Go button several times to see the result.




Visual Studio Hands on Labs                                                            Page 13
5.     Close the debug window.




Visual Studio Hands on Labs      Page 14
Exercise 4 - Breakpoint



1.     Go back to our Button1_Click code and click on a line of code and press F9 [or just click on the
       margin next to the line you want to add the breakpoint to]. This sets a breakpoint [this is
       simular to putting the “Stop” command in your LotusScript+




2.     Debug your application

3.     Press the Go button. The debugger will break into the executing code so you can inspect the
       current state. Hover over some of the variable in the code and you will see their current values.




Visual Studio Hands on Labs                                                                      Page 15
4.     You can use the icons circled here to “Step Into”, “Step Over”, and “Step Out” of the running
       code. *If your Visual Studio preferences are set up for VB, you can use the same “F” keys as you
       do in Domino Designer]

5.     Look around the debug environment (try right clicking)

1.     will continue execution

2.     When done, close the debugging session with the       icon or just close the Form1 window.




Visual Studio Hands on Labs                                                                     Page 16
Exercise 5 - Optional



1.      Add a Timer control to your form. Double click the control to get to the Timer control code.

2.      Copy your button move code to the Timer1_Tick Sub:

Dim myvalue As New Random

        Dim h As Int16 = Me.Size.Height

        Dim w As Int16 = Me.Size.Width

        Button2.Left = myvalue.Next(w)

        Button2.Top = myvalue.Next(h)

3.      In the property window for the Timer1 control, set the interval to 1500 and Enabled to True.

4.      Now start the debugger

5.      If you have time, add code to Button2 to count the number of clicks and put the result in a
        textbox.

6.      Programmatically change the interval to be shorter as the number of Button2 clicks increases.



You now have a very basic game that has you chasing Button2.

Update your resume to say you have VS.NET experience.




Visual Studio Hands on Labs                                                                      Page 17

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:9
posted:10/13/2011
language:English
pages:17