关于 form 的问题!

JAMES001 2004-05-01 10:15:57
本人是vb初学者,现在有个问题:

编译后可执行的窗口,如何禁止用户改变窗口大小。(或者如何让控件跟着窗口大小而改变)

因为改变窗体后,里面的控件无法跟着改变。
现在有急用,忘哪位兄弟帮个忙!!
谢谢先!
...全文
12 9 点赞 打赏 收藏 举报
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
禁止改变大小的话在属性设置里面改变一下就可以,
Borderstyle=1; 'fixed single
同时:maxbutton=FALSE
  • 打赏
  • 举报
回复
shortppsy 2004-05-02
Borderstyle=1
maxbutton=0
  • 打赏
  • 举报
回复
CruelYoung123 2004-05-02
同时变动的话:
就是FORM的RESIZE事件
  • 打赏
  • 举报
回复
CruelYoung123 2004-05-02
禁止:

Borderstyle=1;
同时:maxbutton=FALSE

minbutton=true 这样的窗口形式很常见的一种形式,
你试一下就知道了
  • 打赏
  • 举报
回复
luoxiaoxiang 2004-05-02
固定大小直接在属性里设置就行了。
调整大小的话用代码编写控件的位置,值根据窗体的大小按比例设置。
  • 打赏
  • 举报
回复
BitBlt 2004-05-01
是啊,有些控件,如combo,高度是固定的,显示出来可能要乱套。
  • 打赏
  • 举报
回复
easydone 2004-05-01
方法(一)(不好)
类模块文件:
----------------------------------------------------------------------
Option Explicit
'****************************************************************
'*这是一个自动调整窗口内控间的大小的类模块:
'*1. 建立一个新的类模块,加入下列代码,并给类模块起名(例:autosize)
'*2. 加入一个窗口并且加入:Private el as new autosize
'*3. 在 Form_Load 事件中加入 el.init me
'*4. 在 Form_Resize 事件中加入 el.formresize me
'****************************************************************
Private nFormHeight As Integer
Private nFormWidth As Integer
Private nNumOfControls As Integer
Private nTop() As Integer
Private nLeft() As Integer
Private nHeight() As Integer
Private nWidth() As Integer
Private nFontSize() As Integer
Private nRightMargin() As Integer
Private bFirstTime As Boolean


Sub Init(frm As Form, Optional nWindState As Variant)
Dim I As Integer
Dim bWinMax As Boolean
bWinMax = Not IsMissing(nWindState)
nFormHeight = frm.Height
nFormWidth = frm.Width
nNumOfControls = frm.Controls.Count - 1
bFirstTime = True
ReDim nTop(nNumOfControls)
ReDim nLeft(nNumOfControls)
ReDim nHeight(nNumOfControls)
ReDim nWidth(nNumOfControls)
ReDim nFontSize(nNumOfControls)
ReDim nRightMargin(nNumOfControls)
On Error Resume Next
For I = 0 To nNumOfControls
If TypeOf frm.Controls(I) Is Line Then
nTop(I) = frm.Controls(I).Y1
nLeft(I) = frm.Controls(I).X1
nHeight(I) = frm.Controls(I).Y2
nWidth(I) = frm.Controls(I).X2
Else
nTop(I) = frm.Controls(I).Top
nLeft(I) = frm.Controls(I).Left
nHeight(I) = frm.Controls(I).Height
nWidth(I) = frm.Controls(I).Width
nFontSize(I) = frm.FontSize
nRightMargin(I) = frm.Controls(I).RightMargin
End If
Next
If bWinMax Or frm.WindowState = 2 Then
frm.Height = Screen.Height
frm.Width = Screen.Width
Else
frm.Height = frm.Height * Screen.Height / 7290
frm.Width = frm.Width * Screen.Width / 9690
End If
bFirstTime = True
End Sub

Sub FormResize(frm As Form)
Dim I As Integer
Dim nCaptionSize As Integer
Dim dRatioX As Double
Dim dRatioY As Double
Dim nSaveRedraw As Long
On Error Resume Next
nSaveRedraw = frm.AutoRedraw
frm.AutoRedraw = True
If bFirstTime Then
bFirstTime = False
Exit Sub
End If
If frm.Height < nFormHeight / 2 Then
frm.Height = nFormHeight / 2
End If
If frm.Width < nFormWidth / 2 Then
frm.Width = nFormWidth / 2
End If

nCaptionSize = 400
dRatioY = 1# * (nFormHeight - nCaptionSize) _
/ (frm.Height - nCaptionSize)
dRatioX = 1# * nFormWidth / frm.Width
On Error Resume Next
For I = 0 To nNumOfControls
If TypeOf frm.Controls(I) Is Line Then
frm.Controls(I).Y1 = Int(nTop(I) / dRatioY)
frm.Controls(I).X1 = Int(nLeft(I) / dRatioX)
frm.Controls(I).Y2 = Int(nHeight(I) / dRatioY)
frm.Controls(I).X2 = Int(nWidth(I) / dRatioX)
Else
frm.Controls(I).Top = Int(nTop(I) / dRatioY)
frm.Controls(I).Left = Int(nLeft(I) / dRatioX)
frm.Controls(I).Height = Int(nHeight(I) / dRatioY)
frm.Controls(I).Width = Int(nWidth(I) / dRatioX)
frm.Controls(I).FontSize = Int(nFontSize(I) / _
dRatioX) + Int(nFontSize(I) / dRatioX) Mod 2
frm.Controls(I).RightMargin = Int(nRightMargin(I) / dRatioY)
End If
Next
frm.AutoRedraw = nSaveRedraw
End Sub


----------------------------------------------------------------------

方法(二):(推荐)
Private FormOldWidth As Long '保存窗体的原始宽度
Private FormOldHeight As Long '保存窗体的原始高度


'在调用ResizeForm前先调用本函数(Form_Load中调用)
Public Sub ResizeInit(FormName As Form)

Dim Obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next


For Each Obj In FormName
Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " "
Next Obj

On Error GoTo 0

End Sub

'按比例改变表单内各元件的大小, 在调用ReSizeForm前先调用ReSizeInit函数

Public Sub ResizeForm(FormName As Form)
Dim Pos(4) As Double
Dim i As Long, TempPos As Long, StartPos As Long
Dim Obj As Control
Dim ScaleX As Double, ScaleY As Double


ScaleX = FormName.ScaleWidth / FormOldWidth '保存窗体宽度缩放比例
ScaleY = FormName.ScaleHeight / FormOldHeight '保存窗体高度缩放比例

On Error Resume Next

For Each Obj In FormName
StartPos = 1

For i = 0 To 4 '读取控件的原始位置与大小
TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare)
If TempPos > 0 Then
Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
Pos(i) = 0
End If

'根据控件的原始位置及窗体改变大小 的比例对控件重新定位与改变大小
Obj.Left = Pos(0) * ScaleX
Obj.Top = Pos(1) * ScaleY
Obj.Width = Pos(2) * ScaleX
Obj.Height = Pos(3) * ScaleY
Next i

Next Obj

On Error GoTo 0

End Sub

--------------------------------
可以试试上面2种方法,但并不是都有效的!
  • 打赏
  • 举报
回复
easydone 2004-05-01
禁止:在form resize时间中控制:
me.Width=me.Width
me.Height=me.Height



  • 打赏
  • 举报
回复
yinweihong 2004-05-01
禁止:me.BorderStyle=3
  • 打赏
  • 举报
回复
相关推荐
发帖
VB基础类
加入

7547

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2004-05-01 10:15
社区公告
暂无公告