spirch | voici mon problème
dans le code plus bas, l'event enter est exécuté même si après le messsage box, il y a un e.cancel = true
si j'enlève le message box qui est avant le e.cancel pour le mettre après, l'event enter n'est pas executé
mon problème est que je dois poser une question via un message box et décider si je dois mettre e.cancel a true ou non
Code :
- Public Class Form1
- Inherits Form
- Public Sub New()
- InitializeComponent()
- End Sub
- Protected Overrides Sub Finalize()
- MyBase.Finalize()
- End Sub
- <System.Diagnostics.DebuggerNonUserCode()> _
- Protected Overrides Sub Dispose(ByVal disposing As Boolean)
- Try
- If disposing AndAlso components IsNot Nothing Then
- components.Dispose()
- End If
- Finally
- MyBase.Dispose(disposing)
- End Try
- End Sub
- Private components As System.ComponentModel.IContainer
- <System.Diagnostics.DebuggerStepThrough()> _
- Private Sub InitializeComponent()
- Me.Class12 = New WindowsApplication1.Class1
- Me.Class11 = New WindowsApplication1.Class1
- Me.SuspendLayout()
- Me.Class12.Location = New System.Drawing.Point(192, 67)
- Me.Class12.Name = "Class12"
- Me.Class12.Size = New System.Drawing.Size(143, 59)
- Me.Class12.TabIndex = 1
- Me.Class11.Location = New System.Drawing.Point(44, 43)
- Me.Class11.Name = "Class11"
- Me.Class11.Size = New System.Drawing.Size(142, 83)
- Me.Class11.TabIndex = 0
- Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
- Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
- Me.ClientSize = New System.Drawing.Size(484, 273)
- Me.Controls.Add(Me.Class12)
- Me.Controls.Add(Me.Class11)
- Me.Name = "Form1"
- Me.Text = "Form1"
- Me.ResumeLayout(False)
- End Sub
- Friend WithEvents Class11 As WindowsApplication1.Class1
- Friend WithEvents Class12 As WindowsApplication1.Class1
- End Class
- Public Class Class1
- Inherits UserControl
- Private Sub InitializeComponent()
- Me.Panel1 = New System.Windows.Forms.Panel
- Me.TextBox1 = New System.Windows.Forms.TextBox
- Me.Panel1.SuspendLayout()
- Me.SuspendLayout()
- Me.Panel1.Controls.Add(Me.TextBox1)
- Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
- Me.Panel1.Location = New System.Drawing.Point(0, 0)
- Me.Panel1.Name = "Panel1"
- Me.Panel1.Size = New System.Drawing.Size(150, 150)
- Me.Panel1.TabIndex = 2
- Me.TextBox1.Location = New System.Drawing.Point(9, 18)
- Me.TextBox1.Multiline = True
- Me.TextBox1.Name = "TextBox1"
- Me.TextBox1.Size = New System.Drawing.Size(116, 20)
- Me.TextBox1.TabIndex = 0
- Me.Controls.Add(Me.Panel1)
- Me.Name = "Class1"
- Me.Panel1.ResumeLayout(False)
- Me.Panel1.PerformLayout()
- Me.ResumeLayout(False)
- End Sub
- Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
- Friend WithEvents Panel1 As System.Windows.Forms.Panel
- Private Sub Panel1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Enter
- TextBox1.Dock = DockStyle.Fill
- End Sub
- Private Sub Panel1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Leave
- TextBox1.Dock = DockStyle.None
- End Sub
- Private Sub Panel1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Panel1.Validating
- If TextBox1.Text = "ok" Then
- 'ne fonctionne pas
- MsgBox("no" )
- TextBox1.Focus()
- e.Cancel = True
- 'fonctionne
- 'MsgBox("no" )
- End If
- End Sub
- Public Sub New()
- InitializeComponent()
- End Sub
- End Class
|
|