在两个ListView控件之间放一个Picture1控件,属性设:Appearance=0,BorderStyle=0,Backcolor=窗体背景颜色,MouseIcon=图标文件,MousePointer=99,Width=60,Heigth=ListView1.Height=ListView2.Height 定义一个变量 dim mbMoving as boolean Const sglSplitLimit=500Private Sub Picture1_MouseDown( Button As Integer, Shift As Integer, X As Single, Y As Single) Picture1.BackColor = &H808080 mbMoving = True End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim sglPos As Single If mbMoving Then sglPos = X + Picture1.Left If sglPos < sglSplitLimit Then Picture1.Left = sglSplitLimit ElseIf sglPos > me.Width - sglSplitLimit Then Picture1.Left = me.Width - sglSplitLimit Else Picture1.Left = sglPos End If End If End SubPrivate Sub Picture1_MouseUp( Button As Integer, Shift As Integer, X As Single, Y As Single) call SizeControls(Picture1.Left) mbMoving = False End Subpublic sub SizeControls(byval X as Single) If X < 1500 Then X = 1500 If X > (me.Width - 1500) Then X = me.Width - 1500 ListView1.Width = X - 15 ListView2.Left = X + Picture1.Width ListView2.Width = Me.Width - X - 165 End sub
http://211.141.67.12/vb/z.zip 给分 我为了 你挂上的!!!!!
'文本框的缩放 Dim x0, y0 As IntegerPrivate Sub Form_Load() Text1.Text = "控件的缩放" End SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) x0 = X y0 = Y End SubPrivate Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If X > Text1.Width - 100 And X < Text1.Width + 100 Then If Y < Text1.Height - 200 And Y > 100 Then Text1.MousePointer = 9 If Button > 0 Then Text1.Text = "右侧缩放" Text1.Width = X End If Else If Y > Text1.Height - 100 And Y < Text1.Height + 100 Then
Text1.MousePointer = 8 If Button > 0 Then Text1.Text = "双向缩放" Text1.Width = X Text1.Height = Y End If End If End If Else If Y > Text1.Height - 100 And Y < Text1.Height + 100 Then Text1.MousePointer = 7 If Button > 0 Then Text1.Text = "下侧缩放" Text1.Height = Y End If Else Text1.MousePointer = 0 If Button > 0 Then Text1.MousePointer = 5 Text1.Text = " 移动" Text1.Left = Text1.Left + X - x0 Text1.Top = Text1.Top + Y - y0 End If End If End If End SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Text1.Text = "控件的缩放" End Sub
这是我在一个老外的网站上看到的一篇文章,希望对你有所帮助: 在程序中用鼠标拖动改变文本框大小:I once had occasion to require a textbox that the user could size dynamically at runtime. By experimenting with the Windows APIs GetWindowLong, SetWindowLong, and SetWindowPos, I was able to create a textbox which, on command, had its fixed 3d border change into a sizeable border.
BAS Module Code
Place the following code into the general declarations area of a bas module: --------------------------------------------------------------------------------
Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ?1996-2002 VBnet, Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' You are free to use this code within your own applications, ' but you are expressly forbidden from selling or otherwise ' distributing this source code without prior written consent. ' This includes both posting free demo projects made from this ' code as well as reproducing the code in text or html format. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''windows constants Public Const SWP_DRAWFRAME As Long = &H20 Public Const SWP_NOMOVE As Long = &H2 Public Const SWP_NOSIZE As Long = &H1 Public Const SWP_NOZORDER As Long = &H4 Public Const SWP_FLAGS As Long = SWP_NOZORDER Or SWP_NOSIZE Or _ SWP_NOMOVE Or SWP_DRAWFRAME Public Const GWL_STYLE As Long = (-16) Public Const WS_THICKFRAME As Long = &H40000Public Declare Function GetWindowLong Lib "user32" _ Alias "GetWindowLongA" _ (ByVal hwnd As Long, _ ByVal nIndex As Long) As LongPublic Declare Function SetWindowLong Lib "user32" _ Alias "SetWindowLongA" _ (ByVal hwnd As Long, _ ByVal nIndex As Long, _ ByVal dwNewLong As Long) As LongPublic 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 '--end block--'
Form Code
To a form add a text box (Text1), a command button (Command1), 2 menu items (mnuSize & mnuRestore), and 2 labels (Label1 & Label2). Add the following code to the form: --------------------------------------------------------------------------------
Option Explicit 'variables initially set in Form_Load, 'used to reset default values Dim initBoxStyle As Long Dim initLeft As Integer Dim initTop As Integer Dim initWidth As Integer Dim initHeight As IntegerPrivate Sub Form_Load() 'position the form Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
'set up a few variables needed later initBoxStyle = GetWindowLong(Text1.hwnd, GWL_STYLE) initLeft = Text1.Left initTop = Text1.Top initWidth = Text1.Width initHeight = Text1.Height 'make sure the defaults are set SetControlStyle initBoxStyle, Text1
Label1.Caption = "Text Width : " & Text1.Width Label2.Caption = "Text Height : " & Text1.HeightEnd Sub Private Sub Form_Unload(Cancel As Integer) 'restore the control to a normal textbox SetControlStyle initBoxStyle, Text1End Sub Private Sub Form_Click() 'restore the control to a normal textbox SetControlStyle initBoxStyle, Text1
End Sub Private Sub mnuSize_Click() Dim style As Long
'get the current style attributes for the textbox style = GetWindowLong(Text1.hwnd, GWL_STYLE)
'modify the style to show the sizing frame style = style Or WS_THICKFRAME
'set the control to the chosen style SetControlStyle style, Text1End Sub Private Sub mnuRestore_Click() 'restore the control to a normal textbox SetControlStyle initBoxStyle, Text1
End Sub Private Sub Command1_Click() Unload Me End Sub Private Sub SetControlStyle(style, X As Control)
If style Then Call SetWindowLong(X.hwnd, GWL_STYLE, style) Call SetWindowPos(X.hwnd, Form1.hwnd, 0, 0, 0, 0, SWP_FLAGS) End IfEnd Sub '--end block--'
Comments Save the app & run. Clicking the 'Size' menu item will cause the textbox border to change into a sizeable frame. After resizing, clicking the form or selecting 'Restore' will return the textbox to the normal textbox style at the selected size and position.This same technique can also be successfully applied to lists, listviews, treeviews, picture boxes ... pretty well most VB controls.
定义一个变量
dim mbMoving as boolean
Const sglSplitLimit=500Private Sub Picture1_MouseDown( Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.BackColor = &H808080
mbMoving = True
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim sglPos As Single
If mbMoving Then
sglPos = X + Picture1.Left
If sglPos < sglSplitLimit Then
Picture1.Left = sglSplitLimit
ElseIf sglPos > me.Width - sglSplitLimit Then
Picture1.Left = me.Width - sglSplitLimit
Else
Picture1.Left = sglPos
End If
End If
End SubPrivate Sub Picture1_MouseUp( Button As Integer, Shift As Integer, X As Single, Y As Single)
call SizeControls(Picture1.Left)
mbMoving = False
End Subpublic sub SizeControls(byval X as Single)
If X < 1500 Then X = 1500
If X > (me.Width - 1500) Then X = me.Width - 1500
ListView1.Width = X - 15
ListView2.Left = X + Picture1.Width
ListView2.Width = Me.Width - X - 165
End sub
给分
我为了 你挂上的!!!!!
Dim x0, y0 As IntegerPrivate Sub Form_Load()
Text1.Text = "控件的缩放"
End SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
x0 = X
y0 = Y
End SubPrivate Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If X > Text1.Width - 100 And X < Text1.Width + 100 Then
If Y < Text1.Height - 200 And Y > 100 Then
Text1.MousePointer = 9
If Button > 0 Then
Text1.Text = "右侧缩放"
Text1.Width = X
End If
Else
If Y > Text1.Height - 100 And Y < Text1.Height + 100 Then
Text1.MousePointer = 8
If Button > 0 Then
Text1.Text = "双向缩放"
Text1.Width = X
Text1.Height = Y
End If
End If
End If
Else
If Y > Text1.Height - 100 And Y < Text1.Height + 100 Then
Text1.MousePointer = 7
If Button > 0 Then
Text1.Text = "下侧缩放"
Text1.Height = Y
End If
Else
Text1.MousePointer = 0
If Button > 0 Then
Text1.MousePointer = 5
Text1.Text = " 移动"
Text1.Left = Text1.Left + X - x0
Text1.Top = Text1.Top + Y - y0
End If
End If
End If
End SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = "控件的缩放"
End Sub
在程序中用鼠标拖动改变文本框大小:I once had occasion to require a textbox that the user could size dynamically at runtime. By experimenting with the Windows APIs GetWindowLong, SetWindowLong, and SetWindowPos, I was able to create a textbox which, on command, had its fixed 3d border change into a sizeable border.
BAS Module Code
Place the following code into the general declarations area of a bas module: --------------------------------------------------------------------------------
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ?1996-2002 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' You are free to use this code within your own applications,
' but you are expressly forbidden from selling or otherwise
' distributing this source code without prior written consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''windows constants
Public Const SWP_DRAWFRAME As Long = &H20
Public Const SWP_NOMOVE As Long = &H2
Public Const SWP_NOSIZE As Long = &H1
Public Const SWP_NOZORDER As Long = &H4
Public Const SWP_FLAGS As Long = SWP_NOZORDER Or SWP_NOSIZE Or _
SWP_NOMOVE Or SWP_DRAWFRAME
Public Const GWL_STYLE As Long = (-16)
Public Const WS_THICKFRAME As Long = &H40000Public Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As LongPublic Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As LongPublic 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
'--end block--'
Form Code
To a form add a text box (Text1), a command button (Command1), 2 menu items (mnuSize & mnuRestore), and 2 labels (Label1 & Label2). Add the following code to the form: --------------------------------------------------------------------------------
Option Explicit 'variables initially set in Form_Load,
'used to reset default values
Dim initBoxStyle As Long
Dim initLeft As Integer
Dim initTop As Integer
Dim initWidth As Integer
Dim initHeight As IntegerPrivate Sub Form_Load() 'position the form
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
'set up a few variables needed later
initBoxStyle = GetWindowLong(Text1.hwnd, GWL_STYLE)
initLeft = Text1.Left
initTop = Text1.Top
initWidth = Text1.Width
initHeight = Text1.Height 'make sure the defaults are set
SetControlStyle initBoxStyle, Text1
Label1.Caption = "Text Width : " & Text1.Width
Label2.Caption = "Text Height : " & Text1.HeightEnd Sub
Private Sub Form_Unload(Cancel As Integer) 'restore the control to a normal textbox
SetControlStyle initBoxStyle, Text1End Sub
Private Sub Form_Click() 'restore the control to a normal textbox
SetControlStyle initBoxStyle, Text1
Label1.Caption = "Text Width : " & Text1.Width
Label2.Caption = "Text Height : " & Text1.Height
End Sub
Private Sub mnuSize_Click() Dim style As Long
'get the current style attributes for the textbox
style = GetWindowLong(Text1.hwnd, GWL_STYLE)
'modify the style to show the sizing frame
style = style Or WS_THICKFRAME
'set the control to the chosen style
SetControlStyle style, Text1End Sub
Private Sub mnuRestore_Click() 'restore the control to a normal textbox
SetControlStyle initBoxStyle, Text1
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub SetControlStyle(style, X As Control)
If style Then
Call SetWindowLong(X.hwnd, GWL_STYLE, style)
Call SetWindowPos(X.hwnd, Form1.hwnd, 0, 0, 0, 0, SWP_FLAGS)
End IfEnd Sub
'--end block--'
Comments
Save the app & run. Clicking the 'Size' menu item will cause the textbox border to change into a sizeable frame. After resizing, clicking the form or selecting 'Restore' will return the textbox to the normal textbox style at the selected size and position.This same technique can also be successfully applied to lists, listviews, treeviews, picture boxes ... pretty well most VB controls.