加好友 发短信
等级:幼狐
帖子:79
积分:581
威望:0
精华:0
注册:2022/11/17 21:42:00
|
[求助]关于退出窗口时报错,请老师们指导 Post By:2024/2/26 10:44:00 [只看该作者]
每次通过导航栏增加页签后,增加的页签不关闭,点击安全退出就会报错。如果把页签关闭掉,再退出就不会报错,通过调试,安全退出代码在执行到关闭主窗口时报错,试了好多办法,没解决,请老师们给指导下。
此主题相关图片如下:1708913911792.jpg 此主题相关图片如下:1708913942561.jpg
安全退出的代码如下:
以下内容为程序代码:
1 Dim Result As DialogResult 2 Result = MessageBox.Show("确定要退出系统吗?", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) 3 If Result = DialogResult.OK Then 4 e.Form.Controls("Panel1").Enabled = False 5 Dim dr As DataRow 6 Dim hyzh As String = e.Form.Controls("账号").Text 7 hyzh = hyzh.Trim(" ", "登", "录", "账", "号", ":", "[", "]") 8 dr = DataTables("账户管理").Find("[用户账号] = '" & hyzh & "' ") 9 dr("用户状态") = False 10 Forms("主窗口").Close() 11 Syscmd.Project.Exit(True) 12 Else 13 e.Form.Controls("Panel1").Enabled = True 14 End If
导航栏的代码如下: 以下内容为程序代码:
1 ' 获取选项卡控件 2 Dim tab As WinForm.TabControl = e.Form.Controls("TabControl2") 3 ' 获取导航栏控件 4 Dim bar As WinForm.NavBar = e.sender 5 ' 检查是否已经存在相应的选项卡页签 6 Dim tabPageExists As Boolean = False 7 For i As Integer = 0 To tab.TabPages.Count - 1 8 If tab.TabPages(i).Name = bar.SelectedPage.ButtonText Then 9 ' 如果存在,设置选中的页签并标记存在 10 tab.SelectedIndex = i 11 tabPageExists = True 12 Exit For 13 End If 14 Next 15 If Not tabPageExists Then 16 ' 如果选项卡页签不存在,检查是否已经存在相应的窗体 17 If Forms.Contains(bar.SelectedPage.ButtonText) Then 18 ' 如果窗体已存在,直接切换到对应选项卡 19 ' tab.TabPages.Add(bar.SelectedPage.ButtonText, bar.SelectedPage.ButtonText) 20 tab.SelectedIndex = tab.TabPages.Count - 1 21 ' 停止窗体重绘,提高性能 22 e.Form.StopRedraw 23 tab.TabPages.Add(bar.SelectedPage.ButtonText, bar.SelectedPage.ButtonText) 24 Forms(bar.SelectedPage.ButtonText).Open( - 1000, - 1500) 25 Forms(bar.SelectedPage.ButtonText).BaseForm.TopLevel = False 26 Forms(bar.SelectedPage.ButtonText).BaseForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None 27 Forms(bar.SelectedPage.ButtonText).BaseForm.Dock = System.Windows.Forms.DockStyle.Fill 28 Forms(bar.SelectedPage.ButtonText).BaseForm.AutoScroll = True 29 tab.TabPages(bar.SelectedPage.ButtonText).Controls.Add(Forms(bar.SelectedPage.ButtonText).BaseForm) 30 tab.SelectedPage = tab.TabPages(bar.SelectedPage.ButtonText) 31 BaseMainForm.Activate() 32 e.Form.ResumeRedraw 33 Else 34 ' 如果窗体不存在,显示建设中的提示信息 35 MessageBox.Show("建设中……敬请期待!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning) 36 End If 37 End If 38
|
|