Size chart control in window of user monitor.

I am trying to write code that will determine the resolution of the screen the user is using in order to properly size charts.  I am having trouble getting anything to work. Can someone please help? I am using ASP.Net chart control and vb.net.

Following is code that does not work.

Thanks for the help.

Dim CurScreenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim CurScreenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
        Dim DesignWidth As Integer = 1680        
Dim DesignHeight As Integer = 1050 
        Dim WidthRatio As Single
        Dim HeightRatio As Single

        WidthRatio = CurScreenWidth / DesignWidth
        HeightRatio = CurScreenHeight / DesignHeight

        Dim ChartWidth As Single = DesignWidth * WidthRatio * 0.96         
Dim ChartHeight As Single = DesignHeight * HeightRatio * 0.85

Open in new window

rckrchAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenDBACommented:
Hi rckrch,

The problem seems to be lines 7 and 8, where you're dividing integers.  Convert to the integers to a float or real type and your code should work.


        WidthRatio = (single)CurScreenWidth / (single)DesignWidth
        HeightRatio = (single)CurScreenHeight / (single)DesignHeight


Good Luck!
Kent
rckrchAuthor Commented:
Thanks Kent for the reply.  However, the WidthRatio and HeightRatio work fine.  I get the appropriate result for the variables.  The formula in the code returns the correct numbers, but the chart size is still not adjusted to the screen resolution.
Kent OlsenDBACommented:
Oh.  Ok.  :)

What's the context of this code?  It looks like the snippet is creating the variables ChartWidth and ChartHeight, and setting them.  The values need to be stored in the variables (properties) that are associated with the control.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

rckrchAuthor Commented:
This code is in the page load.  The chart width property  is set in this procedure with Chart1.Width = ChartWidth.  Stepping through the procedure I get all of the variables to calculate correctly, but the chart dimensions are much smaller that the screen.  This works on my development server, but not on the production server.
Kent OlsenDBACommented:
I've never experienced this.  I've only read of similar behavior reported by others, and it has been reported quite often.

It seems that the cause is almost always a conflict with other installed software.  A registry setting, common DLL, or other item that should be benign is causing a different behavior in different environments.

One trick that seems relevant here is to Lock and then UnLock the control.  It seems that the control can inherit a Locked status and explicitly locking and unlocking can clear it.

Give that a try.
rckrchAuthor Commented:
I don't know what locking and unlocking a control means.
Kent OlsenDBACommented:
"Locked" is just a property of the form / control.

Chart1.Locked = true;
Chart1.Locked = false;

Try this just before you set the size.
rckrchAuthor Commented:
"Locked" is not among the list of properties on my asp.net chart control.
Kent OlsenDBACommented:
Apologies.  I misunderstood and thought this was a VB object.

Let me do a bit more research.  Or maybe one of our other experts can join in.
rckrchAuthor Commented:
Thanks
rckrchAuthor Commented:
I used a function in javascript to identify the variable for width 'document.getElementById('<%=PanelWidth.ClientID%>').value'.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.