Method not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chuck Bowling

    Method not working

    VS 2003, .NET 1.1

    I'm throughly puzzled here. I can't seem to get the method below to work...

    private void AutoSizeHeight( )

    {

    Graphics g = this.CreateGrap hics();

    int x, lineCount;

    SizeF layoutSize = new SizeF(this.Widt h, this.Height * 100); // oversized
    height

    this.Height = (int)Math.Ceili ng(g.MeasureStr ing(base.Text, this.Font,
    layoutSize, new StringFormat(), out x, out lineCount).Heig ht);

    g.Dispose();

    // this.Height = 400; // this works

    // this.Height *= 9; // this works

    this.Height *= lineCount; // this doesn't work

    }

    //---------[end]---------------------

    This method is part of an inherited TextBox control. It's purpose is to
    resize the height of the control according to the height of the contents. It
    works fine if I assign a constant value to height or multiply by a constant.
    But when I try to multiply by lineCount it doesn't change. Height and
    lineCount definately both have values but for some reason they won't
    multiply.

    I'm I doing something wrong or is there something strange going on?

    Note: I don't know what it means, but the lineCount is red in the Watch
    window...


  • Nick Malik [Microsoft]

    #2
    Re: Method not working

    I am confused. In your text, you say that 'lineCount' definitely has a
    value, yet the code you posted: this variable is not assigned.

    What gives?

    --
    --- Nick Malik [Microsoft]
    MCSD, CFPS, Certified Scrummaster


    Disclaimer: Opinions expressed in this forum are my own, and not
    representative of my employer.
    I do not answer questions on behalf of my employer. I'm just a
    programmer helping programmers.
    --
    "Chuck Bowling" <chuckbowling@s bcglobal-NO-SPAM.net> wrote in message
    news:%23y1DvaTa FHA.3040@TK2MSF TNGP14.phx.gbl. ..[color=blue]
    > VS 2003, .NET 1.1
    >
    > I'm throughly puzzled here. I can't seem to get the method below to
    > work...
    >
    > private void AutoSizeHeight( )
    >
    > {
    >
    > Graphics g = this.CreateGrap hics();
    >
    > int x, lineCount;
    >
    > SizeF layoutSize = new SizeF(this.Widt h, this.Height * 100); // oversized
    > height
    >
    > this.Height = (int)Math.Ceili ng(g.MeasureStr ing(base.Text, this.Font,
    > layoutSize, new StringFormat(), out x, out lineCount).Heig ht);
    >
    > g.Dispose();
    >
    > // this.Height = 400; // this works
    >
    > // this.Height *= 9; // this works
    >
    > this.Height *= lineCount; // this doesn't work
    >
    > }
    >
    > //---------[end]---------------------
    >
    > This method is part of an inherited TextBox control. It's purpose is to
    > resize the height of the control according to the height of the contents.
    > It works fine if I assign a constant value to height or multiply by a
    > constant. But when I try to multiply by lineCount it doesn't change.
    > Height and lineCount definately both have values but for some reason they
    > won't multiply.
    >
    > I'm I doing something wrong or is there something strange going on?
    >
    > Note: I don't know what it means, but the lineCount is red in the Watch
    > window...
    >
    >[/color]


    Comment

    • Chuck Bowling

      #3
      Re: Method not working

      If I understand correctly, the 'out' keyword in the MeasureString method
      should assign a value to lineCount.


      "Nick Malik [Microsoft]" <nickmalik@hotm ail.nospam.com> wrote in message
      news:KLqdnZSawp 5zZzzfRVn-pg@comcast.com. ..[color=blue]
      >I am confused. In your text, you say that 'lineCount' definitely has a
      >value, yet the code you posted: this variable is not assigned.
      >
      > What gives?
      >
      > --
      > --- Nick Malik [Microsoft]
      > MCSD, CFPS, Certified Scrummaster
      > http://blogs.msdn.com/nickmalik
      >
      > Disclaimer: Opinions expressed in this forum are my own, and not
      > representative of my employer.
      > I do not answer questions on behalf of my employer. I'm just a
      > programmer helping programmers.
      > --
      > "Chuck Bowling" <chuckbowling@s bcglobal-NO-SPAM.net> wrote in message
      > news:%23y1DvaTa FHA.3040@TK2MSF TNGP14.phx.gbl. ..[color=green]
      >> VS 2003, .NET 1.1
      >>
      >> I'm throughly puzzled here. I can't seem to get the method below to
      >> work...
      >>
      >> private void AutoSizeHeight( )
      >>
      >> {
      >>
      >> Graphics g = this.CreateGrap hics();
      >>
      >> int x, lineCount;
      >>
      >> SizeF layoutSize = new SizeF(this.Widt h, this.Height * 100); //
      >> oversized height
      >>
      >> this.Height = (int)Math.Ceili ng(g.MeasureStr ing(base.Text, this.Font,
      >> layoutSize, new StringFormat(), out x, out lineCount).Heig ht);
      >>
      >> g.Dispose();
      >>
      >> // this.Height = 400; // this works
      >>
      >> // this.Height *= 9; // this works
      >>
      >> this.Height *= lineCount; // this doesn't work
      >>
      >> }
      >>
      >> //---------[end]---------------------
      >>
      >> This method is part of an inherited TextBox control. It's purpose is to
      >> resize the height of the control according to the height of the contents.
      >> It works fine if I assign a constant value to height or multiply by a
      >> constant. But when I try to multiply by lineCount it doesn't change.
      >> Height and lineCount definately both have values but for some reason they
      >> won't multiply.
      >>
      >> I'm I doing something wrong or is there something strange going on?
      >>
      >> Note: I don't know what it means, but the lineCount is red in the Watch
      >> window...
      >>
      >>[/color]
      >
      >[/color]


      Comment

      Working...