Answered by:
Screen resolution

Question
-
I have created a C# Winforms app in VS 2008. The font I use is Verdana 8 for the most part and sizes 12 and 14 for various other controls. When I install this app on an older computer that can't change the resolution settings to accomodate this application, there are a lot of controls that are cut off the screen. Some forms have a lot of data and I was trying not to use a very small font.
Is there any way to get around this?Thursday, December 11, 2008 1:27 PM
Answers
-
OK, I finished my testing. In the process I discovered a couple of problem that had to be fixed and they have been fixed. I tested it in a wide range of resolutions starting at 800x600. The code works perfectly at all resolutions but that one is very hard to read. The font becomes too small and at times guessing is involved at least to my eyes.
The form height problem I mentioned was in fact the TabControl problem more than the form's. I introduced a nonlinear factor that grows with the increase in height ever so slightly. It seems to be doing just fine. I would like to hear from you but as far as I can tell it is over.
The resolutions tested:
800 x 600
1024 x 768
1152 x 882
1152 x 900
1280 x 1024
1600 x 1200 default
Discard all previous versions. This is final. One comment: I use a custom TabControl, not MS control. It is reflected in the code. If you have regular one, you must change that. Yours will be "System.Windows.Forms.TabControl"
private void resizeFontsRecursively ( float factorH, float factorV, System.Windows.Forms.Control.ControlCollection crlCol, int width, int height, double factor ) { foreach ( System.Windows.Forms.Control crl in crlCol ) { if ( crl.GetType ( ).ToString ( ) != "TabControlDotNetrix.TabControl_22" ) { crl.Height = ( int )( ( float )crl.Height * factorV ); } else { int newHeight = ( int )( crl.Height * factorV ); double dbHeight = Convert.ToDouble ( newHeight ); dbHeight *= factor; newHeight = Convert.ToInt16 ( dbHeight ); crl.Height = newHeight; } crl.Width = ( int )( ( float )crl.Width * factorH ); float factorVfont = 1F; if ( height < 1200 ) { factorVfont *= 0.8F; } Point pt = crl.Location; Point ptNew = new Point ( ( int )( ( float )pt.X * factorH ), ( int )( ( float )pt.Y * factorV ) ); crl.Location = ptNew; float sz = crl.Font.Size; float sz sz2 = sz * factorV * factorVfont; if ( sz >= 8 ) { string fontFamily = crl.Font.FontFamily.GetName ( 1250 ); bool bold = crl.Font.Bold; if ( bold ) { crl.Font = new System.Drawing.Font ( fontFamily, sz2, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) ); } else { crl.Font = new System.Drawing.Font ( fontFamily, sz2, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) ); } } resizeFontsRecursively ( factorH, factorV, crl.Controls, width, height, factor ); } } // enumFontsRecursively private void resizeAll ( ) { // this must be the maximum withd of the screen hardware wise, not teh screeen resolution // that is actually set up. int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; if ( Environment.OSVersion.ToString ( ) != "Microsoft Windows NT 6.0.6001 Service Pack 1" ) { width = 1280; height = 1024; } if ( width < 1600 | height < 1200 ) { float factorH = ( float )width / 1600F; float factorV = ( float )height / 1200F; this.Width = ( int )( this.Width * factorH ); // nonlinear factor for the form itself // and the tabControl double db = - 0.000026 * Convert.ToDouble ( Math.E - 1 * height ); double factor = Math.Exp ( db ); int newHeight = ( int )( this.Height * factorV ); double dbHeight = Convert.ToDouble ( newHeight ); dbHeight *= factor; newHeight = Convert.ToInt16 ( dbHeight ); this.Height = newHeight; resizeFontsRecursively ( factorH, factorV, this.Controls, width, height, factor ); } } // resizeAll
AlexB- Marked as answer by ski_freak Friday, December 19, 2008 6:43 PM
- Edited by AlexBB - Vista Ult64 SqlSer64 WinSer64 Friday, December 19, 2008 6:47 PM
Friday, December 19, 2008 6:30 PM
All replies
-
OK that seems to work to some extent The scroll bars dont show all the controls but when I use the mouse 'wheel' it scrolls over and displays everything. Is there anything else I need to do/check?Thursday, December 11, 2008 5:18 PM
-
It's a lot of work, but you can tie your conrol sizes to the load event of your form. Set the x and y values to equal some number less than the width of your form.Thursday, December 11, 2008 5:41 PM
-
You might want to consider adding your controls to a scrollable panel control. That way, any cut-off controls can be scrolled to.
Mike G. @ DotNetFun.comThursday, December 11, 2008 5:46 PM -
u mean even form support a scroll bar like a text box , or we must set value of all object on that ?Thursday, December 11, 2008 5:46 PM
-
Yeah that does sound like a lot of work not to mention I would probably have to resize them to a smaller fontThursday, December 11, 2008 5:47 PM
-
deadManN - I have no idea what you just said.
DotNetFun - thats an idea, I will try that and seeThursday, December 11, 2008 5:49 PM -
that's must be hard ... i mean set all controler in scroll object
i accept write 500 line but don't set them :D
Thursday, December 11, 2008 5:51 PM -
I am giving you two simple routines that will do it for you. They warrant some explanation however. I do have a 1600x1200 monitor with Vista on one partition and WinSer2008 on anothe on one of my machinesr. I have no problem with Vista. On the server side teh OS does not want to recognize 1500x1200 resolution and have only 1280x1024. No matter what I tried I could not get more than that with the very same monitor. On top of that I could not find a way to detect this actual operational resolution. So, this code reflects that. There exists code that will detect your monitor resolution but not what you've set. My code does not ahve that part. I hardcode it. Too lazy to improve.
One more thing. When I set up smaller resolution in Vista for test purposes everything scales down perfectly. However, in the Server the fonts do not quite scale down. My explanation is that graphics resources under WinSer2008 are limited and some fonts are not available or the Drawing somehow is defective. I have no idea. I am curious if you describe your actual experience. It may be important for me.
My app has so much stuff in it I am really afraid to take count.
Here is the code:
private void resizeFontsRecursively ( float factorH, float factorV, System.Windows.Forms.Control.ControlCollection crlCol ) { foreach ( System.Windows.Forms.Control crl in crlCol ) { crl.Height = ( int )( ( float )crl.Height * factorV ); crl.Width = ( int )( ( float )crl.Width * factorH ); Point pt = crl.Location; Point ptNew = new Point ( ( int )( ( float )pt.X * factorH ), ( int )( ( float )pt.Y * factorV ) ); crl.Location = ptNew; float sz = crl.Font.Size; szsz = sz * factorH; if ( sz >= 8 ) { string fontFamily = crl.Font.FontFamily.GetName ( 1250 ); bool bold = crl.Font.Bold; if ( bold ) { crl.Font = new System.Drawing.Font ( fontFamily, sz, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) ); } else { crl.Font = new System.Drawing.Font ( fontFamily, sz, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) ); } } resizeFontsRecursively ( factorH, factorV, crl.Controls ); } } // enumFontsRecursively private void resizeAll ( ) { // this must be the maximum withd of the screen hardware wise, not teh screeen resolution // that is actually set up. int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; Console.WriteLine ( Environment.OSVersion.ToString ( ) ); if ( Environment.OSVersion.ToString ( ) != "Microsoft Windows NT 6.0.6001 Service Pack 1" ) { width = 1280; height = 1024; } if ( width != 1600 | height != 1200 ) { Console.WriteLine ( "We are here" ); float factorH = ( float )width / 1600F; float factorV = ( float )height / 1200F; this.Width = ( int )( this.Width * factorH ); this.Height = ( int )( this.Height * factorV ); resizeFontsRecursively ( factorH, factorV, this.Controls ); } } // resizeAll
AlexB- Proposed as answer by deadManN Friday, December 12, 2008 2:49 PM
- Marked as answer by Guo Surfer Thursday, December 18, 2008 6:00 AM
- Unmarked as answer by ski_freak Thursday, December 18, 2008 2:32 PM
Thursday, December 11, 2008 10:41 PM -
Ronald - On one of the forms I do have a tab control and part of whats on the tabs are off the screen
Alex - Cool code, I will check it out, it maybe a few days before I report back but it seems what I am looking for.Friday, December 12, 2008 12:23 AM -
Right, I have pretty much everything with 'AutoScroll' now. For testing I can live with it but in the real world it would be a mess. I hope to look at the code Alex posted by tomorrow.
thanks to everyone for their responses. I will Mark answered when I am doneSunday, December 14, 2008 3:19 PM -
I set the screen resolution to 800x600 and its working somewhat. What is another number I can change (1600F and 1200F) to?
Several listviews are chopped off, datagrid is chopped off for example- Edited by ski_freak Monday, December 15, 2008 6:34 PM type
Monday, December 15, 2008 6:31 PM -
ski_freak said:
I set the screen resolution to 800x600 and its working somewhat. What is another number I can change (1600F and 1200F) to?
Several listviews are chopped off, datagrid is chopped off for example
1280x1024. Open your Control Panel==>Appearance and Personalization==>Adjust Screen Resolution==>Advanced Setting==>List All Modes (In Vista) will give you all resolutions available on your machine. In XP it is available as well. Perhaps thru omputer Management. There should be a few avenues.
Which method are you testing: AutoScroll?
AlexB- Marked as answer by Guo Surfer Thursday, December 18, 2008 6:01 AM
- Unmarked as answer by ski_freak Thursday, December 18, 2008 2:32 PM
Monday, December 15, 2008 6:50 PM -
In XP, you right mouse on the desktop, properties and I set my resolution to 800x600.
I am using the code you posted and AutoScroll = true to the form and each tab (testing with just one form for now)Monday, December 15, 2008 8:58 PM -
Hi ski_freak,
We are marking Ronald's and AlexB's post as answer.
If you still have problem, please feel free to unmark as the answer and change the issue type back to “Question”. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Best regards,
GuoThursday, December 18, 2008 6:03 AM -
Did you not read my comment about me marking it answered when done? Also, as i said in my previous post
I set the screen resolution to 800x600 and its working somewhat. What is another number I can change (1600F and 1200F) to?<BR><BR>Several listviews are chopped off, datagrid is chopped off for example
so to answer your question, it is not working yet. Please allow me to mark it as answered when its working.
Thank you,
MarkThursday, December 18, 2008 2:33 PM -
ski_freak said:
Did you not read my comment about me marking it answered when done? Also, as i said in my previous post
I set the screen resolution to 800x600 and its working somewhat. What is another number I can change (1600F and 1200F) to?<BR><BR>Several listviews are chopped off, datagrid is chopped off for example
so to answer your question, it is not working yet. Please allow me to mark it as answered when its working.
Thank you,
Mark
"Not working yet" is not a good message. You have to say if one or both methods are not working since it appears you are testing both. Secondly you should give details as two what OS you are testing it on, what font you are using, what ranges do work and what don't if this is the case, what exactly happens when it is "not working." As far as the last point you should say if the fonts shrink at all, if there is a reduction in size at least to some degree. What you are doing is a proxy testing for me. I don't have time to do it but I am very interested in your details. Also I may suggest some nonlinear transformation to improve the performance by adding some weighted coefficients to the code. Besides it is not given you are using the code properly. All those details shoulw be explained, I cannot accept your bone-skin statement that it is not working.
The code worked for me perfectly but I tested it on one alternative resolution only.
Another point is, how do you determine the screen resolution? Do you determine it at all or you hardcode it? What kind of controls do you have on your form? Is it a Windows.Forms app?
AlexBThursday, December 18, 2008 6:50 PM -
OK, I have to admit, you are correct. The routine I posted does not work. It took me an hour to fix it however. here is the code. I tested it only on one smaller resolution 1080 x 900. At that resolution it works perfect. I will do some more testing tomorrow. There could be some more complications in the code that I foresee.
These are the corrected routines:
THE CODE HAS BEEN ERASED IN FAVOR OF THE FINAL CORRECTED VERSION, SEE BELOW. // resizeAll
AlexBFriday, December 19, 2008 3:42 AM -
ski_freak said:
I have created a C# Winforms app in VS 2008. The font I use is Verdana 8 for the most part and sizes 12 and 14 for various other controls. When I install this app on an older computer that can't change the resolution settings to accomodate this application, there are a lot of controls that are cut off the screen. Some forms have a lot of data and I was trying not to use a very small font.
Is there any way to get around this?
ski_freak said:Ronald - On one of the forms I do have a tab control and part of whats on the tabs are off the screen
Alex - Cool code, I will check it out, it maybe a few days before I report back but it seems what I am looking for.
ski_freak said:Right, I have pretty much everything with 'AutoScroll' now. For testing I can live with it but in the real world it would be a mess. I hope to look at the code Alex posted by tomorrow.
thanks to everyone for their responses. I will Mark answered when I am done
ski_freak said:I set the screen resolution to 800x600 and its working somewhat. What is another number I can change (1600F and 1200F) to?
Several listviews are chopped off, datagrid is chopped off for example
ski_freak said:In XP, you right mouse on the desktop, properties and I set my resolution to 800x600.
I am using the code you posted and AutoScroll = true to the form and each tab (testing with just one form for now)
Let me know if i missed something. I have tried to put as much as I can in various posts. In the one case I am testing, I have a Winforms form (all Verdana font) that has a tab control. The tab control has 6 tabs, some of the tabs have listviews and datagrids which are getting chopped off using the code you gave me.
To set my screen resolution: I right mouse clicked on the desktop, properties, clicked Settings tab and set the screen resolution to 800x600.
At this point in time in my code I do not determine the resolution as I have never worked on coding resolutions which was my original intent for my posts. Please see my quotes and posts as I thought I gave enough infomation for someone to help me resolve this problem.
I appreciate all the help I have received
This was cute, I will have to use it myself 'Also I may suggest some nonlinear transformation to improve the performance by adding some weighted coefficients to the code'
Thanks,
MarkFriday, December 19, 2008 1:15 PM -
I do have a form with a TabControl with about 13 tabs with a two treeviews on them, many buttons, textboxes, combos, rtf, datagridviews, etc. With the resolution I tested yesterday everything, the sizes, the fonts decreased proportionally. There were two defects. the height of the form shrank somewhat in excess of what is needed and I will have to introduce a coefficient, some sort of nonlinerity. The other thing was that when I opened my texts in rtf the font size was not changed and it remained large (14). I will have to take care of it as well. Otherwise it looked perfect. I hardcode the change and test it in Vista with 1600x1200 resolution but when I hardcode the new resolution I see a much smaller form.
I don't really need it now but in the future I will definitely need this. The fact that I posted the code, you found it defective stimulated me to take care of it in a hurry so I will appreciate your criticism but please describe all details including which version you are testing otherwise I am left guessing. I know now that the idea is working.
I doubt however that it will work as low as 800x600. This is just too much. Everything will be microscopic and hardly readable.
AlexBFriday, December 19, 2008 1:27 PM -
I used the first code you posted ... let me try it with your changes... When I changed my laptop resolution to 800x600 things with the first posted code were in fact larger...
also had to fix this in your 2nd post... fyi
float
szsz2 = sz * factorV * factorVfont;
to
float
sz2 = sz * factorV * factorVfont;- Edited by ski_freak Friday, December 19, 2008 6:11 PM modified
Friday, December 19, 2008 6:05 PM -
OK, I finished my testing. In the process I discovered a couple of problem that had to be fixed and they have been fixed. I tested it in a wide range of resolutions starting at 800x600. The code works perfectly at all resolutions but that one is very hard to read. The font becomes too small and at times guessing is involved at least to my eyes.
The form height problem I mentioned was in fact the TabControl problem more than the form's. I introduced a nonlinear factor that grows with the increase in height ever so slightly. It seems to be doing just fine. I would like to hear from you but as far as I can tell it is over.
The resolutions tested:
800 x 600
1024 x 768
1152 x 882
1152 x 900
1280 x 1024
1600 x 1200 default
Discard all previous versions. This is final. One comment: I use a custom TabControl, not MS control. It is reflected in the code. If you have regular one, you must change that. Yours will be "System.Windows.Forms.TabControl"
private void resizeFontsRecursively ( float factorH, float factorV, System.Windows.Forms.Control.ControlCollection crlCol, int width, int height, double factor ) { foreach ( System.Windows.Forms.Control crl in crlCol ) { if ( crl.GetType ( ).ToString ( ) != "TabControlDotNetrix.TabControl_22" ) { crl.Height = ( int )( ( float )crl.Height * factorV ); } else { int newHeight = ( int )( crl.Height * factorV ); double dbHeight = Convert.ToDouble ( newHeight ); dbHeight *= factor; newHeight = Convert.ToInt16 ( dbHeight ); crl.Height = newHeight; } crl.Width = ( int )( ( float )crl.Width * factorH ); float factorVfont = 1F; if ( height < 1200 ) { factorVfont *= 0.8F; } Point pt = crl.Location; Point ptNew = new Point ( ( int )( ( float )pt.X * factorH ), ( int )( ( float )pt.Y * factorV ) ); crl.Location = ptNew; float sz = crl.Font.Size; float sz sz2 = sz * factorV * factorVfont; if ( sz >= 8 ) { string fontFamily = crl.Font.FontFamily.GetName ( 1250 ); bool bold = crl.Font.Bold; if ( bold ) { crl.Font = new System.Drawing.Font ( fontFamily, sz2, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) ); } else { crl.Font = new System.Drawing.Font ( fontFamily, sz2, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) ); } } resizeFontsRecursively ( factorH, factorV, crl.Controls, width, height, factor ); } } // enumFontsRecursively private void resizeAll ( ) { // this must be the maximum withd of the screen hardware wise, not teh screeen resolution // that is actually set up. int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; if ( Environment.OSVersion.ToString ( ) != "Microsoft Windows NT 6.0.6001 Service Pack 1" ) { width = 1280; height = 1024; } if ( width < 1600 | height < 1200 ) { float factorH = ( float )width / 1600F; float factorV = ( float )height / 1200F; this.Width = ( int )( this.Width * factorH ); // nonlinear factor for the form itself // and the tabControl double db = - 0.000026 * Convert.ToDouble ( Math.E - 1 * height ); double factor = Math.Exp ( db ); int newHeight = ( int )( this.Height * factorV ); double dbHeight = Convert.ToDouble ( newHeight ); dbHeight *= factor; newHeight = Convert.ToInt16 ( dbHeight ); this.Height = newHeight; resizeFontsRecursively ( factorH, factorV, this.Controls, width, height, factor ); } } // resizeAll
AlexB- Marked as answer by ski_freak Friday, December 19, 2008 6:43 PM
- Edited by AlexBB - Vista Ult64 SqlSer64 WinSer64 Friday, December 19, 2008 6:47 PM
Friday, December 19, 2008 6:30 PM -
Thanks.. works great... i appreciate all your effort
MarkFriday, December 19, 2008 6:44 PM -
Yep, I left that debugging comment puprorting that I decided not to implement it for the TabControl but then I took another look and decided to implement it and forgot to delete it. Now I cannot erase it for the life of me. I did implement it for the TabControl. Silly.
AlexBFriday, December 19, 2008 6:49 PM -
Now it is gone. Microsoft is full of mysteries.
AlexBFriday, December 19, 2008 6:55 PM