Method not working

C

Chuck Bowling

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.CreateGraphics();

int x, lineCount;

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

this.Height = (int)Math.Ceiling(g.MeasureString(base.Text, this.Font,
layoutSize, new StringFormat(), out x, out lineCount).Height);

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...
 
N

Nick Malik [Microsoft]

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.
 
C

Chuck Bowling

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


Nick Malik said:
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 said:
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.CreateGraphics();

int x, lineCount;

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

this.Height = (int)Math.Ceiling(g.MeasureString(base.Text, this.Font,
layoutSize, new StringFormat(), out x, out lineCount).Height);

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top