Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > .NET Smart Device เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,...




Clound SSD Virtual Server

.NET Smart Device เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,...

 
  .NET Smart Device Project เป็น Application ใช้สำหรับเขียนโปรแกรมเพื่อทำงานบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,... ใน Visual Studio สามารถสร้าง Application ของ Smart Device นั้น สามารถทำได้อย่างง่ายได้ รูปแบบการเขียนหรือแม้แต่ Event ต่าง ๆ ก็ไม่ต่างอะไรกับ Windows Form Applciation และทั้งยังสามารถพัฒนาใช้งานได้กับหลาย ๆ Target platform เช่น

Framework : 1,2,3,4

- Pocket PC 2003
- Windows CE
- Windows Mobile 5.0 Pockget PC SDK
- Windows Mobile 5.0 Smartphone PC SDK

ในการเขียน Application ประเภท Smart Device สามารถทำการเชื่อมต่อกับอุปกรณ์ จริง หรือจะทำการใช้ตัว Emulator ที่อยู่ใน .NET Framework เพื่อทำการจำลองและใช้สำหรับ Debug โปรแกรม แต่ถ้าหากทำการเชื่อมต่อกับอุปกรณ์จริง ๆ จะต้องทำการติดตั้งตัวโปรแกรม Microsoft ActiveSync หรือใน Windows 7,Vista ขึ้นไปจะใช้ Windows Mobile Device Center สำหรับเชื่อมต่อกับอุปกรณ์

สำหรับบทความนี้มีทั้งที่เป็นภาษา VB.NET และ C# ครับ สามารถเลือกอ่านได้ตามความถนัดได้เลย

Language Code : VB.NET || C#


ในตัวอย่างนี้ผมได้ใช้ Tool ของ Visual Studio 2008 บน .NET Framework 3.5

ให้เปิด Tool ขึ้นมาพร้อมกับ New Project

.NET Smart Device

Project type เลือกเป็น VB.NET หรือ C# ก็แล้วแต่ความถนัด


.NET Smart Device

เลือกเป็น Device Application และเราจะต้องทดสอบบน platform ของ Windows Mobile 5.0 Pockget PC SDK


.NET Smart Device

หน้าจอของ Form ที่พร้อมจเขียนโปรแกรม มีตัวอย่างเป็นหน้าจอบน Pocket PC ให้ดูเป็นตัวอย่าง


.NET Smart Device

อันนี้เป็น Form Default ที่สร้างมาให้ หากไม่ต้องการก็ลบทิ้งได้เลย









.NET Smart Device

สามารถเพิ่ม Form ขึ้นมาใหม่โดยคลิกขวาที่ Project -> Add -> New Item....


.NET Smart Device

เลือก Windows Form และกำหนดชื่อ Form


.NET Smart Device

ได้ Form ขึ้นมาใหม่แล้ว


.NET Smart Device

กรณีที่เป็น VB.NET สามารถกำหนด Start Up โปรเจคได้ที่ คลิกขวาที่ Project เลือก Properties


.NET Smart Device

และตรง Startup Project : เลือก form หลักที่ต้องการให้รันแรกสุดเมื่อมีการรันโปรแกรม


.NET Smart Device

ทดสอบการรัน Application โดยคลิกที่ปุ่ม Start Debugging


.NET Smart Device

กรณีที่เราไม่ได้ทำการเชื่อมต่อกับอุปกรณ์ที่มีอยู่จริงให้เลือก USA Windows Mobile 5.0 Pocket PC R2 Emulator หรือ กรณีที่ได้เชื่อมต่อแล้วก็ให้เลือก Windows Mobile 5.0 Packet PC Device R2 ได้เลย


.NET Smart Device

ในตัวอย่างได้เลือกเป็นแบบ Emulator ซึ่งก็จะได้ผลดังรูป ซึ่งตอนนี้เป็นหน้าว่างเปล่า เพราะยังไม่มีการใส่ข้อความหรือเขียนฟังก์ชั่นเข้าไป


ในตัวอย่างนี้มีการเรียกใช้งาน Database ของ SqlServerCe ด้วย

.NET Smart Device

ให้คลิกขวที่ Project -> Add -> New Item...


.NET Smart Device

เลือก Database File พร้อมกับกำหนดชื่อ Database ด้วย


.NET Smart Device

Database ถุกสร้างขึ้นมาแล้ว


.NET Smart Device

ทดสอบการสร้าง Table โดยไปที่ Server Explorer (อยู่ด้านซ้าย) คลิกที่ Database ที่เราสร้างขึ้นมา


.NET Smart Device

และภายใต้ Table ให้คลิกขวาเลือก Create Table ให้สร้างตารางชื่อ mytable โดยมีฟิว์ id,name,email (id เป็น primary key และ IdentityIncrement) และ save ถือเป็นเสร็จสิ้นการสร้าง Table




ในตัวอย่างนี้จะประกอบด้วย 4 Form คือ
1. frmMain เป็นหน้าแรกของ Application
2. frmHome เป็นหน้าหลักของโปรแกรมใช้ DataGrid สำหรับเรียกข้อมูลมาแสดง (เพื่อลิงค์ไปยังการ เพิ่ม/แก้ไข/ลบ ข้อมูล)
3. frmAdd เป็นหน้าสำหรับเพิ่มข้อมูล
4. frmEdit เป็นหน้าสำหรับแก้ไขข้อมูล

frmMain

.NET Smart Device

Public Class frmMain
    ' By https://www.thaicreate.com (mr.win)'
    Private Sub btnHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHome.Click
        Dim f As New frmHome
        f.Show()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        If MessageBox.Show("Are you sure to exit?", "Confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then
            Application.Exit()
        End If
    End Sub

    Private ReadOnly VK_OFF As Byte = &HDF
    Private ReadOnly KEYEVENTF_KEYUP As Byte = &H2

    <System.Runtime.InteropServices.DllImport("coredll.dll", SetLastError:=True)> _
    Public Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
    End Sub

    Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click
        If MessageBox.Show("Are you sure to shutdown?", "Confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then
            Call keybd_event(VK_OFF, 0, 0, 0)
            Call keybd_event(VK_OFF, 0, KEYEVENTF_KEYUP, 0)
        End If
    End Sub

End Class



frmHome

.NET Smart Device

Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms

Public Class frmHome
    ' By https://www.thaicreate.com (mr.win)'
    Private Sub frmHome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BindDataGrid()
    End Sub

    Private Sub BindDataGrid()

        Dim myConnection As SqlCeConnection
        Dim dt As New DataTable
        Dim Adapter As SqlCeDataAdapter
        myConnection = New SqlCeConnection("Data Source =" _
            + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase ) + "\AppDatabase1.sdf;"))
        myConnection.Open()
        Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
        myCommand.CommandText = "SELECT [id], [name], [email] FROM [mytable]"
        myCommand.CommandType = CommandType.Text

        Adapter = New SqlCeDataAdapter(myCommand)
        Adapter.Fill(dt)

        myConnection.Close()

        Dim tableStyle As New DataGridTableStyle()
        tableStyle.MappingName = dt.TableName


        Dim column As New DataGridTextBoxColumn()
        column.MappingName = "id"
        column.HeaderText = "ID"
        column.Width = 30
        tableStyle.GridColumnStyles.Add(column)

        column = New DataGridTextBoxColumn()
        column.MappingName = "name"
        column.HeaderText = "Name"
        column.Width = 40
        tableStyle.GridColumnStyles.Add(column)

        column = New DataGridTextBoxColumn()
        column.Width = 70
        column.MappingName = "email"
        column.HeaderText = "Email"
        tableStyle.GridColumnStyles.Add(column)

        Me.dgName.DataSource = dt

        Me.dgName.TableStyles.Clear()
        Me.dgName.TableStyles.Add(tableStyle)

        dt = Nothing

    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim f As New frmAdd
        f.Show()
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Dim f As New frmEdit
        f._strID = Me.dgName(Me.dgName.CurrentRowIndex, 0)
        f.Show()
    End Sub

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click

        If MessageBox.Show("Are you sure to delete?", "Confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then

            Dim strID As String = Me.dgName(Me.dgName.CurrentRowIndex, 0)

            Dim myConnection As SqlCeConnection
            myConnection = New SqlCeConnection("Data Source =" _
                + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase ) + "\AppDatabase1.sdf;"))
            myConnection.Open()
            Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
            myCommand.CommandText = "DELETE FROM [mytable] WHERE id = '" & strID & "'"
            myCommand.CommandType = CommandType.Text
            myCommand.ExecuteNonQuery()
            myConnection.Close()
            MessageBox.Show("Delete Successfully")

            BindDataGrid()
        End If

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Dim f As New frmMain
        f.Show()
    End Sub

End Class









frmAdd

.NET Smart Device

Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms

Public Class frmAdd
    ' By https://www.thaicreate.com (mr.win)'
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        If Me.txtName.Text = "" Then
            MessageBox.Show("Please input (Name)")
            Me.txtName.Focus()
            Exit Sub
        End If

        If Me.txtEmail.Text = "" Then
            MessageBox.Show("Please input (Email)")
            Me.txtEmail.Focus()
            Exit Sub
        End If

        Dim myConnection As SqlCeConnection
        myConnection = New SqlCeConnection("Data Source =" _
            + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase ) + "\AppDatabase1.sdf;"))
        myConnection.Open()
        Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
        myCommand.CommandText = "INSERT INTO [mytable] ([name], [email]) VALUES  " & _
        " ('" & Me.txtName.Text & "','" & Me.txtEmail.Text & "' ) "
        myCommand.CommandType = CommandType.Text
        myCommand.ExecuteNonQuery()
        myConnection.Close()

        MessageBox.Show("Save Successfully")

        Dim f As New frmHome
        f.Show()

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Dim f As New frmHome
        f.Show()
    End Sub

    Private Sub txtName_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.GotFocus
        Me.InputPanel1.Enabled = True
    End Sub

    Private Sub txtEmail_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmail.GotFocus
        Me.InputPanel1.Enabled = True
    End Sub

    Private Sub txtName_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.LostFocus
        Me.InputPanel1.Enabled = False
    End Sub

    Private Sub txtEmail_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmail.LostFocus
        Me.InputPanel1.Enabled = False
    End Sub

End Class



frmEdit

.NET Smart Device

Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms

Public Class frmEdit
    ' By https://www.thaicreate.com (mr.win)'
    Dim strID As String = ""

    Public Property _strID() As String
        Get
            Return strID
        End Get
        Set(ByVal value As String)
            strID = value
        End Set
    End Property

    Private Sub frmEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim myConnection As SqlCeConnection
        Dim dt As New DataTable
        Dim Adapter As SqlCeDataAdapter
        myConnection = New SqlCeConnection("Data Source =" _
            + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase ) + "\AppDatabase1.sdf;"))
        myConnection.Open()
        Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
        myCommand.CommandText = "SELECT [id], [name], [email] FROM [mytable] WHERE id = '" & strID & "' "
        myCommand.CommandType = CommandType.Text

        Adapter = New SqlCeDataAdapter(myCommand)
        Adapter.Fill(dt)

        myConnection.Close()

        If dt.Rows.Count > 0 Then
            Me.txtName.Text = dt.Rows(0)("name")
            Me.txtEmail.Text = dt.Rows(0)("email")
        End If

        dt = Nothing

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        If Me.txtName.Text = "" Then
            MessageBox.Show("Please input (Name)")
            Me.txtName.Focus()
            Exit Sub
        End If

        If Me.txtEmail.Text = "" Then
            MessageBox.Show("Please input (Email)")
            Me.txtEmail.Focus()
            Exit Sub
        End If

        Dim myConnection As SqlCeConnection
        myConnection = New SqlCeConnection("Data Source =" _
            + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase ) + "\AppDatabase1.sdf;"))
        myConnection.Open()
        Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
        myCommand.CommandText = "UPDATE [mytable] SET " & _
        " [name] = '" & Me.txtName.Text & "', [email] = '" & Me.txtEmail.Text & "'  " & _
        " WHERE id = '" & strID & "' "
        myCommand.CommandType = CommandType.Text
        myCommand.ExecuteNonQuery()
        myConnection.Close()

        MessageBox.Show("Update Successfully")

        Dim f As New frmHome
        f.Show()

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Dim f As New frmHome
        f.Show()
    End Sub


    Private Sub txtName_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.GotFocus
        Me.InputPanel1.Enabled = True
    End Sub

    Private Sub txtEmail_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmail.GotFocus
        Me.InputPanel1.Enabled = True
    End Sub

    Private Sub txtName_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.LostFocus
        Me.InputPanel1.Enabled = False
    End Sub

    Private Sub txtEmail_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmail.LostFocus
        Me.InputPanel1.Enabled = False
    End Sub

End Class





ทดสอบการรันโปรแกรมโดยคิกที่ Start Debugging

.NET Smart Device

เข้าสู่หน้า Main


.NET Smart Device

หน้า Home


.NET Smart Device

หน้า Add ข้อมูล


.NET Smart Device

หร้า Edit ข้อมูล


.NET Smart Device

สำหรับลบข้อมูล


สำหรับตัวอย่างทั้งหมดนี้สามารถดาวน์โหลด Code ได้จากข้างล่าง โดยมีทั้งภาษา VB.NET และ C# และบทความนี้เป็นเพียงการสอนเบื้องต้นเท่านั้น เพื่อเป็นพื้นฐานในการต่อยอดในการพัฒนาโปรแกรมที่มีความซับซ้อนและการใช้งานที่หลากหลาย



บทความที่เกี่ยวข้อง
Go to : Shared Folder or Map Drive in Emulator Smart Device Mobile Application
Go to : Smart Device Mobile Application Read and Write Text File


       
Bookmark.   
       

 

  By : TC Admin
  Score Rating : -
  Create Date : 2010-09-02 21:19:09
  Download : Download  .NET Smart Device  เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window  Mobile 5-6, Hand Held,... (1.50 MB)
     

Clound SSD Virtual Server
-->
Related Links
Basic jQuery for AJAX in ASP.NET Web Site พื้นฐาน Ajax กับ ASP.NET ด้วย jQuery
Basic jQuery for AJAX in ASP.NET Web Site พื้นฐาน Ajax กับ ASP.NET ด้วย jQuery
บทความ jQuery กับการใช้งาน Ajax บน ASP.NET Framework ทำความเข้าใจพื้นฐานการทำงานกับ Ajax ด้วย jQuery กับ ASP.NET แบบง่าย ๆ เบสิก
Rating :
Update :
2017-03-24 21:23:54 View : 21,676
.NET & Silverlight คืออะไร รู้จักกับ Silverlight ซึ่งเป็น Plugin ของ .NET Framework
.NET & Silverlight คืออะไร รู้จักกับ Silverlight ซึ่งเป็น Plugin ของ .NET Framework
.NET & Silverlight รู้จักกับ Silverlight ซึ่งเป็น Plugin ของ .NET Framework ที่ใช้สร้าง Application Multimedia
Rating :
Update :
2017-03-24 21:18:14 View : 42,412
.NET Windows Form Application  เขียนโปรแกรมบน Windows Form Application ด้วย .NET Framework
.NET Windows Form Application เขียนโปรแกรมบน Windows Form Application ด้วย .NET Framework
.NET Windows Form Application , Windows App by (VB.NET,C#) เขียนโปรแกรมบน Windows Form Application ด้วย .NET Framework
Rating :
Update :
2017-03-17 22:21:14 View : 74,512
.NET Console Application เขียนโปรแกรมบน Console Application ด้วย .NET Framework
.NET Console Application เขียนโปรแกรมบน Console Application ด้วย .NET Framework
.NET Console Application เขียนโปรแกรมบน Console Application ด้วย .NET Framework
Rating :
Update :
2017-03-24 21:19:30 View : 41,732
.NET Windows Form กับการส่งอีเมล์ (Send Mail) แบบง่าย ๆ ด้วย System.Net.Mail (VB.NET , C#)
.NET Windows Form กับการส่งอีเมล์ (Send Mail) แบบง่าย ๆ ด้วย System.Net.Mail (VB.NET , C#)
ง่าย ๆ กับ .NET Framework การเขียน Windows Form ส่งอีเมล์ แบบง่าย ๆ ด้วย Namespace ของ System.Net.Mail
Rating :
Update :
2017-03-17 22:15:41 View : 18,229
ออกรายงาน Crystal Report บน Web(ASP.NET) Step by Step
ออกรายงาน Crystal Report บน Web(ASP.NET) Step by Step
ตัวอย่างการออกรายงานบน crystal report บนเว็บ web(asp.net) อธิบายขั้นตอนทีล่ะ step เข้าใจง่าย ทำงานได้จริง
Rating :
Update :
2017-03-17 21:19:24 View : 62,090
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่

Inline