What property defines a controls paint bounds?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom P.

    What property defines a controls paint bounds?

    I am creating a custom control and I'm trying to get the painting of
    it correct. I'd like to simply use:
    e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e);
    .... or ...
    e.Graphics.Fill Rectangle(Brush es.White, ClientRectangle );
    .... or ...
    e.Graphics.Fill Rectangle(Brush es.White, Bounds);

    But each of those fails to draw a rectangle all the way around (most
    are 1 pixel off). Instead I find myself having to use:
    e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e.X,
    DisplayRectangl e.Y, DisplayRectangl e.Width - 1,
    DisplayRectangl e.Height - 1);

    What am I really supposed to use? How do I get that last pixel
    correct?

    Tom P.
  • Matt

    #2
    Re: What property defines a controls paint bounds?

    On Feb 27, 2:20 pm, "Tom P." <padilla.he...@ gmail.comwrote:
    I am creating a custom control and I'm trying to get the painting of
    it correct. I'd like to simply use:
    e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e);
    ... or ...
    e.Graphics.Fill Rectangle(Brush es.White, ClientRectangle );
    ... or ...
    e.Graphics.Fill Rectangle(Brush es.White, Bounds);
    >
    But each of those fails to draw a rectangle all the way around (most
    are 1 pixel off). Instead I find myself having to use:
    e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e.X,
    DisplayRectangl e.Y, DisplayRectangl e.Width - 1,
    DisplayRectangl e.Height - 1);
    >
    What am I really supposed to use? How do I get that last pixel
    correct?
    >
    Tom P.
    What is wrong with e.Graphics.Fill Rectangle( Brushes.White,
    e.ClipRectangle );

    ?
    Matt

    Comment

    • Peter Duniho

      #3
      Re: What property defines a controls paint bounds?

      On Wed, 27 Feb 2008 13:20:02 -0800, Tom P. <padilla.henry@ gmail.comwrote:
      I am creating a custom control and I'm trying to get the painting of
      it correct. I'd like to simply use:
      e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e);
      ... or ...
      e.Graphics.Fill Rectangle(Brush es.White, ClientRectangle );
      ... or ...
      e.Graphics.Fill Rectangle(Brush es.White, Bounds);
      >
      But each of those fails to draw a rectangle all the way around (most
      are 1 pixel off). Instead I find myself having to use:
      e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e.X,
      DisplayRectangl e.Y, DisplayRectangl e.Width - 1,
      DisplayRectangl e.Height - 1);
      >
      What am I really supposed to use? How do I get that last pixel
      correct?
      Just what you're doing. Either DisplayRectangl e or ClientRectangle are
      appropriate, depending on your specific need (by default, they are the
      same). And you need to subtract one from the width and height to get the
      whole rectangle to draw.

      This may seem arbitrary, but there's actually a good reason for it.
      Graphical coordinates are treated as being the intersection of 0-width
      lines in a grid. The pixels are _between_ these lines. A line drawn from
      (0,0) to (0,100) for example will fill all of the pixels just to the right
      of that 0-width vertical line between those coordinates, inclusive.

      When you try to draw a rectangle a specific width and height, all of the
      pixels are being drawn to the right and below of any coordinate that
      describes the rectangle. This means that on the right and bottom of the
      rectangle, if you've specified coordinates that are actually the absolute
      outer bounds of the area in which the control can draw, those pixels fall
      outside of the control and aren't drawn.

      The fix is to reduce the width and height of the rectangle you're trying
      to draw by the width of one pixel, so that the pixels drawn for that
      rectangle fall within the control's drawable area.

      Pete

      Comment

      • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

        #4
        RE: What property defines a controls paint bounds?



        "Tom P." wrote:
        I am creating a custom control and I'm trying to get the painting of
        it correct. I'd like to simply use:
        e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e);
        .... or ...
        e.Graphics.Fill Rectangle(Brush es.White, ClientRectangle );
        .... or ...
        e.Graphics.Fill Rectangle(Brush es.White, Bounds);
        >
        But each of those fails to draw a rectangle all the way around (most
        are 1 pixel off). Instead I find myself having to use:
        e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e.X,
        DisplayRectangl e.Y, DisplayRectangl e.Width - 1,
        DisplayRectangl e.Height - 1);
        >
        What am I really supposed to use? How do I get that last pixel
        correct?
        >
        Tom P.
        >
        It looks like you really could do it with e.Graphics.Clea r(Color.White);

        Comment

        • Tom P.

          #5
          Re: What property defines a controls paint bounds?

          On Feb 27, 6:58 pm, Family Tree Mike
          <FamilyTreeM... @discussions.mi crosoft.comwrot e:
          "Tom P." wrote:
          I am creating a custom control and I'm trying to get the painting of
          it correct. I'd like to simply use:
          e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e);
          .... or ...
          e.Graphics.Fill Rectangle(Brush es.White, ClientRectangle );
          .... or ...
          e.Graphics.Fill Rectangle(Brush es.White, Bounds);
          >
          But each of those fails to draw a rectangle all the way around (most
          are 1 pixel off). Instead I find myself having to use:
          e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e.X,
          DisplayRectangl e.Y, DisplayRectangl e.Width - 1,
          DisplayRectangl e.Height - 1);
          >
          What am I really supposed to use? How do I get that last pixel
          correct?
          >
          Tom P.
          >
          It looks like you really could do it with e.Graphics.Clea r(Color.White);
          That's fine for clearing the control to white but what would I use to
          draw the black outline?

          Tom P.

          Comment

          • Tom P.

            #6
            Re: What property defines a controls paint bounds?

            On Feb 27, 5:10 pm, Matt <matttel...@spr ynet.comwrote:
            On Feb 27, 2:20 pm, "Tom P." <padilla.he...@ gmail.comwrote:
            >
            >
            >
            I am creating a custom control and I'm trying to get the painting of
            it correct. I'd like to simply use:
            e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e);
            ... or ...
            e.Graphics.Fill Rectangle(Brush es.White, ClientRectangle );
            ... or ...
            e.Graphics.Fill Rectangle(Brush es.White, Bounds);
            >
            But each of those fails to draw a rectangle all the way around (most
            are 1 pixel off). Instead I find myself having to use:
            e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e.X,
            DisplayRectangl e.Y, DisplayRectangl e.Width - 1,
            DisplayRectangl e.Height - 1);
            >
            What am I really supposed to use? How do I get that last pixel
            correct?
            >
            Tom P.
            >
            What is wrong with e.Graphics.Fill Rectangle( Brushes.White,
            e.ClipRectangle );
            >
            ?
            Matt
            The same thing that's wrong with everything else - it's off by one
            pixel.

            Tom P.

            Comment

            • Tom P.

              #7
              Re: What property defines a controls paint bounds?

              On Feb 27, 5:11 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
              wrote:
              On Wed, 27 Feb 2008 13:20:02 -0800, Tom P. <padilla.he...@ gmail.comwrote:
              I am creating a custom control and I'm trying to get the painting of
              it correct. I'd like to simply use:
              e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e);
              ... or ...
              e.Graphics.Fill Rectangle(Brush es.White, ClientRectangle );
              ... or ...
              e.Graphics.Fill Rectangle(Brush es.White, Bounds);
              >
              But each of those fails to draw a rectangle all the way around (most
              are 1 pixel off). Instead I find myself having to use:
              e.Graphics.Fill Rectangle(Brush es.White, DisplayRectangl e.X,
              DisplayRectangl e.Y, DisplayRectangl e.Width - 1,
              DisplayRectangl e.Height - 1);
              >
              What am I really supposed to use? How do I get that last pixel
              correct?
              >
              Just what you're doing. Either DisplayRectangl e or ClientRectangle are
              appropriate, depending on your specific need (by default, they are the
              same). And you need to subtract one from the width and height to get the
              whole rectangle to draw.
              >
              This may seem arbitrary, but there's actually a good reason for it.
              Graphical coordinates are treated as being the intersection of 0-width
              lines in a grid. The pixels are _between_ these lines. A line drawn from
              (0,0) to (0,100) for example will fill all of the pixels just to the right
              of that 0-width vertical line between those coordinates, inclusive.
              >
              When you try to draw a rectangle a specific width and height, all of the
              pixels are being drawn to the right and below of any coordinate that
              describes the rectangle. This means that on the right and bottom of the
              rectangle, if you've specified coordinates that are actually the absolute
              outer bounds of the area in which the control can draw, those pixels fall
              outside of the control and aren't drawn.
              >
              The fix is to reduce the width and height of the rectangle you're trying
              to draw by the width of one pixel, so that the pixels drawn for that
              rectangle fall within the control's drawable area.
              >
              Pete
              I guess you're right. There's nothing else I can find to change this.
              There should be a "DrawRectan gle" property for this type of
              situation. Oh, well... thanks.

              Tom P.

              Comment

              • Peter Duniho

                #8
                Re: What property defines a controls paint bounds?

                On Thu, 28 Feb 2008 10:59:36 -0800, Tom P. <padilla.henry@ gmail.comwrote:
                I guess you're right. There's nothing else I can find to change this.
                There should be a "DrawRectan gle" property for this type of
                situation. Oh, well... thanks.
                I don't understand what you mean. There is a DrawRectangle() method, but
                it just outlines the rectangle rather than filling it.

                There's not an actual problem here with .NET. The only issue is that you
                need to comprehend the API differently. Once you understand that
                coordinates you provide don't refer to pixels, but rather to the grid
                between pixels, everything makes sense.

                If you don't understand that, then yes...you'll continue to believe a
                problem exists, even though none does.

                Pete

                Comment

                • Tom P.

                  #9
                  Re: What property defines a controls paint bounds?

                  On Feb 28, 1:13 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
                  wrote:
                  On Thu, 28 Feb 2008 10:59:36 -0800, Tom P. <padilla.he...@ gmail.comwrote:
                  I guess you're right. There's nothing else I can find to change this.
                  There should be a "DrawRectan gle" property for this type of
                  situation. Oh, well... thanks.
                  >
                  I don't understand what you mean. There is a DrawRectangle() method, but
                  it just outlines the rectangle rather than filling it.
                  >
                  There's not an actual problem here with .NET. The only issue is that you
                  need to comprehend the API differently. Once you understand that
                  coordinates you provide don't refer to pixels, but rather to the grid
                  between pixels, everything makes sense.
                  >
                  If you don't understand that, then yes...you'll continue to believe a
                  problem exists, even though none does.
                  >
                  Pete
                  I know there is a method DrawRectangle() , but I was talking about a
                  property that describe the ACTUAL painting region. In the same units,
                  or relationship, as the method is going to use it. What use have I for
                  a description of an area I have to adjust before using? Why provide me
                  with measurements that are close to what I need, but don't finally
                  describe the area I want? There are no fewer than four rectangles that
                  describe areas one pixel larger than the Displayed area of a control.
                  You mean to tell me they couldn't find it in their hearts to provide
                  one single property that depicts the ACTUAL area that methods like
                  DrawRectangle() are expecting? It doesn't seem like that big a deal.

                  Tom P.

                  Comment

                  • Peter Duniho

                    #10
                    Re: What property defines a controls paint bounds?

                    On Thu, 28 Feb 2008 13:07:46 -0800, Tom P. <padilla.henry@ gmail.comwrote:
                    [...]
                    Understanding all that, what is wrong with saying the PaintingArea is
                    from (x, y) 0, 0 to (width, height) 99, 99?
                    Because that would describe an area only 99 pixels wide and 99 pixels high
                    (9801 pixels total), when in fact the "painting area" (that is, the area
                    that the control is responsible for painting) is 100 pixels wide by 100
                    pixels high (10000 pixels total).
                    >
                    But I think your last statement gives me some insight into my issue
                    (and a better way to paint the object, so thank you) The particular
                    rectangles provided are only 1 pixel too small because the pen I am
                    using is 1 pixel. They are, in point of fact, "Pen.Width" smaller. I
                    should not be subtracting 1, I should be subtracting the Pen.Width to
                    ensure the entire pen falls within the paintable area regardless of
                    what size the pen is.
                    Yes, that's exactly right.
                    To that end I thank you for helping me
                    understand exactly what is being presented and how to use it.
                    You're welcome.

                    Pete

                    Comment

                    Working...