MFC代码: void DrawTextTest(HDC AHdc,int ALeft,int ATop,int AWidth,int AHeight) { CDC outDC; outDC.Attach(AHdc); CRect rect; rect.left = ALeft; rect.right = AWidth; rect.top = ATop; rect.bottom = AHeight; CBitmap bitmap; bitmap.CreateCompatibleBitmap(&outDC,AWidth, AHeight); CDC memDc; memDc.CreateCompatibleDC(&outDC); CBitmap* pOldBitmap = memDc.SelectObject(&bitmap); memDc.FillSolidRect(&rect, RGB(255,255,0)); CString str = _T("test"); memDc.TextOut(0,0,str,str.GetLength()); outDC.BitBlt(0,0, AWidth, AHeight, &memDc, 0,0, SRCCOPY); memDc.SelectObject(pOldBitmap); outDC.Detach(); } C#代码: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace Test { public static class DrawCtrl { const string arcs = "DrawCtrl.dll"; [DllImport(arcs, EntryPoint = "DrawTextTest")] internal static extern void DrawTextTest(int AHandle, int ALeft, int ATop, int AWidth, int AHeight); } } C#调用代码: private void pictureBox1_Paint(object sender, PaintEventArgs e) { IntPtr hdc = e.Graphics.GetHdc(); int handle = hdc.ToInt32(); ArcsCtrl.DrawTextTest(handle, 0, 0, pictureBox1.Width, pictureBox1.Height); e.Graphics.ReleaseHdc(hdc); }