For drawing in raster C # use this code:
Graphics gr = Graphics.FromImage(MyBitmap);
IntPtr hdc = gr.GetHdc();
YourCPPDrawFunction(hdc);
gr.ReleaseHdc(hdc);
YourCPPDrawFunction example :
void YourCPPDrawFunction(HDC hDc)
{
SelectObject(hDc, GetStockObject(BLACK_PEN));
Rectangle(hDc, 10, 10, 20, 20);
}
To draw directly on the surface of the form, use this code:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
IntPtr hdc = e.Graphics.GetHdc();
YourCPPDrawFunction(hdc);
e.Graphics.ReleaseHdc(hdc);
}
Remember to call Graphics.ReleaseHdc () after you finish drawing, otherwise you will not see the results of your drawing.
source
share