how do i get it under .net?
Printable View
how do i get it under .net?
System.Windows.Forms.Form.CreateGraphics.GetHdc
yes ty i made a search and discovered that tks..anyways im getting an error while trying to implement that in C#:
PHP Code:public class test {
[DllImport("user32.dll")]
public static extern int DrawText(IntPtr hdc, string lpStr, int nCount, RECT lpRect, int wFormat);
public struct RECT {
public RECT(int top, int left, int right, int bottom) {
Top = top;
Left = left;
Right = right;
Bottom = bottom;
}
int Top;
int Left;
int Right;
int Bottom;
}
private enum DT {
LEFT = 0,
CENTER = 1,
RIGHT = 2,
VCENTER = 4,
SINGLELINE = 32,
BOTTOM = 8,
CALCRECT = 1024,
EXPANDTABS = 64,
INTERNAL = 4096,
WORDBREAK = 16,
TABSTOP = 128,
NOPREFIX = 2048,
NOCLIP = 256,
EXTERNALLEADING = 512,
}
public static void Teste(Form parent) {
Graphics graphics = parent.CreateGraphics();
IntPtr formHdc = graphics.GetHdc();
string str = "oiiiiiiiii!";
RECT rect = new RECT(0, 0, 100, 100);
DrawText(formHdc, str, str.Length, rect, 64);
}
i get an "Object reference not set to an instance of an object." why?PHP Code:private void Form1_Load(object sender, System.EventArgs e) {
test.Teste(this);
}
also i know in .net i dont things with api but i am just testing how api works here..
where do you get the error?
in the DrawText() function
DrawText(formHdc, str, str.Length, rect, 64); here i mean
I dont get it. I tried to get it working...:confused:
All I can figure is that it must be the formhdc variable.
It looks like your just trying to draw text on a form....is that what your doing? If so, you don't need the api at all. You can use the DrawString method of the graphics object along with a Brush object and Font object to get your desired effect.