Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-22
8
Medium Priority
?
582 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to dynamically set the form action using jQuery.
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…

670 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