form1.cs

来自「清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码」· CS 代码 · 共 101 行

CS
101
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Forms;
using Microsoft.WindowsMobile.Status;
using Microsoft.WindowsMobile.Samples.Location;

namespace CameraApp
{
    public partial class Form1 : Form
    {
        private Gps gps = new Gps();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            gps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
            gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
            gps.Open();
        }

        void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            //invoke our handler on the UI thread
            this.Invoke(new LocationChangedEventHandler(OnLocationChanged), new object[] { sender, args });
        }

        void OnLocationChanged(object sender, LocationChangedEventArgs args)
        {
            statusBar1.Text = "Lat/Lon: " + args.Position.Latitude.ToString("f5") + ", " + args.Position.Longitude.ToString("f5");
        }

        void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
        {
            //invoke our handler on the UI thread.
            this.Invoke(new DeviceStateChangedEventHandler(OnDeviceStateChanged), new object[] { sender, args });
        }

        void OnDeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
        {
            switch (args.DeviceState.DeviceState)
            {
                case GpsServiceState.On:
                    this.BackColor = Color.Green;
                    break;
                case GpsServiceState.Off:
                case GpsServiceState.ShuttingDown:
                case GpsServiceState.Uninitialized:
                case GpsServiceState.Unloading:
                    this.BackColor = Color.Red;
                    break;
                case GpsServiceState.StartingUp:
                    this.BackColor = Color.Yellow;
                    break;

            }
        }

        private void mnuCapture_Click(object sender, EventArgs e)
        {
            CameraCaptureDialog ccd = new CameraCaptureDialog();
            ccd.Mode = CameraCaptureMode.Still;
            ccd.StillQuality = CameraCaptureStillQuality.High;
            ccd.Title = "Say Cheese";

            if (ccd.ShowDialog() == DialogResult.OK)
            {
                pbImage.Image = new Bitmap(ccd.FileName);
            }
        }

        private void mnuChoose_Click(object sender, EventArgs e)
        {
            int signal = SystemState.PhoneSignalStrength;

            SelectPictureDialog spd = new SelectPictureDialog();
            spd.Owner = this;
            spd.Title = "Select a picture";
            spd.CameraAccess = false;
            spd.LockDirectory = true;

            if (spd.ShowDialog() == DialogResult.OK)
            {
                pbImage.Image = new Bitmap(spd.FileName);
            }
        }

        private void mnuLocation_Click(object sender, EventArgs e)
        {
            GpsPosition p = gps.GetPosition();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?