Probleme pour annuler la saisie dans des controles NumericUpDown
Bonsoir à tous,
J'ai enfin terminé mon programme (j'en profite pour remercier tous le monde) mais il me reste ce dernier problème a régler.
Je pense que mon problème est lié au faite que je cherche a écrire le dernière valeur qui été valide avant une saisie invalide dans les NumericUpDown.
C'est à dire que lorsque je fait défiler les valeurs du NumericUpDown jusqu'a tomber sur une valeur invalide (que j'affiche avec un messagebox), et juste aprés avoir cliqué sur le bouton OK de celui-ci, j'ai le message d'erreur ci-dessous et Visual Studio s'arrette sur la ligne : frmEdit.ShowDialog()
Citation:
La référence d'objet n'est pas définie à une instance d'un objet.
J'aimerais arriver a faire fonctionner ce formulaire de cette façon : l'utilisateur doit être avertie immédiatement d'une saisie invalide (dans ValueChanged par exemple) et cette valeur (invalide) ne doit pas s'afficher dans le NumericUpDown.
Ça fait un moment que je cherche et je n'y arrive vraiment pas.
Si quelqu'un peut-m'aider a régler ce dernier problème ça serait vraiment bien.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| Private Sub ContextMenuStrip1_Click(sender As Object, e As EventArgs) Handles ContextMenuStrip1.Click
Dim CMS As ContextMenuStrip = CType(sender, Windows.Forms.ContextMenuStrip)
Dim Index As Integer = ListBoxCuts.SelectedIndex
If Index >= 0 Then
Dim frmEdit As New frmEditCutsPoints(ThisVideo.MediaData.Cuts, Index)
frmEdit.StartPosition = FormStartPosition.Manual
frmEdit.Location = New Point(CMS.Left, CMS.Top)
frmEdit.ShowDialog()
ThisVideo.MediaData.Cuts.RefreshCuts(Index)
Else
MessageBox.Show("Veuillez selectionner les points de coupes a éditer", "Aucun points de coupe selectionnés", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Public Class frmEditCutsPoints
Private _Index As Integer
Private _Cuts As clsVideo.clsCuts
Private _CurrentCut As clsVideo.clsCut
Private _LimiteBasse As Integer
Private _LimiteHaute As Integer
Private _IsLoaded As Boolean
Public Sub New(ByVal Cuts As clsVideo.clsCuts, ByVal Index As Integer)
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
'Me.Location = MousePosition
_Index = Index
_Cuts = Cuts
_CurrentCut = Cuts.Item(Index)
_LimiteBasse = 0
If _Index > 0 Then _LimiteBasse = _Cuts.Item(_Index - 1).Cut_Out + 100
_LimiteHaute = clsVideo.clsMediaData.NbFrames
If _Index < _Cuts.Items.Count - 1 Then _LimiteHaute = _Cuts.Item(_Index + 1).Cut_In - 100
LastValideCutIn = _CurrentCut.Cut_In
LastValideCutOut = _CurrentCut.Cut_Out
NumericUpDownIn.Minimum = _LimiteBasse
NumericUpDownIn.Maximum = _LimiteHaute
NumericUpDownOut.Minimum = _LimiteBasse
NumericUpDownOut.Maximum = _LimiteHaute
NumericUpDownIn.Value = _CurrentCut.Cut_In
NumericUpDownOut.Value = _CurrentCut.Cut_Out
_IsLoaded = True
End Sub
Dim LastValideCutIn As Integer
Private Sub NumericUpDownIn_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDownIn.ValueChanged
If _IsLoaded = False Then Exit Sub
If (NumericUpDownOut.Value - NumericUpDownIn.Value) < 100 Then
MessageBox.Show("Le segment doit être supérieur à 100 frames")
NumericUpDownIn.Value = LastValideCutIn
End If
End Sub
Dim LastValideCutOut As Integer
Private Sub NumericUpDownOut_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDownOut.ValueChanged
If _IsLoaded = False Then Exit Sub
If (NumericUpDownOut.Value - NumericUpDownIn.Value) < 100 Then
MessageBox.Show("Le segment doit être supérieur à 100 frames")
NumericUpDownOut.Value = LastValideCutOut
End If
End Sub
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
_CurrentCut.Cut_In = CInt(NumericUpDownIn.Value)
_CurrentCut.Cut_Out = CInt(NumericUpDownOut.Value)
Me.Close()
End Sub
End Class |