Solved

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

Posted on 2008-10-22
8
568 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:xDJR1875
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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now