您的位置:首页 > 编程语言 > VB

VB程序学习代码记录20160722

2016-07-22 14:32 423 查看
使用API函数enablewindow,禁止所有鼠标和键盘相关操作。

Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long

Private Sub Form_Load()
EnableWindow Command1.hwnd, 0
End Sub


加载窗体

Private Sub Command1_Click()
Load Form2
Form2.Show
Emd Sub


卸载窗体

Private Sub Command2_Click()
Unload Form2
End Sub
Private Sub Command3_Click()
Unload Me
End Sub


设置标题

Private Sub Command2_Click()
Me.caption="设置窗体名称"
End Sub


设置背景

Private Sub Form_Load()
Me.picture=LoadPicture(App.Path & "\VB 餐饮管理系统启动界面.jpg")
End Sub


边框样式

object.BorderStyle = [value]


显示样式

object.WindowState [=value]

Private Sub Form_Load()
Me.WindowState = vbMaximized
End Sub


显示位置

object.StartUpPosition = position


调用[非]模式窗体

Private Sub Command1_Click()
Form2.Show
End Sub

Private Sub Command2_Click()
Form3.Show 1
End Sub


隐藏窗体

Private Sub Command1_Click()
Form2.Hide
End Sub

Private Sub Command2_Click()
Form2.Show
Me.Hide
End Sub

[form2里:]
Private Sub Command1_Click()
Form1.Show
End Sub


移动窗体

object.Move left,top,width,height


click事件

Private Sub Fomr_Click()
Msgbox "您单击了窗体!",vbinformation,"信息提示"
End sub


dblclick事件

Private Sub Fomr_DblClick()
Msgbox "您双击了窗体!",vbinformation,"信息提示"
End sub


Load事件

Private Sub Form_Load()
Dim i as integer
For i= 0 to 5
Combo1.Additem "项目" & i
Next i
Combo1.Listindex=0
End Sub


QueryUnload事件

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim msg
If UnloadMode > 0 Then
msg = "是否退出应用程序?"
Else
msg = "是否关闭窗体?"
End If
If MsgBox(msg, vbQuestion + vbYesNo, "信息提示") = vbNo Then Cancel = True
End Sub


Unload事件

Private Sub Form_Unload(Cancel As Integer)
If MsgBox("是否关闭窗体", vbQuestion + vbYesNo, "信息提示") = vbNo Then
Cancel = True
End If
End Sub


Activate事件、Deactivate事件

Private Sub Form_Activate()
Me.Caption = "当前活动窗体“"
End Sub

Private Sub Form_Deactivate()
Me.Caption = "当前非活动窗体“"
End Sub


Initialize事件

Private Sub Form_Initialize()
Me.Caption = "Initialize事件"
End Sub


resize事件

Private Sub Form_Resize()
Text1.Top = (Me.Height - Text1.Height) / 2
Text1.Left = (Me.Width - Text1.Width) / 2
Text1.Width = Me.Width / 2
Text1.Height = Me.Height / 2
End Sub


paint事件

Private Sub Form_Paint()
Dim x, y
x = ScaleLeft + ScaleWidth / 2
y = ScaleTop + ScaleHeight / 2
Line (ScaleLeft, y)-(x, ScaleTop)
Line -(ScaleWidth + ScaleLeft, y)
Line -(x, ScaleHeight + ScaleTop)
Line -(scalefleft, y)
End Sub


gotfocus事件、lostfocus事件

Private Sub Form_GotFocus()
Form1.Print "form2获得焦点"
End Sub

Private Sub Form_LostFocus()
Form1.Print "form2失去焦点"
End Sub


窗体事件的生命周期

Private Sub form_activate()
Print Spc(3); "触发Activate事件"
End Sub
Private Sub Form_Click()
Form2.Show
End Sub
Private Sub Form_Deactivate()
Print Spc(3); "触发Deactive事件"
End Sub
Private Sub Form_GotFocus()
Print Spc(3); "触发Gotfocus事件"
End Sub
Private Sub Form_Initialize()
MsgBox "触发Initialize事件", vbInformation, "信息提示”"
End Sub
Private Sub Form_Load()
Print Spc(3); "触发Load事件"
End Sub
Private Sub Form_LostFocus()
Print Spc(3); "触发LostFocus事件"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
MsgBox "触发QueryUnload事件", vbInformation, "信息提示”"
End Sub
Private Sub Form_Terminate()
MsgBox "触发Terminate事件", vbInformation, "信息提示”"
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBox "触发Unload事件", vbInformation, "信息提示”"
End Sub


App对象

companyname属性
me.caption=me.caption & " (" & app.companyname & "创建)"

exename属性和path属性
filecopy app.path & "\" & app.exename & ".exe", app.path & "\" & app.exename & "备份.exe"

prevlnstance属性
private sub form_load()
if app.prevlnstance=false then
else
msgbox "程序已运行"
end
end if
end sub


Screen对象

activecontrol属性
Private Sub form_Click()
Screen.ActiveControl.Visible = False
End Sub

activeform属性
Private Sub Timer1_Timer()
Randomize
clt(Int(Rnd * 3) + 1).SetFocus
Screen.ActiveForm.Image1.Visible = True
End Sub

height、width属性
Private Sub Form_Load()
With Me
.Top = 0
.Left = 0
.Width = Screen.Width
.Height = Screen.Height
End With
End Sub


clipboard对象:操作剪贴板上的文本和图形

me.picture=clipboard.getdata
me.print clipboard.gettext
clipboard.setdata me.picture
clipboard.settext text1.text


debug对象

object.assert booleanexpression
object.print [outputlist]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: