Solved

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

Posted on 2008-10-22
8
574 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

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…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This video teaches users how to migrate an existing Wordpress website to a new domain.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 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