Compact 2013 Ebook

17.2 C# GetTime App
Created by djones on 6/26/2013 5:29:11 AM

Managed Code C# GetTime Application

In this activity the GetTime application as implemented in the native code and XAML chapters, is implemented as a Managed Code C# .NET CF application.

Create the Application

  1. In application development IDE, create a new project: File—>New Project
  2. Under C#, locate the Windows Embedded Compact/SDK and select Device Application 
    image
    Figure 17.1
  3. Call the project ManagedTime and finish [OK].
  4. Open the form (form1) in the Visual Designer.
  5. Create the UI for the application as shown: 
    image
    Figure 17.2
    • The controls are
      • A label (Local Time:)
      • A TextBox (textBox1)
      • Two Buttons, called TimeButton and ExitButton
    • Set the Text property of the form to ManagedTime
  6. At the bottom of the Visual Designer window, locate the Menu control icon and delete it.
    As we have no menu, this just takes up space at the top of the form and may impinge upon what the TextBox displays..
  7. Create the event handlers for the buttons by in the Visual Designer double-clicking on the buttons
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ManagedTime
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void TimeButton_Click(object sender, EventArgs e)
            {
    
            }
    
            private void ExitButton_Click(object sender, EventArgs e)
            {
    
            }
        }
    }

    Listing 17.1 The C# code behind with the button event handlers.


  8. Implement the TimeButton event handler by inserting the following code:
    textBox1.Text = DateTime.Now.ToString();
    Listing 17.2 The C# TimeButton event handler code.


  9. Implement the ExitButton event handler by inserting the following code:
    Application.Exit();

    Listing 17.3 The C# ExitButton event handler code.

  10. Set the application in Debug mode (default) and build the application


    Run the Application

    Now to run the application on the target device using CoreCon.
    Refer the 16.4 CoreCon Application Development Connectivity.

  1. Boot the target and get its IP Address:
    On the OS development system) Target—>Target Control—>IpConfig /d 
    The IP Address will appear on the OS Output Debug Window
  2. Start CoreCon on the target
  3. (Back on the app development system) In the property pages of the app project,
    Enter the IP address of the target.
    Alternatively, just enter it when prompted when you run the app. 
  4. Check the connectivity by attempting to deploy the app:
    From the project context—>Deploy
    The app should successfully deploy
  5. Run the application (eg press F5 etc.)
  6. Test the app functionality, including exit.
    image
    Figure 17.3 The ManagedTime app running

  7. Place a Breakpoint in the TimeButton event handler, run the app in Debug mode and determine that the debugging works.
  8. From the Project Context(Right-click on it in Solution Explorer)—>Run app
  9. From the Project Context(Right-click on it in Solution Explorer)—>Step into the application
  10. Browse into the bin/Debug directory and double-click on ManagedTime.exe to run it on the desktop!

    The local time has been formatted as a string in its default format. To explicitly format as per the previous chapters use a format string. A format string is similar to printf format string. Instead of %d, %s etc. the parameters to be formatted in the string are listed in it in braces numbered from zero.
  11. Modify the the TimeButton event code by replacing it with the following code:
                DateTime localTime = DateTime.Now;
    
                string dateTimeStr = string.Format(
    
                    "Time  {0}:{1}:{2} Date  {3}/{4}/{5}",
    
                    localTime.Hour, localTime.Minute, localTime.Second,
    
                    localTime.Day, localTime.Month, localTime.Year);
    
                textBox1.Text = dateTimeStr;
    

    Listing 17.4 The revised C# TimeButton event handler code using a formatted string 
    image
  12. Rebuild the application and test run it. 


    Figure 17.4

More:  17.3 Managed Code VB GetTime Application

print

Click here to provide feedback and input

  Comments

There is no comment.

Turkish porno izle video site in rokettubeporno izle