'VB
Imports System.Reflection
Imports System.Drawing
Dim bm As New Bitmap(200, 100)
Dim width As Integer = 0
' Explicitly set one pixel for testing
Dim x As Integer = 199
Dim y As Integer = 20
Dim pixColor As Color = Color.Black
bm.SetPixel(x, y, Color.Magenta)
' Get the "Width" property
Dim propInfo As PropertyInfo() = _
bm.GetType().GetProperties((BindingFlags.GetProperty Or _
BindingFlags.Public Or BindingFlags.Instance))
Dim i As Integer
For i = 0 To propInfo.Length - 1
If propInfo(i).Name = "Width" Then
width = Fix(propInfo(i).GetValue(bm, Nothing))
Exit For
End If
Next i
' Call the SetPixel method
Dim methInfo As MethodInfo() = bm.GetType().GetMethods((BindingFlags.Public _
Or BindingFlags.Instance))
For i = 0 To methInfo.Length - 1
If methInfo(i).Name = "GetPixel" Then
Dim paramInfo As ParameterInfo() = methInfo(i).GetParameters()
If paramInfo.Length = 2 Then
Dim xy(1) As Object
If paramInfo(0).Name = "x" Then
xy(0) = x
xy(1) = y
Else
xy(1) = x
xy(0) = y
End If
pixColor = CType(methInfo(i).Invoke(bm, xy), Color)
Exit For
End If
End If
Next i
7.30. How do I determine the device name programatically?
The device name can be accessed through the System.Net namespace, as demonstrated by the following code. //C#
String devName = System.Net.Dns.GetHostName();
'VB
Dim devName As String = System.Net.Dns.GetHostName()
7.31. How do I build a C# Smart Device project from the command line?
Enter the following commands as single lines (each is broken into two lines for clarity): set CFPath=%SystemDrive%\Program Files\Microsoft Visual Studio .NET 2003 CompactFrameworkSDK\v1.0.5000\Windows CE
csc Form1.cs /noconfig /nostdlib /lib:"%CFPath%" /r:"%CFPath%\system.dll";"%CFPath% system.drawing.dll";"%CFPath%\system.windows.forms.dll";"%CFPath%\mscorlib.dll"
7.32. How do I abort an executing thread??
There is no Abort method to the Thread class in the .NET Compact Framework so a thread must be aborted by returning from the executing procedure. Typically, an application will notify threads of a closing event by setting a global variable. The main thread will then wait for worker threads to finish processing before closing the application. The following HOWTO article demonstrates how to accomplish this.
http://msdn.microsoft.com/library/en-us/dncfhowto/html/stopmt.asp
7.33. Why can't I play a movie on the Pocket PC emulator?
Windows Media Player is only available on the Pocket PC 2003 emulator. The Windows Media Player install package is for installation on a hardware device connected through ActiveSync and will not install to the emulator.
7.34. How do I suppress Form titles from showing in the active applications list?
The Active Programs list on the Pocket PC enumerates all open Forms. To stop a Form from being displayed in the list, simply set the Form's caption to be an empty string. The following example shows how to keep only the application name in the list while a Form is displayed from within another Form:
//C#
string AppName = "MyApp";
Form1 form1 = new Form1();
this.Text = "";
form1.Text = AppName;
form1.ShowDialog();
this.Text = AppName;
'VB
Dim AppName As String = "MyApp"