linestyle and linecaps

  • Thread starter Thread starter zjz
  • Start date Start date
Z

zjz

I was wondering whether we can set linestyle and linecaps in CF using
P/invoke to call WinCE dll.

Thank you in advance.
 
There's no such functionality exist even in the WinCE API's

-Alex

----- zjz wrote: -----

I was wondering whether we can set linestyle and linecaps in CF using
P/invoke to call WinCE dll.

Thank you in advance.
 
Well there is no easy way of doing styles and caps such as a DashStyle and
DashCap property in the Pen class. But you could do all the work yourself to
get this type of look. Although you're pretty much on your own with this as
you will need to work out all the drawing algorithms to put the caps on and
draw the proper styles. However, if all you really need is to draw a few
simple shapes with a dashed line then you can do some PInvokin':

[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr GetFocus();

[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);

[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr CreatePen(int fnPenStyle, int nWidth, uint
crColor);

[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern bool Polyline(IntPtr hdc, POINT[] lppt, int cPoints);

[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern bool RoundRect(IntPtr hdc, int nLeftRect, int
nTopRect, int nRightRect, int nBottomRect, int nWidth, int nHeight);

[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern bool DeleteObject(IntPtr hObject);

[System.Runtime.InteropServices.DllImport("coredll.dll")]
private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

private struct POINT
{
public int x;
public int y;
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
}

private const int PS_SOLID = 0;
private const int PS_DASH = 1;

private void button1_Click(object sender, System.EventArgs e)
{
this.Focus();
IntPtr hWnd = GetFocus();
IntPtr hDC = GetDC(hWnd);
IntPtr hPen = CreatePen(PS_DASH, 1, RGB(Color.Black));
IntPtr hPenOld = SelectObject(hDC, hPen);
POINT[] pointArray = new POINT[] {new POINT(10, 25), new POINT(230, 25)};
// Draw a line.
Polyline(hDC, pointArray, 2);
// Draw a rounded rectangle.
RoundRect(hDC, 10, 50, 230, 100, 10, 10);
SelectObject(hDC, hPenOld);
DeleteObject(hPen);
ReleaseDC(hWnd, hDC);
}

private uint RGB(Color color)
{
// Format the value of color - 0x00bbggrr
return ((uint) (((uint) (color.R) | ((uint) (color.G) << 8)) | (((uint)
(color.B)) << 16)));
}

private Color UnRGB(int color)
{
return Color.FromArgb(color & 0xFF, (color & 0xFF00) >> 8, (color &
0xFF0000) >> 16);
}
 
Back
Top