IF声明确定Me.Cancel选项

时间:2017-08-07 09:21:57

标签: vb.net visual-studio

我正在尝试根据传递给表单的值来控制ESC操作。

Private Sub SetDefault(ByVal myDefaultBtn As Button)
    If Id = "1" Then Me.CancelButton = Button3
    If Id = "2" Then Me.CancelButton = Button1
    If Id = "" Then Me.CancelButton = Button3
End Sub

有可能做我正在尝试的事情吗?目前这似乎没有起作用......

下面我附上了我的代码的大部分内容。

Public Class Issue_Detail
Private DayName As String

Dim Val As String = ""
Dim User As String = ""
Dim Days As String = ""
Dim Id As String = ""
Public Sub New(val As String)
    InitializeComponent()
    Me.Val = val
End Sub

Public Sub New(val As String, user As String, Days As String, Id As String)
    Me.New(val)
    Me.User = user
    Me.Days = Days
    Me.Id = Id
End Sub
Public Property iassist As String
Public Property Day As String
Private Sub SetDefault(ByVal myDefaultBtn As Button)
    If Id = "1" Then Me.CancelButton = Button3
    If Id = "2" Then Me.CancelButton = Button1
    If Id = "" Then Me.CancelButton = Button3
End Sub
Private Sub Issue_Detail_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

1 个答案:

答案 0 :(得分:0)

将下面的代码放入我的MyBase.Load Sub中,它给了我需要的结果。

    If Id = "1" Then Me.CancelButton = Button2
    If Id = "2" Then Me.CancelButton = Button1
    If Id = "" Then Me.CancelButton = Button3