Problème avec visual basic .net, usercontrol, validating/enter event

Problème avec visual basic .net, usercontrol, validating/enter event - VB/VBA/VBS - Programmation

Marsh Posté le 10-07-2008 à 02:54:10    

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 :
  1. Public Class Form1
  2.     Inherits Form
  3.     Public Sub New()
  4.         InitializeComponent()
  5.     End Sub
  6.     Protected Overrides Sub Finalize()
  7.         MyBase.Finalize()
  8.     End Sub
  9.     <System.Diagnostics.DebuggerNonUserCode()> _
  10.     Protected Overrides Sub Dispose(ByVal disposing As Boolean)
  11.         Try
  12.             If disposing AndAlso components IsNot Nothing Then
  13.                 components.Dispose()
  14.             End If
  15.         Finally
  16.             MyBase.Dispose(disposing)
  17.         End Try
  18.     End Sub
  19.     Private components As System.ComponentModel.IContainer
  20.     <System.Diagnostics.DebuggerStepThrough()> _
  21.     Private Sub InitializeComponent()
  22.         Me.Class12 = New WindowsApplication1.Class1
  23.         Me.Class11 = New WindowsApplication1.Class1
  24.         Me.SuspendLayout()
  25.         Me.Class12.Location = New System.Drawing.Point(192, 67)
  26.         Me.Class12.Name = "Class12"
  27.         Me.Class12.Size = New System.Drawing.Size(143, 59)
  28.         Me.Class12.TabIndex = 1
  29.         Me.Class11.Location = New System.Drawing.Point(44, 43)
  30.         Me.Class11.Name = "Class11"
  31.         Me.Class11.Size = New System.Drawing.Size(142, 83)
  32.         Me.Class11.TabIndex = 0
  33.         Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
  34.         Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
  35.         Me.ClientSize = New System.Drawing.Size(484, 273)
  36.         Me.Controls.Add(Me.Class12)
  37.         Me.Controls.Add(Me.Class11)
  38.         Me.Name = "Form1"
  39.         Me.Text = "Form1"
  40.         Me.ResumeLayout(False)
  41.     End Sub
  42.     Friend WithEvents Class11 As WindowsApplication1.Class1
  43.     Friend WithEvents Class12 As WindowsApplication1.Class1
  44. End Class
  45. Public Class Class1
  46.     Inherits UserControl
  47.     Private Sub InitializeComponent()
  48.         Me.Panel1 = New System.Windows.Forms.Panel
  49.         Me.TextBox1 = New System.Windows.Forms.TextBox
  50.         Me.Panel1.SuspendLayout()
  51.         Me.SuspendLayout()
  52.         Me.Panel1.Controls.Add(Me.TextBox1)
  53.         Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
  54.         Me.Panel1.Location = New System.Drawing.Point(0, 0)
  55.         Me.Panel1.Name = "Panel1"
  56.         Me.Panel1.Size = New System.Drawing.Size(150, 150)
  57.         Me.Panel1.TabIndex = 2
  58.         Me.TextBox1.Location = New System.Drawing.Point(9, 18)
  59.         Me.TextBox1.Multiline = True
  60.         Me.TextBox1.Name = "TextBox1"
  61.         Me.TextBox1.Size = New System.Drawing.Size(116, 20)
  62.         Me.TextBox1.TabIndex = 0
  63.         Me.Controls.Add(Me.Panel1)
  64.         Me.Name = "Class1"
  65.         Me.Panel1.ResumeLayout(False)
  66.         Me.Panel1.PerformLayout()
  67.         Me.ResumeLayout(False)
  68.     End Sub
  69.     Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  70.     Friend WithEvents Panel1 As System.Windows.Forms.Panel
  71.     Private Sub Panel1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Enter
  72.         TextBox1.Dock = DockStyle.Fill
  73.     End Sub
  74.     Private Sub Panel1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Leave
  75.         TextBox1.Dock = DockStyle.None
  76.     End Sub
  77.     Private Sub Panel1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Panel1.Validating
  78.         If TextBox1.Text = "ok" Then
  79.             'ne fonctionne  pas
  80.             MsgBox("no" )
  81.             TextBox1.Focus()
  82.             e.Cancel = True
  83.             'fonctionne
  84.             'MsgBox("no" )
  85.         End If
  86.     End Sub
  87.     Public Sub New()
  88.         InitializeComponent()
  89.     End Sub
  90. End Class

Reply

Marsh Posté le 10-07-2008 à 02:54:10   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed