|
-
Mar 7th, 2003, 04:36 PM
#1
Thread Starter
yay gay
Get a form's hdc
how do i get it under .net?
\m/  \m/
-
Mar 7th, 2003, 04:48 PM
#2
System.Windows.Forms.Form.CreateGraphics.GetHdc
-
Mar 7th, 2003, 04:51 PM
#3
Thread Starter
yay gay
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);
}
PHP Code:
private void Form1_Load(object sender, System.EventArgs e) {
test.Teste(this);
}
i get an "Object reference not set to an instance of an object." why?
also i know in .net i dont things with api but i am just testing how api works here..
\m/  \m/
-
Mar 7th, 2003, 05:00 PM
#4
where do you get the error?
-
Mar 7th, 2003, 05:01 PM
#5
Thread Starter
yay gay
in the DrawText() function
\m/  \m/
-
Mar 7th, 2003, 05:03 PM
#6
Thread Starter
yay gay
DrawText(formHdc, str, str.Length, rect, 64); here i mean
\m/  \m/
-
Mar 10th, 2003, 10:10 AM
#7
I dont get it. I tried to get it working...
All I can figure is that it must be the formhdc variable.
-
Mar 10th, 2003, 11:31 AM
#8
PowerPoster
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|