当前位置:编程学习 > VB >>

这个VB程序怎么写

2.编写一个效果如kt2.exe的程序,在窗体上创建一个命令按钮,标题为“移动”。一个计时器。一个标签,标题为“Visual Basic6.0”.程序运行后,单击命令按钮,每隔0.1秒标签向左移动50,当移出窗体时返回窗体的右端(保存于考生文件夹中,窗体用文件名kt2.frm保存,工程用文件名kt2.vbp保存)

 高手帮帮忙 谢啦~

答案:
Option Explicit


Private Sub Command1_Click()
Timer1.Enabled = True
End Sub


Private Sub Form_Load()
Form1.Caption = "基本操作2"
Label1.Caption = "Visual Basic 6.0"
Command1.Caption = "移动"
Timer1.Interval = 100
Timer1.Enabled = False
End Sub


Private Sub Timer1_Timer()
If Label1.Left <= 0 Then
    Label1.Left = Form1.Width
    Label1.Left = Label1.Left - 50
Else
   Label1.Left = Label1.Left - 50
End If
End Sub

这是我写的代码,相信对你有用
Dim sFind As String
'声明文件类型
Dim FileType, FiType As String
'初始化程序
Private Sub Form_Load()
'设置程序启动时的大小
Me.Height = 6000
Me.Width = 9000
End Sub
'设置编辑框的位置和大小
Private Sub Form_Resize()
On Error Resume Next '出错处理
RichTextBox1.Top=20
RichTextBox1.Left=20
RichTextBox1.Height = ScaleHeight-40
RichTextBox1.Width = ScaleWidth-40
End Sub
'新建文件
Private Sub mnuNew_Click()
RichTextBox1.Text = "" '清空文本框
FileName = "未命名"
Me.Caption = FileName
End Sub

'打开文件
Private Sub mnuOpen_Click()
CommonDialog1.Filter = "文本文档(*.txt) *.txt RTF文档(*.rtf) *.rtf 所有文件(*.*) *.*"
CommonDialog1.ShowOpen
RichTextBox1.Text = "" '清空文本框
FileName = CommonDialog1.FileName
RichTextBox1.LoadFile FileName
Me.Caption = "超级记事本:" & FileName
End Sub
'保存文件
Private Sub mnuSave_Click()
CommonDialog1.Filter = "文本文档(*.txt) *.txt RTF文档(*.rtf) *.rtf 所有文件(*.*) *.*"
CommonDialog1.ShowSave
FileType = CommonDialog1.FileTitle
FiType = LCase(Right(FileType, 3))
FileName = CommonDialog1.FileName
Select Case FiType
Case "txt"
RichTextBox1.SaveFile FileName, rtfText
Case "rtf"
RichTextBox1.SaveFile FileName, rtfRTF
Case "*.*"
RichTextBox1.SaveFile FileName
End Select
Me.Caption = "超级记事本:" & FileName
End Sub
'退出
Private Sub mnuExit_Click()
End
End Sub
'复制
Private Sub mnuCopy_Click()
Clipboard.Clear
Clipboard.SetText RichTextBox1.SelText
End Sub
'剪切
Private Sub mnuCut_Click()
Clipboard.Clear
Clipboard.SetText RichTextBox1.SelText
RichTextBox1.SelText = ""
End Sub
'全选
Private Sub mnuSelectAll_Click()
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
End Sub
'粘贴
Private Sub mnuPaste_Click()
RichTextBox1.SelText = Clipboard.GetText
End Sub
'查找
Private Sub mnuFind_Click()
sFind = InputBox("请输入要查找的字、词:", "查找内容", sFind)
RichTextBox1.Find sFind
End Sub
'继续查找
Private Sub mnuFindOn_Click()
RichTextBox1.SelStart = RichTextBox1.SelStart + RichTextBox1.SelLength + 1
RichTextBox1.Find sFind, , Len(RichTextBox1)
End Sub
'使用说明
Private Sub mnuReadme_Click()
On Error GoTo handler
RichTextBox1.LoadFile "Readme.txt", rtfText '请写好Readme.txt文件并存入程序所在文件夹中
Me.Caption = "超级记事本:" & "使用说明"
Exit Sub
handler:
MsgBox "使用说明文档可能已经被移除,请与作者联系。", vbOKOnly, " 错误信息"
End Sub
'关于
Private Sub mnuAbout_Click()
MsgBox "超级记事本 Ver1.0 版权所有(C) 2001 土人",vbOKOnly,"关于"
End Sub
'设置弹出式菜单(即在编辑框中单击鼠标右键时弹出的动态菜单)
Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
PopupMenu mnuEdit, vbPopupMenuLeftAlign
Else
Exit Sub
End If
End Sub

上一个:vb的for代码怎么写?
下一个:VB2008如何命名空间

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,