Results 1 to 8 of 8

Thread: Get a form's hdc

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Get a form's hdc

    how do i get it under .net?
    \m/\m/

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    System.Windows.Forms.Form.CreateGraphics.GetHdc
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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 hdcstring lpStrint nCountRECT lpRectint wFormat);

            public 
    struct RECT {
                public 
    RECT(int topint leftint rightint 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(00100100);

                
    DrawText(formHdcstrstr.Lengthrect64);
            } 
    PHP Code:
            private void Form1_Load(object senderSystem.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/

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    where do you get the error?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    in the DrawText() function
    \m/\m/

  6. #6

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    DrawText(formHdc, str, str.Length, rect, 64); here i mean
    \m/\m/

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I dont get it. I tried to get it working...

    All I can figure is that it must be the formhdc variable.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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
  •  



Click Here to Expand Forum to Full Width