We can add many different controls, such as text boxes, add to the Visual Basic's window. During the design period, the size and position of the control can be adjusted. Text introduction This control is modified during the run during the operation of the Visual Basic application.
Running the size of the control ---- When you design the Visual Basic application, you can simply add controls to the form as needed, for example, text box control provides programs with a minimum function of word processing programs. .
---- The size of the control must be set during the design period. However, through the use of two Windows API functions: getWindowlong and setWindowlong, we can change a control at the time of running, such as a text box control.
---- When a control, an example is added to the Visual Basic application program, this is an entered a new window. Each window created in the Windows Operation System has some kind of style property, such as, one text box control can have an ES_MULTILINE window style. This tells Windows that control is a multi-line editing control.
---- Tongmong, a text box control cannot be reset to be larger during operation. However, through the style of change control, the user will be able to adjust the physical measurement of this box during the program operation.
---- This can be completed by calling the getWindowlong and SetWindowlong functions. First, call the getWindowlong function to provide this box control when the window control is the style of windows. This time, can use the OR bit operator to set the WS_THICKFRAME attribute for this box control. A window with a WS_THICKFRAME attribute will draw a crude frame on its border. It can be used to change the size of the window to change the window.
---- Running the setWindowlong function, which tells Windows to modify the style of this box control.
---- The latest, fixing this box update, so that its new bit and size is registered in the window below it, the SETWINDOWPOS function can be used to complete this work.
Sample Examples ---- This program shows that in Visual Basic, if you want to create a variable-size text box control at the time of running.
---- 1. In the Visual Basic, a new process is started, using the default method to build FORM1. ---- 2. Add as follows and sound statements to FORM1's universal sounding part (Note Each sound statement needs to be written in one line):
---- Private Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long ---- Private Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long ---- Private Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal CX As Integer, ByVal CY As Integer, ByVal wFlags AS integer ---- const swP_nosize = & h1 ---- const swP_nozorder = & h4 ---- const swP_nomove = & h2 ---- const swP_drawframe = & h20 ---- const gwl_style = (-16) ---- Const ws_thickframe = & h40000
---- For the use of Visual Basic 5.0, the use of Visual Basic 5.0 is needed to add the following statement to the Welmic sound specification of Form1 (note that each sound statement needs to be written in one line):
---- 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 SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long , Byval Cy As Long, BYVAL WFLAGS As Long) As long ---- const swP_nosize = & h1 ---- const swP_nozorder = & h4 ---- const swP_nomove = & h2 ---- const swP_drawframe = & H20 ---- Const GWL_Style = (-16) ---- Const WS_THICKFRAME = & H40000
---- 3. Add a command button control on Form1, and use the default method to build Comand1. Setting its CAPTION attribute to "change the text box control size"
---- 4. Add the following code to the COMMAND1 clicking: ---- Private submmand1_click () ---- Resizecontrol Text1, Form1 ---- End Sub
---- 5. Add a text box control on Form1, and use the default method to build TEXT1.
---- 6. Creating a new function called Resizecontrol, add the following code to this function:
---- Sub ResizeControl (ControlName As Control, FormName As Form) ---- Dim NewStyle As Long ---- NewStyle = GetWindowLong (ControlName.hWnd, GWL_STYLE) ---- NewStyle = NewStyle Or WS_THICKFRAME ---- NewStyle = SetWindowLong (Text1.hWnd, GWL_STYLE, NewStyle) ---- SetWindowPos ControlName.hWnd, FormName.hWnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME ---- End Sub
---- Press F5 to run the sample order, click the command button to change the size of this box to change the size of this box.