Pen/Line width > 1 in CF

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi,

how can I draw a line with a width larger than 1 in the
compact framework ?

Thx
Mark
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top