Storing WebControl.Width and WebControl.Height int variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • xiko tripa

    Storing WebControl.Width and WebControl.Height int variables

    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 MakeCentralTabl e(Panel panel)
    {
    double twoThird = double.Parse(pa nel.Width.ToStr ing()) * 0.66;
    double oneThird = double.Parse(pa nel.Width.ToStr ing()) * 0.33;
    double half = double.Parse(pa nel.Height.ToSt ring()) * 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
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Storing WebControl.Widt h and WebControl.Heig ht int variables

    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]
    - mvp@spam.guard. caspershouse.co m

    "xiko tripa" <xikotripa@bol. com.br> wrote in message
    news:3d5956e5.0 311130500.657ed 825@posting.goo gle.com...[color=blue]
    > 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 MakeCentralTabl e(Panel panel)
    > {
    > double twoThird = double.Parse(pa nel.Width.ToStr ing()) * 0.66;
    > double oneThird = double.Parse(pa nel.Width.ToStr ing()) * 0.33;
    > double half = double.Parse(pa nel.Height.ToSt ring()) * 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[/color]


    Comment

    • Ignacio Machin \( .NET/ C#  MVP \)

      #3
      Re: Storing WebControl.Widt h and WebControl.Heig ht int variables

      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,

      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation

      "xiko tripa" <xikotripa@bol. com.br> wrote in message
      news:3d5956e5.0 311130500.657ed 825@posting.goo gle.com...[color=blue]
      > 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 MakeCentralTabl e(Panel panel)
      > {
      > double twoThird = double.Parse(pa nel.Width.ToStr ing()) * 0.66;
      > double oneThird = double.Parse(pa nel.Width.ToStr ing()) * 0.33;
      > double half = double.Parse(pa nel.Height.ToSt ring()) * 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[/color]


      Comment

      • xiko tripa

        #4
        Re: Storing WebControl.Widt h and WebControl.Heig ht int variables

        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 [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in message news:<#Ytrh1eqD HA.2588@tk2msft ngp13.phx.gbl>. ..[color=blue]
        > 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]
        > - mvp@spam.guard. caspershouse.co m
        >
        > "xiko tripa" <xikotripa@bol. com.br> wrote in message
        > news:3d5956e5.0 311130500.657ed 825@posting.goo gle.com...[color=green]
        > > 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 MakeCentralTabl e(Panel panel)
        > > {
        > > double twoThird = double.Parse(pa nel.Width.ToStr ing()) * 0.66;
        > > double oneThird = double.Parse(pa nel.Width.ToStr ing()) * 0.33;
        > > double half = double.Parse(pa nel.Height.ToSt ring()) * 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[/color][/color]

        Comment

        • xiko tripa

          #5
          Re: Storing WebControl.Widt h and WebControl.Heig ht int variables

          Hi Ignacio

          Thanks for your reply. Please, see my reply to Nicholas.

          Thanks


          "Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT dot.state.fl.us > wrote in message news:<Oj#nTbfqD HA.2632@TK2MSFT NGP09.phx.gbl>. ..[color=blue]
          > 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,
          >
          > --
          > Ignacio Machin,
          > ignacio.machin AT dot.state.fl.us
          > Florida Department Of Transportation
          >
          > "xiko tripa" <xikotripa@bol. com.br> wrote in message
          > news:3d5956e5.0 311130500.657ed 825@posting.goo gle.com...[color=green]
          > > 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 MakeCentralTabl e(Panel panel)
          > > {
          > > double twoThird = double.Parse(pa nel.Width.ToStr ing()) * 0.66;
          > > double oneThird = double.Parse(pa nel.Width.ToStr ing()) * 0.33;
          > > double half = double.Parse(pa nel.Height.ToSt ring()) * 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[/color][/color]

          Comment

          Working...