Pen/Line width > 1 in CF

  • Thread starter Thread starter Mark
  • Start date Start date
For a vertical or horizontal line you can use a rectangle instead. Otherwise
you are going to have to draw multiple parallel lines to create the illusion
of a single thicker line.

Peter
 
Thanks at first.

Is it possible to use DLL functions to draw a line with
width > 1. I tried to do so in the full framework and it
works (Graphics.GetHdc(), CreatePen, SelectObject,
MoveToEx, LineTo etc.). But in CF I don't have a DC and no
idea where I can get one.

Mark
 
It is possible with a Bitmap object -see Alex's article here:-
http://www.opennetcf.org/Articles/GdiObjects.asp

For a form you can use GetDC which will return the DC for a specified window
handle. You can get the hWnd of the form by calling Focus() and then
P/Invoking the GetFocus API call. These two functions are fairly simple to
P/Invoke:-

[DllImport("coredll")]
private static extern IntPtr GetFocus();

[DllImport("coredll")]
private static extern IntPtr GetDC(IntPtr hWnd);

Then you can do
this.Focus();
IntPtr hDC = GetDC(GetFocus());

Peter
 
Back
Top