刚才我编写记事本可以这样调整textbox的大小 Private Sub Form_Resize() Text1.Top = Me.ScaleTop Text1.Left = Me.ScaleLeft Text1.Width = Me.ScaleWidth Text1.Height = Me.ScaleHeight End Sub
在command1_mousedown()中写入Move
Sorry,让楼主笑话了。 看看你要的是不是这个。让command1随着鼠标的拖拽而移动 Public blFlag As BooleanPrivate Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) blFlag = True If (X - Command1.Left) > 0 And (Y - Command1.Top) > 0 Then Command1.Width = X - Command1.Left Command1.Height = X - Command1.Top End IfEnd SubPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If blFlag = True Then If (X - Command1.Left) > 0 And (Y - Command1.Top) > 0 Then Command1.Width = X - Command1.Left Command1.Height = X - Command1.Top End IfEnd If End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) blFlag = False End Sub
Option Explicit
Private M_FormHight As Integer '记录窗体高度
Private M_FormWide As Integer '记录窗体宽度
Private M_NumControls As Integer '记录窗体中控件总数Private Type M_FormPropertySize
M_FTop As Integer '存储窗体中所有控件的相对高度
M_FLeft As Integer '存储窗体中所有控件的相对左偏移
M_FWide As Integer '存储窗体中所有控件的控件宽
M_FHight As Integer '存储窗体中所有控件的高度
M_FRightMargin As Integer '存储窗体中所有控件的页边距
M_FFontSize As Integer '存储窗体中所有控件的字体大小
End Type
Private M_FControlSize() As M_FormPropertySize '定义一个控件类型Public Sub M_Init(M_Form As Form) '对窗体的性质进行初始化
Dim i As Integer '计数器
On Error GoTo ine
If M_Form.WindowState = 1 Then '如果窗体最小化,什么也不做
GoTo inerr
End If
'M_Form.WindowState = 2 '先最大化窗体
M_FormHight = M_Form.Height '得到窗体高度
M_FormWide = M_Form.Width '得到窗体宽度
M_NumControls = M_Form.Controls.Count '得到窗体上控件的总数ReDim M_FControlSize(M_NumControls + 1) '定义窗体中控件类型的个数
On Error Resume Next
For i = 1 To M_NumControls '为窗体属性结构数组赋值
If TypeOf M_Form.Controls(i - 1) Is Line Then
M_FControlSize(i).M_FTop = M_Form.Controls(i - 1).Y1
M_FControlSize(i).M_FLeft = M_Form.Controls(i - 1).X1
M_FControlSize(i).M_FWide = M_Form.Controls(i - 1).X2
M_FControlSize(i).M_FHight = M_Form.Controls(i - 1).Y2
'M_FControlSize(i).M_FFontSize = M_Form.Controls(i).FontSize
Else
M_FControlSize(i).M_FTop = M_Form.Controls(i - 1).Top
M_FControlSize(i).M_FLeft = M_Form.Controls(i - 1).Left
M_FControlSize(i).M_FWide = M_Form.Controls(i - 1).Width
M_FControlSize(i).M_FHight = M_Form.Controls(i - 1).Height
M_FControlSize(i).M_FFontSize = M_Form.Controls(i - 1).FontSize
'M_FControlSize(i).M_FRightMargin = M_Form.Controls(i - 1).RightMargin
End If
Next iGoTo inerr '无错跳出循环
ine:
MsgBox Err.Description, , "错误信息"
inerr:
End SubPublic Sub M_FormResize(M_Form As Form)
Dim i As Integer
Dim M_X As Single '横向缩放比例
Dim M_Y As Single '纵向缩放比例
On Error GoTo ine
If M_Form.WindowState = 1 Then '如果窗体最小化,什么也不做
GoTo inerr
End If
'M_FormHight = M_Form.Height '得到窗体高度
'M_FormWide = M_Form.Width '得到窗体高度
M_Form.AutoRedraw = True '允许窗体控件重画If M_Form.Height < M_FormHight / 2 Then
M_Form.Height = M_FormHight / 2 '自动缩放到原来的1/2
End If
If M_Form.Width < M_FormWide / 2 Then
M_Form.Width = M_FormWide / 2 '自动缩放到原来的1/2
End If'计算访缩比例
M_X = 1# * M_FormWide / M_Form.Width '得到宽比例
M_Y = 1# * M_FormHight / M_Form.Height '得到高比例
On Error Resume Next
For i = 1 To M_NumControls
If TypeOf M_Form.Controls(i - 1) Is Line Then
M_Form.Controls(i - 1).Top = Int(M_FControlSize(i).M_FTop / M_Y)
M_Form.Controls(i - 1).Left = Int(M_FControlSize(i).M_FLeft / M_X)
M_Form.Controls(i - 1).Width = Int(M_FControlSize(i).M_FWide / M_X)
M_Form.Controls(i - 1).hight = Int(M_FControlSize(i).M_FHight / M_Y)
Else
M_Form.Controls(i - 1).Top = Int(M_FControlSize(i).M_FTop / M_Y)
M_Form.Controls(i - 1).Left = Int(M_FControlSize(i).M_FLeft / M_X)
M_Form.Controls(i - 1).Width = Int(M_FControlSize(i).M_FWide / M_X)
M_Form.Controls(i - 1).Height = Int(M_FControlSize(i).M_FHight / M_Y)
M_Form.Controls(i - 1).FontSize = (Int(M_FControlSize(i).M_FFontSize / M_X) + Int(M_FControlSize(i).M_FFontSize / M_Y)) / 2
'M_Form.Controls(i - 1).RightMargin = Int(M_FControlSize(i).M_FRightMargin / M_Y)
End If
Next iGoTo inerr
ine:
MsgBox Err.Description, , "错误信息"
inerr:
End Sub
按钮获得焦点之后将PICTUREBOX移动到按钮四周。
PICTUREBOX的MOUSE_Down事件中,以PictureBox的位置画矩形,隐藏按钮和PictureBox数组,然后在背景容器的Mouse_Move中继续画矩形(检测左键状态),Mouse_Up事件中调整按钮大小和PictureBox位置,显示按钮和PictureBox数组,OK。
Private Sub Form_Resize()
Text1.Top = Me.ScaleTop
Text1.Left = Me.ScaleLeft
Text1.Width = Me.ScaleWidth
Text1.Height = Me.ScaleHeight
End Sub
看看你要的是不是这个。让command1随着鼠标的拖拽而移动
Public blFlag As BooleanPrivate Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
blFlag = True
If (X - Command1.Left) > 0 And (Y - Command1.Top) > 0 Then
Command1.Width = X - Command1.Left
Command1.Height = X - Command1.Top
End IfEnd SubPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blFlag = True Then
If (X - Command1.Left) > 0 And (Y - Command1.Top) > 0 Then
Command1.Width = X - Command1.Left
Command1.Height = X - Command1.Top
End IfEnd If
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blFlag = False
End Sub