Disable form resizing in delphi

后端 未结 3 1447
渐次进展
渐次进展 2021-02-18 22:49

Is there any way to stop the user resizing the form?

Currently I am using:

When form size changed....

MainForm.Height := 761;
MainForm.Width := 7         


        
3条回答
  •  耶瑟儿~
    2021-02-18 23:10

    Fixing the size is easy, you have two options:

    1. Delphi forms have a BorderStyle property and a BorderIcons property. If you set BorderStyle to bsDialog, and BorderIcons to biSystemMenu only, user can not resize the form.

    2. You can specify value to Constraints property. If you write the same number to MinWidth and MaxWidth, the width will be fixed.

    Preventing move is more tricky. I can come up with only these solutions now:

    1. Set BorderStyle to bsNone. You will need to draw the form caption yourself, if needed.

    2. Write a message handler to WM_NCHITTEST, call inherited first, then check the Message.Result for HTCAPTION. If it is HTCAPTION, set it to HTCLIENT instead. This way, you fool Windows to think the user didn't click on caption, so he will not be able to drag. Please try if the user can still move the window opening the system menu, and choosing Move. If so, you have to hide the system menu too (BorderIcons).

    Answer found here.

提交回复
热议问题