Now not all controls can be moved that way, i.e., Line controls. Comboboxes typically have a fixed height (depending on properties) and trying to change the height results in an error in that case.
Edited: same applies when moving an item vs. moving & resizing. Use the Move method and supply the new left/top coordinates. Otherwise, setting the Top and Left properties individually results in 2 move actions
Last edited by LaVolpe; Aug 12th, 2020 at 01:00 PM.
Insomnia is just a byproduct of, "It can't be done"
I had to change the form's borderstyle so I can resize it to see the problem.
The problem is the way you are trying to prevent the form from be resized. Each time someone tries to size the form, you tell the form to go back to another size. This is at least 2 to 4 resizing actions and maybe more, each time the mouse is dragging the border edges for sizing.
What is your goal regarding the user sizing the form?
Insomnia is just a byproduct of, "It can't be done"
What is your goal regarding the user sizing the form?
I'm trying to develop an application for Windows Tablet (Win10 Pro), and I wish the Form has only two size, first initial size (full screen), but to be able to have second size (fixed windowed 800x600 pixels), and all application controls (TextBox, Labels, CommandButtons, ListView, etc...) would be placed into the PictureBox (Container), so, the PictureBox would be always centered in the Form.
That's why I set the Form BorderStyle to be fixed, not sizable by mouse by user.
I have some trouble resizing the Form and the controls inside the PictureBox, it flickers while resizing the Form.
What flickers? Do you mean the form is flickering when you are setting its position? The PictureBox is not flickering and the controls inside of it are not flickering. You have to provide a better demo and instructions how to produce the flickering you want to prevent. Usually it's as simple as putting your controls inside a PictureBox and using WM_SETREDRAW -- very simple if there is a reproducable sample code of the problem.
Just don't use LockWindowUpdate API for anything -- it's not designed to prevent flicker in any way. Au contraire -- it *forces* your desktop icons to flicker. Just don't use it for anything, forget about it. I'll petition MS to remove it or make it a noop in future versions of Windows.
What flickers? Do you mean the form is flickering when you are setting its position? The PictureBox is not flickering and the controls inside of it are not flickering.
The PictureBox (as a Container) flickers while you are resizing the Form, you clearly see the inside controls how they are moving.
Ok, I see what the problem is with this approach. Form's Resize event is too late to prevent flicker as the form is already positioned/sized and so controls get repainted when moved around at this point.
You'll need to handle WM_SYSCOMMAND specifically wParam = SC_MAXIMIZE and wParam = SC_RESTORE if you are willing to implement form subclassing that is.
What might work is first disable WM_SETREDRAW before passing WM_SYSCOMMAND to next SubclassProc, then position controls in form's Resize event as already implemented and finally enabling WM_SETREDRAW before returning from SubclassProc.
Edit: No, this didn't work.
What worked on my monitor was this
Code:
Public Function SubclassProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long, Handled As Boolean) As Long
Select Case wMsg
Case WM_SYSCOMMAND
If wParam = SC_RESTORE Then
Picture1.Move 0, 0
ElseIf wParam = SC_MAXIMIZE Then
Picture1.Move 9360, 3666
End If
End Select
End Function
Of course the position on SC_MAXIMIZE has to be calculated based on monitor estimated size (the one the form is placed on) and form's border/title size which is an effort in its own right.
cheers,
</wqw>
Last edited by wqweto; Aug 13th, 2020 at 05:55 AM.
Public Function SubclassProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long, Handled As Boolean) As Long
Select Case wMsg
Case WM_SYSCOMMAND
If wParam = SC_RESTORE Then
Picture1.Move 0, 0
ElseIf wParam = SC_MAXIMIZE Then
Picture1.Move 9360, 3666
End If
End Select
End Function
Okay, any idea to be able to start with it, implementing calling, destroying it after or?
Had to remove Form_Resize implementation altogether and position Picture1 inside WM_SYSCOMMAND. Not the best of code, more like total kludge, don't use in production.
Hi beic - I see the flicker when changing your form position.
I tried wqweto suggestion on subclassing, and used iPrank’s code (https://www.vbforums.com/showthread....on-in-MDI-Form) to capture the repositioning event prior to form repainting. During that capture, the module1 repositions your Picture1. Flicker appears to be gone.
There is minimal change to your code. All you need to add is the module1, and
Hi beic - I see the flicker when changing your form position.
I tried wqweto suggestion on subclassing, and used iPrank’s code (https://www.vbforums.com/showthread....on-in-MDI-Form) to capture the repositioning event prior to form repainting. During that capture, the module1 repositions your Picture1. Flicker appears to be gone.
There is minimal change to your code. All you need to add is the module1, and
Hi beic - I see the flicker when changing your form position.
I tried wqweto suggestion on subclassing, and used iPrank’s code (https://www.vbforums.com/showthread....on-in-MDI-Form) to capture the repositioning event prior to form repainting. During that capture, the module1 repositions your Picture1. Flicker appears to be gone.
There is minimal change to your code. All you need to add is the module1, and
Hi beic- I don't have any experience with MDIForms, sorry about that. However, I imagine the principle would be the same, per form. I think you would have to 'hook' and 'un-hook' each form's resize (or reposition) event independently. And the Module would need to be re-written so that the Module would know which form to respond to. While the last solution I provided worked to remove the flicker, I admit it is inelegant. I think a nicer solution would be a general purpose module or class written to provide a generic "Pre-Resize" event, that could provide that service to any form for any similar purpose in the future. But before going through all that hassle, does the MDIForm Child even flicker?
Last edited by SeabrookStan; Aug 16th, 2020 at 06:14 PM.
But before going through all that hassle, does the MDIForm Child even flicker?
Yes, it can be seen while the Child are being resized and moved inside MDIForm using same functions ResizeForm and CenterForm inside my example project.