Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Overridden OnPaint method not called on form

Overridden OnPaint method not called on form

Scheduled Pinned Locked Moved C#
question
16 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P pr1mem0ver

    I have no idea what you would want to see. Other than than the fact that I am using a regular System.Windows.Forms form, I have no idea what else matters. All that I should need to do is write an overridden onpaint method... doing this has worked in other applications. that is the only thing that I know is relevant. I have simply written a method override. Here is the content but its all commented out because except for the call to the base method because it wasn't working. Putting a break point in here indicates that the method isn't being executed at all. It is working fine in other applications where I have overwritten the OnPaint method.

    protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);
    /*if (designMode)
    base.OnPaint(e);
    else
    {
    switch (DisplayMode)
    {
    case DisplayMode.DesktopWidget:
    if (UseWorkerAPI)
    {
    IntPtr dc = GetDCEx(hWorkerAPI, IntPtr.Zero, (DeviceContextValues)0x403);
    base.OnPaint(new PaintEventArgs(Graphics.FromHdc(dc), e.ClipRectangle));
    }
    break;
    case DisplayMode.WindowWidget:
    base.OnPaint(e);
    break;
    default:
    break;
    }
    }*/
    }

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #6

    Stupid question, but why is all the code commented out?

    1 Reply Last reply
    0
    • P pr1mem0ver

      I have no idea what you would want to see. Other than than the fact that I am using a regular System.Windows.Forms form, I have no idea what else matters. All that I should need to do is write an overridden onpaint method... doing this has worked in other applications. that is the only thing that I know is relevant. I have simply written a method override. Here is the content but its all commented out because except for the call to the base method because it wasn't working. Putting a break point in here indicates that the method isn't being executed at all. It is working fine in other applications where I have overwritten the OnPaint method.

      protected override void OnPaint(PaintEventArgs e)
      {
      base.OnPaint(e);
      /*if (designMode)
      base.OnPaint(e);
      else
      {
      switch (DisplayMode)
      {
      case DisplayMode.DesktopWidget:
      if (UseWorkerAPI)
      {
      IntPtr dc = GetDCEx(hWorkerAPI, IntPtr.Zero, (DeviceContextValues)0x403);
      base.OnPaint(new PaintEventArgs(Graphics.FromHdc(dc), e.ClipRectangle));
      }
      break;
      case DisplayMode.WindowWidget:
      base.OnPaint(e);
      break;
      default:
      break;
      }
      }*/
      }

      P Offline
      P Offline
      pr1mem0ver
      wrote on last edited by
      #7

      Hello all who have made comments. I am replying to my own comment so that I can address all of your comments in one reply. All of you except for OriginalGriff are asking questions that I have already implied or explicitly written answers too: Perhaps some of you don't speak English so I will clarify. This statement implies that the code I provided above is in a class derived from System.Windows.Forms: "Other than than the fact that I am using a regular System.Windows.Forms form" As for why I commented code out, I answered that question with the statement: "Here is the content but its all commented out because except for the call to the base method because it wasn't working." If you don't understand any of the above statements, then ask about that. Otherwise please don't ask questions that I have already answered. It wastes everyone's time. For my part, I probably could have written that second statement better as: "Here is the content but it's all commented out because, except for the call to the base method, because it wasn't working." OriginalGriff: 1. Yes 2. Yes 3. No. I did not want the form drawn normally under certain conditions. EVERYONE: I wrote a test program to both figure this issue out and move forward with my purpose since that test program is working correctly. I have learned that overriding OnPaint will not accomplish what I am currently trying to do (which is to make the application into a desktop widget when the user decides... that means drawing it as part of the desktop). However, I would still like to troubleshoot this in case I need to override OnPaint for another reason... chances are good I may need to since this is a very customized form.

      L 1 Reply Last reply
      0
      • P pr1mem0ver

        Hello all who have made comments. I am replying to my own comment so that I can address all of your comments in one reply. All of you except for OriginalGriff are asking questions that I have already implied or explicitly written answers too: Perhaps some of you don't speak English so I will clarify. This statement implies that the code I provided above is in a class derived from System.Windows.Forms: "Other than than the fact that I am using a regular System.Windows.Forms form" As for why I commented code out, I answered that question with the statement: "Here is the content but its all commented out because except for the call to the base method because it wasn't working." If you don't understand any of the above statements, then ask about that. Otherwise please don't ask questions that I have already answered. It wastes everyone's time. For my part, I probably could have written that second statement better as: "Here is the content but it's all commented out because, except for the call to the base method, because it wasn't working." OriginalGriff: 1. Yes 2. Yes 3. No. I did not want the form drawn normally under certain conditions. EVERYONE: I wrote a test program to both figure this issue out and move forward with my purpose since that test program is working correctly. I have learned that overriding OnPaint will not accomplish what I am currently trying to do (which is to make the application into a desktop widget when the user decides... that means drawing it as part of the desktop). However, I would still like to troubleshoot this in case I need to override OnPaint for another reason... chances are good I may need to since this is a very customized form.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #8

        I just tried something similar (using the code you posted) and it works every time. There must be something else in your form/project that is preventing it calling your OnPaint override.

        P 1 Reply Last reply
        0
        • P pr1mem0ver

          I am trying to override the OnPaint and OnPaintBackground methods for my Application's main form. For some reason neither of the methods are being called EVER. They are completely ignored. What am I doing wrong?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #9

          Wild guess: your project got corrupted. Try "rebuild all". :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          P 1 Reply Last reply
          0
          • L Luc Pattyn

            Wild guess: your project got corrupted. Try "rebuild all". :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            P Offline
            P Offline
            pr1mem0ver
            wrote on last edited by
            #10

            LOL. Already tried that. Didn't work.

            1 Reply Last reply
            0
            • L Lost User

              I just tried something similar (using the code you posted) and it works every time. There must be something else in your form/project that is preventing it calling your OnPaint override.

              P Offline
              P Offline
              pr1mem0ver
              wrote on last edited by
              #11

              Yeah. I know. I tried it again in the newer "test" app (as I mention in my most recent post above). It works fine. I still can't find anything wrong with the project app. I am hoping someone will have an idea of what could possibly get in the way of the override being called.

              L 1 Reply Last reply
              0
              • P pr1mem0ver

                Yeah. I know. I tried it again in the newer "test" app (as I mention in my most recent post above). It works fine. I still can't find anything wrong with the project app. I am hoping someone will have an idea of what could possibly get in the way of the override being called.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #12

                Impossible to guess since we do not have enough information.

                L 1 Reply Last reply
                0
                • L Lost User

                  Impossible to guess since we do not have enough information.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #13

                  That is exactly when a guess is required... When all information is available, you can rationally deduce what causes the problem. ;)

                  Luc Pattyn [My Articles] Nil Volentibus Arduum

                  L 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    That is exactly when a guess is required... When all information is available, you can rationally deduce what causes the problem. ;)

                    Luc Pattyn [My Articles] Nil Volentibus Arduum

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #14

                    Luc Pattyn wrote:

                    When all information is available

                    Exactly so; but until then ...

                    P 1 Reply Last reply
                    0
                    • L Lost User

                      Luc Pattyn wrote:

                      When all information is available

                      Exactly so; but until then ...

                      P Offline
                      P Offline
                      pr1mem0ver
                      wrote on last edited by
                      #15

                      Until then... For now I can live without an answer.

                      L 1 Reply Last reply
                      0
                      • P pr1mem0ver

                        Until then... For now I can live without an answer.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #16

                        And without providing more information that's how it will remain, I am afraid.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups