开发实践教程1:试卷生成系统6.3 主界面(FormMain)
Posted VB.Net
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发实践教程1:试卷生成系统6.3 主界面(FormMain)相关的知识,希望对你有一定的参考价值。
版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
主界面提供了试卷生成、试卷管理、考题管理等功能,另外试卷类型管理、考题类型管理、用户管理等功能只有管理员才有权限操作。
窗体设计如下:
图1-13
主界面是多文档界面容器,需要将窗体属性IsMdiContainer设置为True。关于多文档界面编程请参看教程第7.12节《多文档界面》。
主界面并不提供具体操作,只是一个显示其它窗口的容器,其工具栏上按钮打开对应功能的窗体。
为了更好控制用户界面,FormMain窗体中showWindow()方法仅允许同一时间显示一个子窗体。
具体代码如下:
Imports System.ComponentModel
Imports System.IO
Public Class FormMain
Private Sub showWindow(ByVal windowName As String)
If Me.MdiChildren.Length = 1 Then
If Me.MdiChildren(0).Name = windowName Then
If Me.MdiChildren(0).WindowState <> FormWindowState.Maximized Then
Me.MdiChildren(0).WindowState = FormWindowState.Maximized
Exit Sub
End If
Else
Me.MdiChildren(0).Close()
End If
End If
Dim formShow As Form
Select Case windowName
Case "FormTestPaper"
formShow = New FormTestPaper()
Case "FormTestPaperManager"
formShow = New FormTestPaperManager()
Case "FormExam"
formShow = New FormExam()
Case "FormUserList"
formShow = New FormUserList()
End Select
formShow.WindowState = FormWindowState.Maximized
formShow.MdiParent = Me
formShow.Show()
End Sub
Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If permissions = 0 Then
tsbSubjectType.Visible = True
tsbExamType.Visible = True
tsbUserList.Visible = True
Else
tsbSubjectType.Visible = False
tsbExamType.Visible = False
tsbUserList.Visible = False
End If
Call drawUI()
blTempPicPath = createTempPicPath()
If blTempPicPath = False Then
MessageBox.Show("创建图片临时目录失败,输出文档时,将不包含图片!")
End If
tsslInfo.Text = loginName & ",谢谢您使用 试卷生成系统!"
End Sub
Private Sub drawUI()
If permissions = 0 Then
tsbSubjectType.Visible = True
tsbExamType.Visible = True
tsbUserList.Visible = True
Else
tsbSubjectType.Visible = False
tsbExamType.Visible = False
tsbUserList.Visible = False
End If
End Sub
Private Function createTempPicPath() As Boolean
Dim sp As String
sp = Application.StartupPath
tempPicPath = IIf(sp.Substring(sp.Length - 1, 1) = "\\", sp, sp & "\\") & "temppic"
Try
If Directory.Exists(tempPicPath) = False Then
Directory.CreateDirectory(tempPicPath)
End If
Return True
Catch ex As Exception
Return False
End Try
End Function
Private Sub tsbExamType_Click(sender As Object, e As EventArgs) Handles tsbExamType.Click
FormPaperType.ShowDialog()
End Sub
Private Sub tsbExam_Click(sender As Object, e As EventArgs) Handles tsbExam.Click
Call showWindow("FormExam")
End Sub
Private Sub tsbUserList_Click(sender As Object, e As EventArgs) Handles tsbUserList.Click
Call showWindow("FormUserList")
End Sub
Private Sub tsmiPaperSet_Click(sender As Object, e As EventArgs) Handles tsmiPaperSet.Click
Call showWindow("FormTestPaper")
End Sub
Private Sub tsmiPaperManage_Click(sender As Object, e As EventArgs) Handles tsmiPaperManage.Click
Call showWindow("FormTestPaperManager")
End Sub
Private Sub tsbInfo_Click(sender As Object, e As EventArgs) Handles tsbInfo.Click
FormSelfInfo.ShowDialog()
End Sub
Private Sub tsbSubjectType_Click(sender As Object, e As EventArgs) Handles tsbSubjectType.Click
FormExamType.ShowDialog()
End Sub
Private Sub tsbPass_Click(sender As Object, e As EventArgs) Handles tsbPass.Click
FormPass.ShowDialog()
End Sub
Private Sub tsbAbout_Click(sender As Object, e As EventArgs) Handles tsbAbout.Click
FormAbout.ShowDialog()
End Sub
Private Sub tsbExit_Click(sender As Object, e As EventArgs) Handles tsbExit.Click
If MessageBox.Show("是否退出系统", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
Application.Exit()
End If
End Sub
Private Sub FormMain_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
Application.Exit()
End Sub
End Class
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供的参考。
学习更多vb.net知识,请参看 vb.net 教程 目录
以上是关于开发实践教程1:试卷生成系统6.3 主界面(FormMain)的主要内容,如果未能解决你的问题,请参考以下文章
开发实践教程1:试卷生成系统6.2 用户注册界面(FormRegist)
开发实践教程1:试卷生成系统6.12 试卷管理(FormTestPaperManager)