PDA

View Full Version : Form showing odd sizes



tramyer
01-18-2018, 01:16 AM
Hi Mates,

I have used a code that allows me to remove the Xbutton in a form.

But it seems that i need to resize my Form in VBA editor in order to show the size that i want.

21386<--- Resized from VBA editor :banghead:

21385<-- and when i try to run it it shows like this.

Can someone help me out thanks in advance.

georgiboy
01-18-2018, 09:11 AM
You may be better off deactivating the X button rather than removing it.

This will also give you the opportunity to explain to the user why it is deactivated via use of a message box.

Hope this helps

SamT
01-18-2018, 11:59 AM
The "Forms" shown on those two images are the same size on my screen.
The top image does not have a command button.
The bottom image does not have a Title Bar.

tramyer
01-19-2018, 12:12 AM
Hi georiboy,

I need to hide the xbutton so that. It will have a good looking msgbox. And sometimes it allows the user to just use the x box to close the msgbox. So to avoid that i need to remvoe the xbutton.

tramyer
01-19-2018, 12:14 AM
The "Forms" shown on those two images are the same size on my screen.
The top image does not have a command button.
The bottom image does not have a Title Bar.

Yes the code removes the title bar (xbutton). But in return i have to resize my form in VBA editor just to show the desired size i want. May the code adjuses the size of the form. Moving it downard so that the user will not be able to see the xbutton.

georgiboy
01-19-2018, 03:47 AM
Maybe try to hide only the x button and not the whole bar:


Private Const GWL_STYLE = (-16)Private Const WS_SYSMENU = &H80000
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "User32" (ByVal hWnd As Long) As Long


Private Sub UserForm_Initialize()

Dim FndForm, tpe

FndForm = FindWindow(vbNullString, Me.Caption)

If FndForm <> 0 Then
tpe = GetWindowLong(FndForm, GWL_STYLE)
tpe = SetWindowLong(FndForm, GWL_STYLE, tpe And Not WS_SYSMENU)
DrawMenuBar FndForm
End If

End Sub

Hope this helps