Storing WebControl.Width and WebControl.Height int variables

  • Thread starter Thread starter xiko tripa
  • Start date Start date
X

xiko tripa

Hi. I have an apsx page with a Panel inside. The panel has his
properties Width and Height set to 590 and 390 respectively.

I call a function to make up an table inside this panel. That table
has 2 columns. The size of the first one has 2/3 of the panel.width
and the size of the second one has 1/3 of the panel.width.

The only way I got to calculate these values was:

private void MakeCentralTable(Panel panel)
{
double twoThird = double.Parse(panel.Width.ToString()) * 0.66;
double oneThird = double.Parse(panel.Width.ToString()) * 0.33;
double half = double.Parse(panel.Height.ToString()) * 0.5;

First I tryied to convert panel.Width and .Height this way:

double twoThird = (double) panel.Width * 0.66;

but I got an error saying that the compiler cannot cast Unit.Pixel to
double. Ok I understand I cannot cast an object to a type value. But
converto to string and follow convert to double just to store in a
double variable seems to me to much work for nothing.

Can anyone tell if there's a simpler way to do this?

Thanks
 
xiko,

Instead of using actual pixels (or some other absolute unit, which
really isn't a good way to do it), why not set the Width property to a Unit
which was generated using the static Percentage method on the Unit
structure? The width of a panel is in units, and that is a combination of a
number, and a unit of measurement.

Hope this helps.
 
Hi Xiko,

Are you generating your table dinamically? if so you could use the
Attributes property of the HtmlTableCell to set the width from the client
view, in such a way you could do something like:
htmltablecell_1.Attributes.Add( "width", "33%");
htmltablecell_2.Attributes.Add( "width", "67%");

I haven't tested it but I think it could work.

in this way you could avoid setting the value in pixels


Hope this help,
 
Hello Nicholas

Yes you're right, I could use the Percentage method. But my question
is about how to store width and height values into variables for use
to other purposes later.

I'm wondering how to cast Unit.xxx() values to some type variable in
order to store and recover these values sometime in code execution for
some reason, and I didn't find how to do that.

Excuse me my bad English, it's not my first language. I'm trying to do
my best to be understandable.

Thanks

Nicholas Paldino said:
xiko,

Instead of using actual pixels (or some other absolute unit, which
really isn't a good way to do it), why not set the Width property to a Unit
which was generated using the static Percentage method on the Unit
structure? The width of a panel is in units, and that is a combination of a
number, and a unit of measurement.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

xiko tripa said:
Hi. I have an apsx page with a Panel inside. The panel has his
properties Width and Height set to 590 and 390 respectively.

I call a function to make up an table inside this panel. That table
has 2 columns. The size of the first one has 2/3 of the panel.width
and the size of the second one has 1/3 of the panel.width.

The only way I got to calculate these values was:

private void MakeCentralTable(Panel panel)
{
double twoThird = double.Parse(panel.Width.ToString()) * 0.66;
double oneThird = double.Parse(panel.Width.ToString()) * 0.33;
double half = double.Parse(panel.Height.ToString()) * 0.5;

First I tryied to convert panel.Width and .Height this way:

double twoThird = (double) panel.Width * 0.66;

but I got an error saying that the compiler cannot cast Unit.Pixel to
double. Ok I understand I cannot cast an object to a type value. But
converto to string and follow convert to double just to store in a
double variable seems to me to much work for nothing.

Can anyone tell if there's a simpler way to do this?

Thanks
 
Back
Top