为简单起见,我已经开发了一个应用程序,在最后阶段,我考虑为该应用程序的第一次运行创建一个表单,用户(admin)将在其中设置一些控制变量。
为了实现此功能,我必须确保有一个表单可以控制用户是否是第一次“看到”该应用程序,称其为“幽灵”表单(该表单不会可见)。
此“ ghost”形式将检查变量FirstRun是否为true。如果为真,则将调用用于设置控制变量的表单,否则将启动应用程序的主要表单:
Public Class fGhostForm
Private Sub fGhostForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Close()
End Sub
Private Sub fGhostForm_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
If My.Settings.FirstRun Then
Dim FormToLaunch As fFirstRunApplicationSettings = New fFirstRunApplicationSettings()
FormToLaunch.ShowDialog()
Else
Dim FormToLaunch As fMainForm = New fMainForm()
FormToLaunch.ShowDialog()
End If
End Sub
End Class
这很好而且很花哨,因为我可以看到我的主要表单处于其主要状态,这意味着我目前是访客用户,目前几乎无法访问该应用程序的任何功能。 为了获得访问权限,我需要先登录数据库,然后单击“ IniciarSessão”选项,然后弹出一个新表格,用户必须在该表格中输入其凭据:
登录后,根据用户所具有的安全级别,新的工具项必须出现在主窗体的菜单项中。 现在是问题所在:
如果我将“ fMainForm”设置为项目的启动表单,则会发生这种情况。 但是,如果我将“ fGhostForm”设置为启动表单,则确实会看到弹出主表单,但是登录后,工具项完全不会显示。
为找出问题所在,我决定创建一个测试按钮,只是为了创建主窗体的新实例,并调用它的精确副本。 现在,当我执行登录步骤时,在按下测试按钮所调用的主窗体上,不会显示工具条。 但是,在第一个主窗体上,工具项确实按预期显示(我使用“ fMainForm”作为项目的启动窗体来完成此操作)
这是测试按钮代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim testForm As fMainForm = New fMainForm()
testForm.Show()
End Sub
我无法弄清楚造成这种现象的原因。有谁知道为什么会这样吗? 如果需要,我可以提供更多详细信息。
P.S。主要形式是MdiContainer,我还检查了菜单栏的AllowMerge属性,将其禁用,但是结果仍然相同。
编辑* 我只是意识到我没有发布主表单的加载事件或登录事件,对于由此造成的混乱,我深表歉意。 在这里:
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
currentOp = "Low Database"
Try
Dim taLogins As New RecipeMasterDBDataSetTableAdapters.LoginsTableAdapter
Dim tLogins As New RecipeMasterDBDataSet.LoginsDataTable
Dim PED As cPassEncrypterDecrypter
PED = New cPassEncrypterDecrypter()
If taLogins.FillByLoginAuthByUsernamePassword(tLogins, txtUsername.Text, PED.StringEncrypter(txtPassword.Text)) > 0 Then
Dim taSessions As New RecipeMasterDBDataSetTableAdapters.SessionsTableAdapter
Dim tSession As New RecipeMasterDBDataSet.SessionsDataTable
taSessions.InsertQuerySession(Date.Now.Date & " " & Date.Now.Hour & ":" & Date.Now.Minute & ":" & Date.Now.Second, CInt(tLogins.Rows(0).Item(0)))
fMainForm.CurrentUserSessionID = taSessions.SelectQueryCurrentSession(CInt(tLogins.Rows(0).Item(0)))
If tLogins.Rows(0).Item(4) Then
Dim taRecipes As New RecipeMasterDBDataSetTableAdapters.RecipesTableAdapter
Dim tRecipes As New RecipeMasterDBDataSet.RecipesDataTable
Dim taRatings As New RecipeMasterDBDataSetTableAdapters.RatingsTableAdapter
taRecipes.Fill(tRecipes)
taEvents.InsertQueryEvents("SELECT Statement - Login Interface", "Query: Generic query | Parameters - N/A" _
, Date.Now, "Form: " & Me.Name & "Site: btnLogin_Click", _
CInt(tLogins.Rows(0).Item(0)), 28)
For recipeIndex As Integer = 0 To tRecipes.Rows.Count - 1
If My.Settings.ChosenLanguageIndex = 0 Then
taRatings.InsertQueryBaseRatingsForUser(Nothing, "Ainda não comentada", 0, 0D, False, "1900-01-01", CInt(tLogins.Rows(0).Item(0)), CInt(tRecipes.Rows(recipeIndex).Item(0)))
taEvents.InsertQueryEvents("INSERT Transaction - Login Interface", _
"Procedure: InsertQueryBaseRatingsForUser | Parameters - " & _
"Comment: " & String.Empty & " Comment_Flag: " & " Ainda não comentada " & _
"Rate_Level: " & 0 & " Rate_Score_Index: " & 0D & "Rated_Flag: " & _
"False " & "Rate_Recent_Date: " & "1900-01-01 " & "Login ID: " & _
CInt(tLogins.Rows(0).Item(0)) & " Recipe ID: " & _
CInt(tRecipes.Rows(recipeIndex).Item(0)), Date.Now, "Form: " & Me.Name & _
" Site: btnLogin_Click", CInt(tLogins.Rows(0).Item(0)), 31)
ElseIf My.Settings.ChosenLanguageIndex = 1 Then
taRatings.InsertQueryBaseRatingsForUser(Nothing, "Not yet commented", 0, 0D, False, "1900-01-01", CInt(tLogins.Rows(0).Item(0)), CInt(tRecipes.Rows(recipeIndex).Item(0)))
taEvents.InsertQueryEvents("INSERT Transaction - Login Interface", _
"Procedure: InsertQueryBaseRatingsForUser | Parameters - " & _
"Comment: " & String.Empty & " Comment_Flag: " & " Not yet commented " & _
"Rate_Level: " & 0 & " Rate_Score_Index: " & 0D & "Rated_Flag: " & _
"False " & "Rate_Recent_Date: " & "1900-01-01 " & "Login ID: " & _
CInt(tLogins.Rows(0).Item(0)) & " Recipe ID: " & _
CInt(tRecipes.Rows(recipeIndex).Item(0)), Date.Now, "Form: " & Me.Name & _
" Site: btnLogin_Click", CInt(tLogins.Rows(0).Item(0)), 31)
ElseIf My.Settings.ChosenLanguageIndex = 2 Then
taRatings.InsertQueryBaseRatingsForUser(Nothing, "Pas encore de commentaires", 0, 0D, False, "1900-01-01", CInt(tLogins.Rows(0).Item(0)), CInt(tRecipes.Rows(recipeIndex).Item(0)))
taEvents.InsertQueryEvents("INSERT Transaction - Login Interface", _
"Procedure: InsertQueryBaseRatingsForUser | Parameters - " & _
"Comment: " & String.Empty & " Comment_Flag: " & " Pas encore engagé " & _
"Rate_Level: " & 0 & " Rate_Score_Index: " & 0D & "Rated_Flag: " & _
"False " & "Rate_Recent_Date: " & "1900-01-01 " & "Login ID: " & _
CInt(tLogins.Rows(0).Item(0)) & " Recipe ID: " & _
CInt(tRecipes.Rows(recipeIndex).Item(0)), Date.Now, "Form: " & Me.Name & _
" Site: btnLogin_Click", CInt(tLogins.Rows(0).Item(0)), 31)
ElseIf My.Settings.ChosenLanguageIndex = 3 Then
taRatings.InsertQueryBaseRatingsForUser(Nothing, "Aún no ha comentado", 0, 0D, False, "1900-01-01", CInt(tLogins.Rows(0).Item(0)), CInt(tRecipes.Rows(recipeIndex).Item(0)))
taEvents.InsertQueryEvents("INSERT Transaction - Login Interface", _
"Procedure: InsertQueryBaseRatingsForUser | Parameters - " & _
"Comment: " & String.Empty & " Comment_Flag: " & " Aún no ha comentado " & _
"Rate_Level: " & 0 & " Rate_Score_Index: " & 0D & "Rated_Flag: " & _
"False " & "Rate_Recent_Date: " & "1900-01-01 " & "Login ID: " & _
CInt(tLogins.Rows(0).Item(0)) & " Recipe ID: " & _
CInt(tRecipes.Rows(recipeIndex).Item(0)), Date.Now, "Form: " & Me.Name & _
" Site: btnLogin_Click", CInt(tLogins.Rows(0).Item(0)), 31)
ElseIf My.Settings.ChosenLanguageIndex = 4 Then
taRatings.InsertQueryBaseRatingsForUser(Nothing, "Non ancora commentato", 0, 0D, False, "1900-01-01", CInt(tLogins.Rows(0).Item(0)), CInt(tRecipes.Rows(recipeIndex).Item(0)))
taEvents.InsertQueryEvents("INSERT Transaction - Login Interface", _
"Procedure: InsertQueryBaseRatingsForUser | Parameters - " & _
"Comment: " & String.Empty & " Comment_Flag: " & " Non ancora commentato " & _
"Rate_Level: " & 0 & " Rate_Score_Index: " & 0D & "Rated_Flag: " & _
"False " & "Rate_Recent_Date: " & "1900-01-01 " & "Login ID: " & _
CInt(tLogins.Rows(0).Item(0)) & " Recipe ID: " & _
CInt(tRecipes.Rows(recipeIndex).Item(0)), Date.Now, "Form: " & Me.Name & _
" Site: btnLogin_Click", CInt(tLogins.Rows(0).Item(0)), 31)
ElseIf My.Settings.ChosenLanguageIndex = 5 Then
taRatings.InsertQueryBaseRatingsForUser(Nothing, "Noch nicht kommentiert", 0, 0D, False, "1900-01-01", CInt(tLogins.Rows(0).Item(0)), CInt(tRecipes.Rows(recipeIndex).Item(0)))
taEvents.InsertQueryEvents("INSERT Transaction - Login Interface", _
"Procedure: InsertQueryBaseRatingsForUser | Parameters - " & _
"Comment: " & String.Empty & " Comment_Flag: " & " Noch nicht kommentiert " & _
"Rate_Level: " & 0 & " Rate_Score_Index: " & 0D & "Rated_Flag: " & _
"False " & "Rate_Recent_Date: " & "1900-01-01 " & "Login ID: " & _
CInt(tLogins.Rows(0).Item(0)) & " Recipe ID: " & _
CInt(tRecipes.Rows(recipeIndex).Item(0)), Date.Now, "Form: " & Me.Name & _
" Site: btnLogin_Click", CInt(tLogins.Rows(0).Item(0)), 31)
End If
Next
taLogins.UpdateQueryFirstLoginFlag(False, txtUsername.Text)
taEvents.InsertQueryEvents("UPDATE Transaction - Login Interface", _
"Procedure: UpdateQueryFirstLoginFlag | Parameters - " & _
"IsFirstLogin: " & "False " & "Username: " & txtUsername.Text, Date.Now, _
"Form: " & Me.Name & " Site: btnLogin_Click", CInt(tLogins.Rows(0).Item(0)), 31)
End If
fMainForm.ChefesToolStripMenuItem.Enabled = True
fMainForm.ChefesToolStripMenuItem.Visible = True
fMainForm.ReceitasToolStripMenuItem.Enabled = True
fMainForm.ReceitasToolStripMenuItem.Visible = True
fMainForm.AvaliaçõesToolStripMenuItem.Enabled = True
fMainForm.AvaliaçõesToolStripMenuItem.Visible = True
'fMainForm.GestõesMassivasToolStripMenuItem.Enabled = False
'fMainForm.GestõesMassivasToolStripMenuItem.Visible = False
fMainForm.ToolStripSeparator5.Visible = True
fMainForm.AlterarDadosDaContaDeUtilizadorToolStripMenuItem.Enabled = True
fMainForm.AlterarDadosDaContaDeUtilizadorToolStripMenuItem.Visible = True
fMainForm.SuporteTécnicoToolStripMenuItem.Enabled = True
fMainForm.SuporteTécnicoToolStripMenuItem.Visible = True
'fMainForm.AdministraçãoToolStripMenuItem.Enabled = False
'fMainForm.AdministraçãoToolStripMenuItem.Visible = False
taLogins.UpdateQueryLastLoginTimeStamp(CDate(Date.Now), txtUsername.Text)
taEvents.InsertQueryEvents("UPDATE Transaction - Login Interface", _
"Procedure: UpdateQueryLastLoginTimeStamp | Parameters - " & _
"LAST_LOGIN_TIMESTAMP: " & CDate(Date.Now) & " Username: " & txtUsername.Text, Date.Now, _
"Form: " & Me.Name & " Site: btnLogin_Click", CInt(tLogins.Rows(0).Item(0)), 31)
If CInt(tLogins.Rows(0).Item(7)) >= 1 And CInt(tLogins.Rows(0).Item(7)) <= 3 Then
fMainForm.GestõesMassivasToolStripMenuItem.Enabled = True
fMainForm.GestõesMassivasToolStripMenuItem.Visible = True
fMainForm.AdministraçãoToolStripMenuItem.Enabled = True
fMainForm.AdministraçãoToolStripMenuItem.Visible = True
fMainForm.ToolStripSeparator2.Visible = True
fMainForm.GerirFotografiasToolStripMenuItem.Enabled = True
fMainForm.GerirFotografiasToolStripMenuItem.Visible = True
fMainForm.ToolStripSeparator6.Visible = True
fMainForm.FotografiasToolStripMenuItem.Enabled = True
fMainForm.FotografiasToolStripMenuItem.Visible = True
fMainForm.ToolStripSeparator9.Visible = True
fMainForm.GeradorDeModelosToolStripMenuItem.Enabled = True
fMainForm.GeradorDeModelosToolStripMenuItem.Visible = True
ElseIf CInt(tLogins.Rows(0).Item(7)) >= 4 And CInt(tLogins.Rows(0).Item(7)) <= 5 Then
fMainForm.GestõesMassivasToolStripMenuItem.Enabled = True
fMainForm.GestõesMassivasToolStripMenuItem.Visible = True
fMainForm.AdministraçãoToolStripMenuItem.Enabled = False
fMainForm.AdministraçãoToolStripMenuItem.Visible = False
fMainForm.ToolStripSeparator2.Visible = True
fMainForm.GerirFotografiasToolStripMenuItem.Enabled = True
fMainForm.GerirFotografiasToolStripMenuItem.Visible = True
fMainForm.ToolStripSeparator6.Visible = True
fMainForm.FotografiasToolStripMenuItem.Enabled = True
fMainForm.FotografiasToolStripMenuItem.Visible = True
fMainForm.ToolStripSeparator9.Visible = True
fMainForm.GeradorDeModelosToolStripMenuItem.Enabled = True
fMainForm.GeradorDeModelosToolStripMenuItem.Visible = True
ElseIf CInt(tLogins.Rows(0).Item(7)) = 6 Then
fMainForm.GestõesMassivasToolStripMenuItem.Enabled = False
fMainForm.GestõesMassivasToolStripMenuItem.Visible = False
fMainForm.AdministraçãoToolStripMenuItem.Enabled = False
fMainForm.AdministraçãoToolStripMenuItem.Visible = False
fMainForm.ToolStripSeparator2.Visible = True
fMainForm.GerirFotografiasToolStripMenuItem.Enabled = True
fMainForm.GerirFotografiasToolStripMenuItem.Visible = True
fMainForm.ToolStripSeparator6.Visible = False
fMainForm.FotografiasToolStripMenuItem.Enabled = False
fMainForm.FotografiasToolStripMenuItem.Visible = False
fMainForm.ToolStripSeparator9.Visible = False
fMainForm.GeradorDeModelosToolStripMenuItem.Enabled = False
fMainForm.GeradorDeModelosToolStripMenuItem.Visible = False
Else
fMainForm.GestõesMassivasToolStripMenuItem.Enabled = False
fMainForm.GestõesMassivasToolStripMenuItem.Visible = False
fMainForm.AdministraçãoToolStripMenuItem.Enabled = False
fMainForm.AdministraçãoToolStripMenuItem.Visible = False
fMainForm.ToolStripSeparator2.Visible = False
fMainForm.GerirFotografiasToolStripMenuItem.Enabled = False
fMainForm.GerirFotografiasToolStripMenuItem.Visible = False
fMainForm.ToolStripSeparator6.Visible = False
fMainForm.FotografiasToolStripMenuItem.Enabled = False
fMainForm.FotografiasToolStripMenuItem.Visible = False
fMainForm.ToolStripSeparator9.Visible = False
fMainForm.GeradorDeModelosToolStripMenuItem.Enabled = False
fMainForm.GeradorDeModelosToolStripMenuItem.Visible = False
End If
fMainForm.CurrentUser = CStr(tLogins.Rows(0).Item(1))
AuthSessionValid = True
Me.Close()
Else
numberOfLoginFailedAttempts += 1
If My.Settings.ChosenLanguageIndex = 0 Then
MessageBox.Show("As credenciais que introduziu estão incorrectas." & ControlChars.CrLf & "Por favor, tente novamente." _
, "Erro: Credenciais Inválidas", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf My.Settings.ChosenLanguageIndex = 1 Then
MessageBox.Show("The credentials you entered are incorrect." & ControlChars.CrLf & "Please, try again." _
, "Error: Invalid Credentials", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf My.Settings.ChosenLanguageIndex = 2 Then
MessageBox.Show("Les informations d'identification que vous avez inscrits sont incorrects." & ControlChars.CrLf & "Veuillez réessayer." _
, "Erreur: Lettres de Créance non Valides", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf My.Settings.ChosenLanguageIndex = 3 Then
MessageBox.Show("Las credenciales que ha introducido son incorrectos." & ControlChars.CrLf & "Por favor, inténtelo de nuevo." _
, "Error: Credenciales no Válidas", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf My.Settings.ChosenLanguageIndex = 4 Then
MessageBox.Show("Le credenziali immesse non sono corrette." & ControlChars.CrLf & "Si prega, riprovare." _
, "Errore: Credenziali non Valide", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf My.Settings.ChosenLanguageIndex = 5 Then
MessageBox.Show("Die Anmeldeinformationen eingegeben sind falsch." & ControlChars.CrLf & "Bitte versuche es erneut." _
, "Fehler: Ungültige Anmeldeinformationen ", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If numberOfLoginFailedAttempts > 5 Then
btnLogin.Enabled = False
If My.Settings.ChosenLanguageIndex = 0 Then
Throw New Exception("O início de sessão foi bloqueado durante 30 segundos, devido ao número abusivo de tentativas." & ControlChars.CrLf & "Por favor, aguarde...")
ElseIf My.Settings.ChosenLanguageIndex = 1 Then
Throw New Exception("Session start was blocked for 30 seconds due to abusive attempts." & ControlChars.CrLf & "Please wait...")
ElseIf My.Settings.ChosenLanguageIndex = 2 Then
Throw New Exception("Le démarrage de la session a été bloqué pendant 30 secondes en raison de tentatives abusives." & ControlChars.CrLf & "S'il vous plaît, attendez...")
ElseIf My.Settings.ChosenLanguageIndex = 3 Then
Throw New Exception("El inicio de sesión se bloqueó durante 30 segundos debido a intentos abusivos." & ControlChars.CrLf & "Por favor, espere...")
ElseIf My.Settings.ChosenLanguageIndex = 4 Then
Throw New Exception("Inizia di la sessione è stata bloccata per 30 secondi a causa di tentativi abusivi." & ControlChars.CrLf & "Attendere prego...")
ElseIf My.Settings.ChosenLanguageIndex = 5 Then
Throw New Exception("Der Sitzungsstart wurde wegen missbräuchlicher, Versuche für 30 Sekunden blockiert." & ControlChars.CrLf & "Warten Sie mal...")
End If
End If
End If
Catch ex As Exception
Dim taLogins As New RecipeMasterDBDataSetTableAdapters.LoginsTableAdapter
Dim tLogins As New RecipeMasterDBDataSet.LoginsDataTable
Dim taEvents As New RecipeMasterDBDataSetTableAdapters.AppEventsTableAdapter
Dim tEvents As New RecipeMasterDBDataSet.LoginsDataTable
taLogins.FillByLoginByUsername(tLogins, "Admin")
taEvents.InsertQueryEvents(currentOp & " Error - Multiple Failed Login Attempts", "Code Error: " & ex.HResult & " | Error Description: " & ex.Message & " | Source: " & _
ex.Source, Date.Now, "Site: " & ex.TargetSite.Name, CInt(tLogins.Rows(0).Item(0)), 10)
If My.Settings.ChosenLanguageIndex = 0 Then
MessageBox.Show("Ocorreu a seguinte excepção:" & ControlChars.CrLf & ex.Message & ControlChars.CrLf & ControlChars.CrLf & _
"Rastreamento de Pilha: " & ex.StackTrace, "Erro de Sistema: " & ex.HResult, MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf My.Settings.ChosenLanguageIndex = 1 Then
MessageBox.Show("The following exception occurred:" & ControlChars.CrLf & ex.Message & ControlChars.CrLf & ControlChars.CrLf & _
"Stack Trace: " & ex.StackTrace, "System Error: " & ex.HResult, MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf My.Settings.ChosenLanguageIndex = 2 Then
MessageBox.Show("L'exception suivante s'est produite:" & ControlChars.CrLf & ex.Message & ControlChars.CrLf & ControlChars.CrLf & _
"Trace de la Pile: " & ex.StackTrace, "Erreur de Système: " & ex.HResult, MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf My.Settings.ChosenLanguageIndex = 3 Then
MessageBox.Show("Se produjo la siguiente excepción:" & ControlChars.CrLf & ex.Message & ControlChars.CrLf & ControlChars.CrLf & _
"Rastro de la Pila: " & ex.StackTrace, "Error del Sistema: " & ex.HResult, MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf My.Settings.ChosenLanguageIndex = 4 Then
MessageBox.Show("Si è verificato il seguente eccezione:" & ControlChars.CrLf & ex.Message & ControlChars.CrLf & ControlChars.CrLf & _
"Analisi dello Stack: " & ex.StackTrace, "Errore di Sistema: " & ex.HResult, MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf My.Settings.ChosenLanguageIndex = 5 Then
MessageBox.Show("Die folgende Ausnahme ist aufgetreten:" & ControlChars.CrLf & ex.Message & ControlChars.CrLf & ControlChars.CrLf & _
"Stapelüberwachung: " & ex.StackTrace, "Systemfehler: " & ex.HResult, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
tmrFailedLoginAttemptsController.Start()
End Try
End Sub
以下是主窗体的加载事件:
Private Sub fMainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
LastVisitedForm = Me.Text
currentOp = "High System"
If Not Directory.Exists(My.Settings.BackupFilesFolderPath) Then
Throw New Exception("The backup files folder either was moved or is missing from this computer." & ControlChars.CrLf & _
"Check your application folders for any misspeled names.")
Application.Exit()
End If
If Not Directory.Exists(My.Settings.DBPath) Then
Throw New Exception("The database files folder either was moved or is missing from this computer." & ControlChars.CrLf & _
"Check your application folders for any misspeled names.")
Application.Exit()
End If
If My.Settings.BackupFilesFolderPath = String.Empty Then
My.Settings.BackupFilesFolderPath =
Application.StartupPath.Remove(Application.StartupPath.Length - 10) & "\Backup Files"
My.Settings.Save()
End If
If My.Settings.DBPath = String.Empty Then
My.Settings.DBPath = "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA" 'temp folder
My.Settings.Save()
End If
If My.Settings.DBFileName = String.Empty Then
My.Settings.DBFileName = "RecipeMasterDB.mdf"
My.Settings.Save()
End If
Me.Text = "Recipe Master"
JanelasToolStripMenuItem.Enabled = False
EmailAccountCheckSumArray = New List(Of String)
'System clock code...
'Synchronize time always on application startup
secondsController = CDate(My.Settings.AppCurTime).Second
minutesController = CDate(My.Settings.AppCurTime).Minute
hoursController = CDate(My.Settings.AppCurTime).Hour
daysController = CDate(My.Settings.AppCurTime).Day
monthsController = CDate(My.Settings.AppCurTime).Month
yearsController = CDate(My.Settings.AppCurTime).Year
SystemClockStartUp = True
tmrAppTimeController.Start()
LanguageInterpreter(My.Settings.ChosenLanguageIndex)
ChefesToolStripMenuItem.Enabled = False
ChefesToolStripMenuItem.Visible = False
ReceitasToolStripMenuItem.Enabled = False
ReceitasToolStripMenuItem.Visible = False
AvaliaçõesToolStripMenuItem.Enabled = False
AvaliaçõesToolStripMenuItem.Visible = False
GestõesMassivasToolStripMenuItem.Enabled = False
GestõesMassivasToolStripMenuItem.Visible = False
ToolStripSeparator5.Visible = False
AlterarDadosDaContaDeUtilizadorToolStripMenuItem.Enabled = False
AlterarDadosDaContaDeUtilizadorToolStripMenuItem.Visible = False
SuporteTécnicoToolStripMenuItem.Enabled = False
SuporteTécnicoToolStripMenuItem.Visible = False
AdministraçãoToolStripMenuItem.Enabled = False
AdministraçãoToolStripMenuItem.Visible = False
Catch ex As Exception
'exception handling code ...
End Try
End Sub
答案 0 :(得分:0)
感谢TnTinMn,答案在于只需在Ghost表单上实例化主要表单,同时将变量声明为公共共享变量。 然后所需要做的就是通过该变量调用menustripitems。
Ghost表单的加载事件代码:
Public Class fGhostForm
Public Shared MainForm As fMainForm
Private Sub fGhostForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Close()
End Sub
Private Sub fGhostForm_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
If My.Settings.FirstRun Then
Dim FormToLaunch As fFirstRunApplicationSettings = New fFirstRunApplicationSettings()
FormToLaunch.ShowDialog()
Else
MainForm = New fMainForm()
MainForm.ShowDialog()
End If
End Sub
End Class
用于调用和控制菜单项的代码:
fGhostForm.MainForm.ChefesToolStripMenuItem.Enabled = True
fGhostForm.MainForm.ChefesToolStripMenuItem.Visible = True
感谢大家的时间。