![fit image to width of screen blocs app fit image to width of screen blocs app](https://miro.medium.com/max/564/1*UJoIjb9bfP8iQIdOkLPYHg.jpeg)
![fit image to width of screen blocs app fit image to width of screen blocs app](https://venturebeat.com/wp-content/uploads/2017/12/echospot-3.jpg)
In the later case, the result looks sort of like it was drawn in crayon. That's okay if you are only increasing the form size slightly, perhaps from a screen size of 640 x 480 to one of 720 x 480, but it looks a bit silly if you go from a 640 x 480 screen to 1600 x 1200 pixels. This technique fills the form with controls but it doesn't give the user any new information it just makes things bigger. This example also does not stretch pictures.įor a more complete example, see the Stretchable control in my book Custom Controls Library. For example, if you place a TextBox inside a PictureBox, the TextBox's position and dimensions are relative to the PictureBox not the form. Note that this example does not scale controls within other controls. If WindowState = vbMinimized Then Exit Sub ReDim m_ControlPositions(1 To Controls.Count) ' Save the controls' positions and sizes. ' Save the form's and controls' dimensions. Private m_ControlPositions() As ControlPositionType This routine loops through each of the controls scaling their size and position properties appropriately for the form's new size. When the form is resized, the Form_Resize event handler calls subroutine ResizeControls.
Fit image to width of screen blocs app code#
Notice how the code handles Line controls specially because they have X1, Y1, X2, and Y2 properties instead of the usual Left, Top, Width, and Height properties.
![fit image to width of screen blocs app fit image to width of screen blocs app](https://cdn.wccftech.com/wp-content/uploads/2021/09/iPhone-13-Pro-screen-protectors.jpg)
This routine saves each control's size and position in an array of the ControlPositionType user-defined type (UDT). When the program starts, the Form_Load event handler calls subroutine SaveSizes. Probably the most popular solution to the form sizing dilemma is to resize the form's controls automatically so they fill the form. In that case, you may want to simply tell the user not to use higher spatial resolutions and you won't have to worry about them. Your program may become unusable at these higher spatial resolutions. If your application displays photographic images or uses lots of colors, some of the colors may be lost. If you expect users to set their screens to use very high spatial resolution, you should also expect them to be using low color resolution. If I go to 1660 x 1200 pixels, however, the system only has enough graphic memory to display 8-bit color (256 colors). On my computer, I can display 24-bit color at up to 1280 x 1024 pixels. When you design for different resolutions, remember that color resolution and pixel resolution are related. If you like, you can add a picture or pattern to the form so the background is not completely blank. ' At design time we set: ' ControlBox = False ' Caption = "" ' WindowState = Maximized ' BorderStyle = FixedSingle Then you only need to center the PictureBox. This is easiest if you place the controls inside a PictureBox. Then center the form's controls in the form. Simply maximize the form by setting the WindowState property to vbMaximized. Fortunately it's easy to cover the entire screen. That generally does not change the program's usability, but it can be distracting. This method also leaves some of the screen uncovered. If the screen is 800 x 600, you could display a lot more data.
Fit image to width of screen blocs app full#
The disadvantage of this technique is that it does not take full advantage of the screen if it has a greater resolution than 640 x 480. It requires no special changes or rearrangement of controls at run time. Wa_hgt = ScaleY(wa_info.Bottom, vbPixels, vbTwips) Wa_wid = ScaleX(wa_info.Right, vbPixels, vbTwips) If SystemParametersInfo(SPI_GETWORKAREA, _ Private Sub CenterForm(ByVal frm As Form) ' Center the form taking the task bar ' into account. Private Declare Function SystemParametersInfo Lib "user32" _Īlias "SystemParametersInfoA" (ByVal uAction As Long, _īyVal uParam As Long, ByRef lpvParam As RECT, _ When the screen is larger, you can center it, taking the task bar into account like this: So what can you do to ensure that a form will look good at all resolutions? Here are some approaches you can take:ĭesign your form for the smallest screen the users will have, probably 640 x 480 pixels. My computer can run at these resolutions: Modern computers can work at many different resolutions depending on how many colors they display. You designed it with 800 x 600 pixels so the form doesn't fit. Then you distribute the program and your customers run it on a screen with 640 x 480 pixels. You position every control exactly to achieve the perfect visual effect. Suppose you carefully craft a form sized to fit your screen. This tutorial describes several ways a program can handle different screen resolutions. VB Helper: Tutorial: Size Forms to Fit the Screen