每个实例都只是演示处理和这个实例有关的功能逻辑,是不会通盘考虑整个项目所有其它功能的合理性的。
既然知道这个错误会导致事件异常就把AfterOpenProject事件根据代码放到try里处理,然后到catch中退出项目即可
想在注册窗口加入包含空值的判断代码,Dim tt As WinForm.TextBox = e.Form.Controls("TextBox2")
If tt.Value > "" And tt.Value.ToString.Contains(" ") = True Then
MessageBox.Show("注册码不能包含有空格,注册窗口将关闭退出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
tt.Value = Nothing
End If
SaveConfigValue("Register" & HardDiskID, e.Form.Controls("TextBox2").Value)
e.Form.Close()
加入后如果包含有空格值则可以正常判断,但如果没有值时则会出现错误提示

此主题相关图片如下:ad.gif

确定按钮没有必要加这个判断,因为AfterOpenProject事件有相关的判断的
如果想避免1楼的错误,try就行了呀
try
Dim n As Integer = GetConfigValue("Count",1)
Dim Code As String = GetConfigValue("Register" & ComputerId,"")
Dim Ok As Boolean
If Code > "" AndAlso DecryptText(Code,"abc","abc") = ComputerId Then '如果注册码正确
OK = True
Else
If n > 30 Then
Forms("注册").Open()
Code = GetConfigValue("Register" & ComputerId,"")
If Code > "" AndAlso DecryptText(Code,"abc","abc") = ComputerId Then '如果注册码正确
OK = True
End If
End If
If n > 60 AndAlso Ok = False Then
Messagebox.Show("您正在使用的产品已经超出试用次数!")
Syscmd.Project.Exit()
End If
End If
n = n + 1
SaveConfigValue("Count",n)
Catch ex As Exception
Messagebox.Show("注册异常!")
Syscmd.Project.Exit()
End Try
但如果不清除输入包含空格的注册码,那么每次启动系统时都会执行第二代代码的,也就是
Messagebox.Show("注册异常!")
Syscmd.Project.Exit()
这2句代码在出错的情况下,也就是注册码不对才会执行的,既然注册信息不对,退出是应该的呀。
谢谢,不过第二层代码还得加上打开注册窗口,让其修改错误的注册码,因为如果不删除或修改过来,就永远的执行第二层的代码,直接退出而无法进入系统,也无法输入正确的注册码,因为系统在加载时就直接载入之前录入的注册码,而载入的又是错误的注册码,所以就永远执行第二层代码。
窗口beforeclose事件
if DecryptText(e.Form.Controls("TextBox2").text.trim(),"abc","abc") <> ComputerId then
Messagebox.Show("注册吗不正确,请重新填写!")
e.cancel=true
end if