⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码
💻 VB
字号:
Public Class Form1

    Private gps As Gps

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.gps = New Gps

    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        gps.Close()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        AddHandler Me.gps.DeviceStateChanged, New DeviceStateChangedEventHandler(AddressOf Me.gps_DeviceStateChanged)
        AddHandler Me.gps.LocationChanged, New LocationChangedEventHandler(AddressOf Me.gps_LocationChanged)
        Me.gps.Open()
    End Sub

    Private Sub gps_DeviceStateChanged(ByVal sender As Object, ByVal args As DeviceStateChangedEventArgs)
        MyBase.Invoke(New DeviceStateChangedEventHandler(AddressOf Me.OnDeviceStateChanged), New Object() {sender, args})
    End Sub

    Private Sub gps_LocationChanged(ByVal sender As Object, ByVal args As LocationChangedEventArgs)
        MyBase.Invoke(New LocationChangedEventHandler(AddressOf Me.OnLocationChanged), New Object() {sender, args})
    End Sub

    Private Sub OnDeviceStateChanged(ByVal sender As Object, ByVal args As DeviceStateChangedEventArgs)
        Select Case args.DeviceState.DeviceState
            Case GpsServiceState.Off, GpsServiceState.ShuttingDown, GpsServiceState.Unloading, GpsServiceState.Uninitialized
                Me.BackColor = Color.Red
                Exit Select
            Case GpsServiceState.On
                Me.BackColor = Color.Green
                Exit Select
            Case GpsServiceState.StartingUp
                Me.BackColor = Color.Yellow
                Exit Select
        End Select
    End Sub

    Private Sub OnLocationChanged(ByVal sender As Object, ByVal args As LocationChangedEventArgs)
        Me.statusBar1.Text = ("Lat/Lon: " & args.Position.Latitude.ToString("f5") & ", " & args.Position.Longitude.ToString("f5"))
    End Sub

    Private Sub mnuCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCapture.Click

        Dim ccd As New CameraCaptureDialog
        ccd.Mode = CameraCaptureMode.Still
        ccd.StillQuality = CameraCaptureStillQuality.High
        ccd.Title = "Say Cheese"
        If (ccd.ShowDialog = DialogResult.OK) Then
            Me.pbImage.Image = New Bitmap(ccd.FileName)
        End If

    End Sub
    Private Sub mnuChoose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuChoose.Click

        Dim signal As Integer = SystemState.PhoneSignalStrength
        Dim spd As New SelectPictureDialog
        spd.Owner = Me
        spd.Title = "Select a picture"
        spd.CameraAccess = False
        spd.LockDirectory = True
        If (spd.ShowDialog = DialogResult.OK) Then
            Me.pbImage.Image = New Bitmap(spd.FileName)
        End If

    End Sub
    Private Sub mnuLocation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLocation.Click
        Dim p As GpsPosition = Me.gps.GetPosition
    End Sub
End Class

⌨️ 快捷键说明

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