WindowsCE – deploying to the device

A very quick blog on some pointers when deploying your .NET Compact Framework application to a device.

Assuming that you’ve got your windows mobile application built.  And it runs in the virtual emulator shipped with VS.NET.  What’s next?

  1. Connect your device (PDA, hand-held, smart phone…)
  2. If you can not connect, you will need either Active Sync, or Windows Mobile Device center
    Grab it here: http://www.microsoft.com/downloads/details.aspx?FamilyId=4F68EB56-7825-43B2-AC89-2030ED98ED95&displaylang=en
  3. Once you can connect – check in VS.NET to see that VS.NET can connect to the device.  You may be prompted on the device about several installation and whether to trust a few files.
  4. Verify and accept them.  Then you should be able to deploy and debug the application on your WindowsCE

 

Next step – how do I add a short cut link to my application?

VS.NET will typically deploy the application to \Program Files\<Project Name>\<Assembly Executable Name>

You can change these settings in the application project properties.

To add a shortcut:

  1. You can’t create short cut within Windows CE. 
  2. Create a plain text file called <My App>.lnk
  3. Open the text file with notepad
  4. the format is <length>#<path to exe as well as arguments>
    e.g.
    28#”\Program Files\App\App.exe”
  5. 35#”\Program Files\App\App.exe” “mydb”
  6. save the text file to \Windows\Startup\Programs

Windows CE – building a transparent picturebox

Surprise!  PictureBox in Windows CE doesn’t support transparency.

Diving into yet another old forgotten corner of the .NET compact framework.

And just in case the mention of Compact Framework hasn’t scared you to death, today’s code will be in Visual Basic .NET

 

Imports System.Drawing.Imaging
Imports System.ComponentModel

Public Class TransparentPictureBox
    Inherits PictureBox

    Private _transparentColor As Color = Color.White
    Public Property TransparentColor() As Color
        Get
            Return _transparentColor
        End Get
        Set(ByVal value As Color)
            _transparentColor = value
        End Set
    End Property

    Protected Overloads Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

        If Not Me.Image Is Nothing Then
            Dim pictureBounds As New Rectangle(0, 0, Me.Width, Me.Height)
            Dim imageBounds As New Rectangle(0, 0, Me.Image.Width, Me.Image.Height)
            Dim attributes As New ImageAttributes()
            ' set color to be set to transparent - if you don't paint the background below, then these pixels
            ' will appear black
            attributes.SetColorKey(Me.TransparentColor, Me.TransparentColor)
            e.Graphics.DrawImage(Me.Image, pictureBounds, imageBounds.X, imageBounds.Y, imageBounds.Width, imageBounds.Height, GraphicsUnit.Pixel, attributes)
        End If

    End Sub

    Protected Overloads Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
        ' paint background color
        Dim brush As SolidBrush
        brush = New SolidBrush(Me.Parent.BackColor)
        e.Graphics.FillRectangle(brush, Me.ClientRectangle)
    End Sub

End Class