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. Visual Basic
  4. Paint a rectangle [modified]

Paint a rectangle [modified]

Scheduled Pinned Locked Moved Visual Basic
questioncomtools
14 Posts 3 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.
  • T Offline
    T Offline
    The ANZAC
    wrote on last edited by
    #1

    I have a custom control and am painting a custom border, how do i paint this outside of the bounds of the control from within the control itself. It's just a custom panel so its a straight rectangle.

    Please check out my articles: The ANZAC's articles

    G 1 Reply Last reply
    0
    • T The ANZAC

      I have a custom control and am painting a custom border, how do i paint this outside of the bounds of the control from within the control itself. It's just a custom panel so its a straight rectangle.

      Please check out my articles: The ANZAC's articles

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      It's possible to do, but you shouldn't do that. The entire control is supposed to go inside the bounds of the control, including any border. The Graphics object that you get in the Paint event is clipped to the bounds of the control or the part of the control that needs redrawing. If you draw outside this clipping, you risk drawing on top of other windows.

      Experience is the sum of all the mistakes you have done.

      T 1 Reply Last reply
      0
      • G Guffa

        It's possible to do, but you shouldn't do that. The entire control is supposed to go inside the bounds of the control, including any border. The Graphics object that you get in the Paint event is clipped to the bounds of the control or the part of the control that needs redrawing. If you draw outside this clipping, you risk drawing on top of other windows.

        Experience is the sum of all the mistakes you have done.

        T Offline
        T Offline
        The ANZAC
        wrote on last edited by
        #3

        yes but because the control contains other controls the border appears under them, or how do i draw over the top of all controls in the control remaining inside the bounds.

        Please check out my articles: The ANZAC's articles

        G 1 Reply Last reply
        0
        • T The ANZAC

          yes but because the control contains other controls the border appears under them, or how do i draw over the top of all controls in the control remaining inside the bounds.

          Please check out my articles: The ANZAC's articles

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Override the OnPaint method so that you can do your drawing after you call the OnPaint method of the base class.

          Experience is the sum of all the mistakes you have done.

          T 1 Reply Last reply
          0
          • G Guffa

            Override the OnPaint method so that you can do your drawing after you call the OnPaint method of the base class.

            Experience is the sum of all the mistakes you have done.

            T Offline
            T Offline
            The ANZAC
            wrote on last edited by
            #5

            Did that. Still not working. I can't seem to just draw a rectangle straight over the top of everything in my control, even if i paint it after on paint. How do i make things i paint out of the control's bounds visible?

            Please check out my articles: The ANZAC's articles

            L 1 Reply Last reply
            0
            • T The ANZAC

              Did that. Still not working. I can't seem to just draw a rectangle straight over the top of everything in my control, even if i paint it after on paint. How do i make things i paint out of the control's bounds visible?

              Please check out my articles: The ANZAC's articles

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

              Hi, have a look at the ControlPaint class, it allows you to paint anywhere on the screen! :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


              T 2 Replies Last reply
              0
              • L Luc Pattyn

                Hi, have a look at the ControlPaint class, it allows you to paint anywhere on the screen! :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                T Offline
                T Offline
                The ANZAC
                wrote on last edited by
                #7

                Thankyou this was very useful. Now...you wouldn't happen to know the best way to change the client area would you?. I need it to behave similar to a form in the sense that we can't place a control on or under the title bar but we can put it anywhere else on the form. I need to just redefine the client area location and width. Howe can i achieve this?

                Please check out my articles: The ANZAC's articles

                L 1 Reply Last reply
                0
                • L Luc Pattyn

                  Hi, have a look at the ControlPaint class, it allows you to paint anywhere on the screen! :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                  T Offline
                  T Offline
                  The ANZAC
                  wrote on last edited by
                  #8

                  As useful as this was it still doesn't let me draw outside the bounds of my control, it just cuts it off.

                  Please check out my articles: The ANZAC's articles

                  L 1 Reply Last reply
                  0
                  • T The ANZAC

                    As useful as this was it still doesn't let me draw outside the bounds of my control, it just cuts it off.

                    Please check out my articles: The ANZAC's articles

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

                    I once tried ControlPaint.DrawReversibleLine and dropped it since it ignored all windowing, so when applied to a window that was partly covered by something else it was painting over that something else, what I did not want at the time. :confused:

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                    T 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      I once tried ControlPaint.DrawReversibleLine and dropped it since it ignored all windowing, so when applied to a window that was partly covered by something else it was painting over that something else, what I did not want at the time. :confused:

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                      T Offline
                      T Offline
                      The ANZAC
                      wrote on last edited by
                      #10

                      Well i can't get it to paint outside my control, then again i am caling it from within my contro, don't know if this should make a difference, but i certainly can't draw anywhere on the screen.

                      Please check out my articles: The ANZAC's articles

                      L 1 Reply Last reply
                      0
                      • T The ANZAC

                        Thankyou this was very useful. Now...you wouldn't happen to know the best way to change the client area would you?. I need it to behave similar to a form in the sense that we can't place a control on or under the title bar but we can put it anywhere else on the form. I need to just redefine the client area location and width. Howe can i achieve this?

                        Please check out my articles: The ANZAC's articles

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

                        Hi,

                        The ANZAC wrote:

                        I need to just redefine the client area location and width.

                        Well you can set a new ClientSize, but I guess it just resizes the entire Form. I have never tried to create a different Form layout. If I were to need such thing I would try this: - create MyForm class inheriting from Form; - probably select a very simple BorderStyle (maybe None); - organize the painting of the non-client area (border, title bar, close box, whatever); - override some properties such as ClientSize, ClientRectangle, ... (and maybe a whole lot more); - and hope the majority of properties and methods can remain unchanged. I do not plan to try this on XP. And I hope I will never need to do it on Vista, although I am pretty sure I will not like transparant title bars... :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                        T 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          Hi,

                          The ANZAC wrote:

                          I need to just redefine the client area location and width.

                          Well you can set a new ClientSize, but I guess it just resizes the entire Form. I have never tried to create a different Form layout. If I were to need such thing I would try this: - create MyForm class inheriting from Form; - probably select a very simple BorderStyle (maybe None); - organize the painting of the non-client area (border, title bar, close box, whatever); - override some properties such as ClientSize, ClientRectangle, ... (and maybe a whole lot more); - and hope the majority of properties and methods can remain unchanged. I do not plan to try this on XP. And I hope I will never need to do it on Vista, although I am pretty sure I will not like transparant title bars... :)

                          Luc Pattyn [Forum Guidelines] [My Articles]


                          this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                          T Offline
                          T Offline
                          The ANZAC
                          wrote on last edited by
                          #12

                          well it's a panel not a form, problem is the clientsize is readonly and not overridable (i don't think) only overloadable. I wouldn't need to do this if i could just figure out how to paint outside my controls bounds.

                          Please check out my articles: The ANZAC's articles

                          1 Reply Last reply
                          0
                          • T The ANZAC

                            Well i can't get it to paint outside my control, then again i am caling it from within my contro, don't know if this should make a difference, but i certainly can't draw anywhere on the screen.

                            Please check out my articles: The ANZAC's articles

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

                            There seem to be two kinds of drawing methods in ControlPaint: - the ones working on the screen, using screen coordinates, ignoring all windows, just painting everywhere; - the ones needing a Graphics; now a Graphics always has clipping built-in, that's one of its features (did you ever care about a DrawString exceeding the width of a Control?). As another reply already told you, you (theoretically) cannot make a Control's OnPaint paint outside the Control, i.e. you must set the Control's Size large enough so it contains all the areas where you want it to paint something (that's how non-rectangular Forms basically work, as far as I can tell from reading some articles, I am not really in to this). :)

                            Luc Pattyn [Forum Guidelines] [My Articles]


                            this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                            T 1 Reply Last reply
                            0
                            • L Luc Pattyn

                              There seem to be two kinds of drawing methods in ControlPaint: - the ones working on the screen, using screen coordinates, ignoring all windows, just painting everywhere; - the ones needing a Graphics; now a Graphics always has clipping built-in, that's one of its features (did you ever care about a DrawString exceeding the width of a Control?). As another reply already told you, you (theoretically) cannot make a Control's OnPaint paint outside the Control, i.e. you must set the Control's Size large enough so it contains all the areas where you want it to paint something (that's how non-rectangular Forms basically work, as far as I can tell from reading some articles, I am not really in to this). :)

                              Luc Pattyn [Forum Guidelines] [My Articles]


                              this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                              T Offline
                              T Offline
                              The ANZAC
                              wrote on last edited by
                              #14

                              ok thankyou.

                              Please check out my articles: The ANZAC's articles

                              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