为什么当我登录应用程序 VB.NET 时我的事件处理程序被命中

问题描述 投票:0回答:1

我正在使用 VB.NET,当我单击登录页面时,我很难意识到为什么我的事件处理程序适用于我的应用程序中的另一个页面。

我有一个需要登录的应用程序,在下一页上,它显示一个个人资料屏幕。在该配置文件屏幕上有一个按钮,当我向该处理程序添加断点时,当我单击“登录”按钮时,它会点击它。

它不会干扰应用程序,但试图让我头疼。

这是登录按钮:

Private Sub LoginLogin_Click(sender As Object, e As EventArgs) Handles loginLogin.Click
    ' Create a new instance of the ProfileScreen
    Dim profileScreen As New ProfileScreen()

    ' Set the size of the ProfileScreen to the size of Form1
    profileScreen.Size = Me.Size

    ' Show the ProfileScreen
    profileScreen.Show()

    ' Hide the current form
    Me.Hide()
End Sub

我将按钮命名为“Dude”用于测试目的:

Partial Class ProfileScreen
Inherits System.Windows.Forms.Form

' Designer-generated variables
Private components As System.ComponentModel.IContainer
Private WithEvents Dude As Button
Private scrapedData As New List(Of Tuple(Of String, String)) ' Declare scrapedData here
Private WithEvents scrapeWebsiteButton As Button
Private WithEvents scrapeFileButton As Button
Friend WithEvents SplitContainer1 As SplitContainer

' Constructor
Public Sub New()
    InitializeComponent()

    ' Set the license context for EPPlus
    ExcelPackage.LicenseContext = LicenseContext.NonCommercial

    ' Initialize the Dude button
    Dude = New Button With {
    .Text = "Dude",
    .Size = New Size(150, 50),
    .Location = New Point(10, 10),
    .BackColor = ColorTranslator.FromHtml("#333333"), ' Set the button color to #001f0f
    .ForeColor = Color.White ' Set the text color to white
}

    ' Add Dude button to Panel1 (sidebar)
    Me.SplitContainer1.Panel1.Controls.Add(Dude)

    ' Assign the ScrapeInfoButton_Click method as the event handler for Dude button click event
    AddHandler Dude.Click, AddressOf ScrapeInfoButton_Click
End Sub

任何解释将不胜感激,因为它应该只在我按下按钮时点击,而不是在我登录应用程序时点击。

vb.net
1个回答
0
投票

解决方案是为“Dude”处理程序创建自己的方法。

© www.soinside.com 2019 - 2024. All rights reserved.