Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
CSS
I'm making a Windows Form that has a background image using Image Stretch property to be automatically resized while the screen is resized, but what I'm needing is a control like a button for example and also the text of the button using the Fill Dock Property, will also be automatically resized while the screen and the background image of the screen is resized.
The result that I need is similar to the program that can be seen by downloading <a href="http://www.mediafire.com/download/h8z52if6pswe90b/TM-L500A.rar">here</a>

Note that in this example the application the buttons and text buttons are also resized automatically according to the screen and the background image of the screen is resized.
How can I do this in C#?

Many thanks in advance.
Kind regards,
Posted

About 5 days ago, in the context of a Windows Form Application, there was a similar question, and you might find my dialog (in the comments) with the OP, and my posted (outline of a) "solution" useful: [^].

But, I advise you against attempting dynamic re-sizing and re-positioning of Win Form Controls unless absolutely necessary: imho, too much work for too little a return, and a good chance that arbitrary re-sizing will result in a UI that looks terrible.
 
Share this answer
 
Comments
Levi Henrique EPSON 18-Dec-13 8:16am    
Hello BillWoodruff6,

I appreciate the advice and answer, but I'm doing this kind much need dynamic re-sizing similar to the sample application I have made available for download. I agree that seems to be a big job to get it but I do dynamic re-sizing to be very useful and better for the user
BillWoodruff 18-Dec-13 9:02am    
I agree with Sergey that properly designed Win Forms can use Docking and Anchor Properties ... and perhaps some clever use of enclosing Panels or other ContainerControls ... to give good layouts.

When you resize Controls in WinForms, and you try to scale things like fonts, you may be very unsatisfied with the results.

If you could use WPF, you'd have all the built-in vector-based graphic horsepower to make things look really good at any zoom, re-size.

I'm still waiting for my client from a few years ago to give me permission to post a full code example.

good luck, Bill
Levi Henrique EPSON 18-Dec-13 9:57am    
BillWoodruff and Sergey Alexandrovich,

seems then that there is not an easy way to do what I need using Visual Studio C # own resources. Can you tell me if there is any example of source or something in WPF that can help me in this situation? Thank you very much.
Sergey Alexandrovich Kryukov 18-Dec-13 8:54am    
The right approach to this problem is to use the resizing feature which are already in the library, such as docking. In other word, the application code should not directly handle resize events, it should have proper layout, that's all.

Please see my answer, the second reference including a rudimentary sample.

—SA
Maciej Los 18-Dec-13 8:59am    
Absolutely right!
Please see my past answers:
Zom Out malfunctions when Screen resolution changes[^],
how to dock button so that it can adjust with the form[^].
[EDIT]

Answering the question about WPF. In WPF, everything is the pretty much the same as in System.Windows.Forms, but it has one additional feature which would allow you to automatically re-scale absolutely everything, images, vector or pixel graphics, any controls, everything. This is the decorator System.Windows.Controls.Viewbox:
http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox%28v=vs.110%29.aspx[^].

As I already mentioned, you probably need to take care of the aspect ratio of an image. This is done via the property System.Windows.Controls.Viewbox.Streatch:
http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.stretch.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.stretch.aspx[^].

Here you can find a clear explanation of it: http://stackoverflow.com/questions/288954/how-do-i-keep-aspect-ratio-on-scalable-scrollable-content-in-wpf[^].

—SA
 
Share this answer
 
v3
Comments
Maciej Los 18-Dec-13 8:59am    
+5!
Sergey Alexandrovich Kryukov 18-Dec-13 9:05am    
Thank you, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900