Solved

How can i convert a System.Web.Ui.WebControls.Unit object from Percent to Pixels

Posted on 2008-10-22
8
575 Views
Last Modified: 2013-12-25
I am drawing graphics dynamically for my web page and need to convert the System.Web.Ui.WebControls.Unit object from percent to pixels if it is supplied in that unit type.  Is there any way to do this?

Thanks.
0
Comment
Question by:eddyevations
  • 4
  • 3
8 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 22782095
The following link may prove helpful to you.

http://support.microsoft.com/kb/79604
0
 

Author Comment

by:eddyevations
ID: 22785274
Thanks,
But i think this will not work on the web...this seems like more of a windows forms solution.
0
 
LVL 10

Expert Comment

by:Bane83
ID: 22786007
Do you know the full size of the image?  Couldn't you just do fullsize * percent = pixels?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:eddyevations
ID: 22790505
I am creating the image based on the control that is hosting it.  If the control is sized in percent i do not know how to convert that to pixels.
0
 
LVL 10

Expert Comment

by:Bane83
ID: 22790603
Ah, I think I understand.  So you're drawing new images (not pulling them from the database or anything) and they need to go into an asp:Image (or perhaps as a background-image to a div or something?) control that's on the page, however you're concerned that the asp:Image control may have it's Height and/or Width set to something like 80% x 90% and you're not sure how to convert that.  Am I right so far?

Well, the way to handle this changes depending on the control that you're trying to place the image in, so please give me a bit more detail.  Let me know how close I am and fill in whatever else you can.
0
 

Author Comment

by:eddyevations
ID: 22791432
Yes, you are correct.  I am trying to dynamically draw an image as the background of a panel.  There are three panels side by side and i know the width of the one on the left and the one on the right, but the centre panel needs to by dynamic based on the width of the control minus the left panel and the right panel... So, if the control width is given in something other than pixels, i need to be able to convert that to pixels in order to create my graphic for the centre panel.

Thanks.
0
 
LVL 10

Accepted Solution

by:
Bane83 earned 500 total points
ID: 22793354
Hum, definitely a tricky one.  I don't suppose there's any way for you to always know the exact width of the parent to the control?  Of course not, that would make life easy. :P

Well, there's no way for you to know the width of the control until it's actually been rendered (except for in the above case some times).  This means you'll have to use some AJAX callbacks.

Once your page is done loading, you can find the control in the DOM and get the offsetWidth property.  This will tell you it's pixel width on screen.  You can then subtract the pixel widths of the left and right panels from it and make your AJAX call to the image generator.
0
 

Author Closing Comment

by:eddyevations
ID: 31508978
Thanks Bane83.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question