Comment ouvrire et fermer ma forme a des heur precis a tout les jour

Résolu
daval43 Messages postés 49 Date d'inscription jeudi 29 avril 2010 Statut Membre Dernière intervention 14 septembre 2012 - 14 déc. 2011 à 03:24
KcHeY Messages postés 261 Date d'inscription dimanche 23 mai 2004 Statut Membre Dernière intervention 22 septembre 2012 - 17 déc. 2011 à 01:45
bonjour je suis entrain de faire un programe pour but de me pratiquer avec les timer et lheur reelle mais je suis bloquer ...
ce que je veut faire :
-je veut ouvrire une form(form2) a une heur pricise et la refermer a une autre heur precise (ex ouvrir form2 a 8h et fermer form2 a 8h30

voici le code que jais utiliser:
'lerreur ici ces que ma fome nest jamais fermer javais esailler avec 2timer mais je suis sur quil y a une facon bien plus facil si quelle qu un pourais maider???
Public Class Form1
    Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = TimeString
        If CheckBox1.Checked = True Then
            If Hour(Now) NumericUpDown1.Value And Minute(Now) NumericUpDown2.Value And Second(Now) = NumericUpDown3.Value = True Then
                Form2.Show()
                If Hour(Now) NumericUpDown4.Value And Minute(Now) NumericUpDown5.Value And Second(Now) = NumericUpDown6.Value = True Then
                Form2.Close()
                End If
            End If


        End If

    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        NumericUpDown1.Value = Hour(Now)
        NumericUpDown2.Value = Minute(Now)
        NumericUpDown3.Value = 30
        NumericUpDown4.Value = Hour(Now)
        NumericUpDown5.Value = Minute(Now)
        NumericUpDown6.Value = 30
    End Sub
    Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Me.Show()
    End Sub
End Class

merci de votre aide

15 réponses

Mayzz Messages postés 2813 Date d'inscription mardi 15 avril 2003 Statut Membre Dernière intervention 2 juin 2020 28
14 déc. 2011 à 04:23
Salut,

Avec un tel code l'interval de ton timer dois être de 1000ms au maximum.

As-tu mis des points d'arrêts dans ton formulaire ?


Si le déboguage est l'art d'enlever les bogues, la programmation doit être l'art de les créer.
3
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
14 déc. 2011 à 07:30
Bonjour,

La maladresse est celle de l'utilisation de l'égalité, qui risque fort de ne jamais se produire pile poil.

____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
14 déc. 2011 à 07:37
En rappelant à Mayzz (que je salue) une vielle lapalissade :
5 minutes avant sa mort, il était encore vivant

Et même en mettant au plus bas possible l'intervalle du timer : il ne faut jamais qu'une valeur infiniment petite pour basculer de A - epsilon à A + epsilon
, ce qui fait que l'on a peu de chances de "tomber" pile poil sur la valeur A.
____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
0
daval43 Messages postés 49 Date d'inscription jeudi 29 avril 2010 Statut Membre Dernière intervention 14 septembre 2012
14 déc. 2011 à 08:08
bon jais trouver il le sufisais de metre un else
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = TimeString
        If CheckBox1.Checked = True Then
            If Hour(Now) NumericUpDown1.Value And Minute(Now) NumericUpDown2.Value And Second(Now) = NumericUpDown3.Value = True Then
                Form2.Show()
            else               
If Hour(Now) NumericUpDown4.Value And Minute(Now) NumericUpDown5.Value And Second(Now) = NumericUpDown6.Value = True Then
               Form2.Close()
mais maintenant a la fin une boite de recherche (openfile) ouvre ?? javais 2 openfile avant mais je les est suprimer (et leur code aussi)est-ce un bug????
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
daval43 Messages postés 49 Date d'inscription jeudi 29 avril 2010 Statut Membre Dernière intervention 14 septembre 2012
14 déc. 2011 à 09:44
Bon jais trouver (quand explorer.exe est deja ouvert et on le ouvre une 2e fois sa sort une fenetre (openfile dialog) setais juste mon timer qui tournais trop vite donc il relisais le code et ouvrais explorer plusieur fois
0
daval43 Messages postés 49 Date d'inscription jeudi 29 avril 2010 Statut Membre Dernière intervention 14 septembre 2012
14 déc. 2011 à 09:48
et ucfoutu ton jargon est un peut trop compliquer pour moi!
il ne faut jamais qu'une valeur infiniment petite pour basculer de A - epsilon à A + epsilon
, ce qui fait que l'on a peu de chances de "tomber" pile poil sur la valeur A

si tu a le temps bien sure peut tu metre une traduction pour que je puise aprendre un langage (plus adapter) merci!
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
14 déc. 2011 à 09:56
Il n'y a absolument rien à traduire. C'est écrit en français ! (Hé oui : le français existe, même si d'aucuns l'utilisent à ce point mal que leurs expressions auraient sans aucun doute, en ce qui les concerne, réellement besoin d'être traduites en français )
Je peux comprendre que tu ne "piges" pas la subtilité de la lapalissade.
Je ne comprends par contre pas que ceci :
La maladresse est celle de l'utilisation de l'égalité, qui risque fort de ne jamais se produire pile poil
te paraisse du "chinois".*
Je n'ai rien à y ajouter.
____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
14 déc. 2011 à 10:09
Et en plus, je vois que j'avais détaillé par :
Et même en mettant au plus bas possible l'intervalle du timer : il ne faut jamais qu'une valeur infiniment petite pour basculer de A - epsilon à A + epsilon
, ce qui fait que l'on a peu de chances de "tomber" pile poil sur la valeur A.

Et cela te parait du jargon !

____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
0
Mayzz Messages postés 2813 Date d'inscription mardi 15 avril 2003 Statut Membre Dernière intervention 2 juin 2020 28
14 déc. 2011 à 14:28
Je te salue également ucfoutu :)

C'est pourquoi j'ai marqué :

Avec un tel code l'interval de ton timer dois être de 1000ms au maximum.

Pour ce qui est de l'else, c'est marrant je n'avais pas vu que les deux instructions étaient imbriquées.

Si le déboguage est l'art d'enlever les bogues, la programmation doit être l'art de les créer.
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
14 déc. 2011 à 14:46
pour ce qui est de l'else, c'est marrant je n'avais pas vu que les deux instructions étaient imbriquées.

Alors qu'il est si simple d'utiliser un intervalle bien moins gourmand et de décider d'ouvrir ou fermer en fonction de ce que l'heure actuelle est ou non dans la fourchette horaire délimitée par les valeurs de ses "numericupdowns" !



____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
15 déc. 2011 à 00:38
Salut
à tester
form2 est la form à afficher ou cacher
les controls sont crées dynamiquement
Public Class Form1
Private groupboxin As New GroupBox
Private groupboxout As New GroupBox
Private WithEvents combohoursin As New ComboBox
Private WithEvents combominsin As New ComboBox
Private WithEvents combohoursout As New ComboBox
Private WithEvents combominsout As New ComboBox
Private WithEvents valid As New Button
Private WithEvents timing As New Timer
Private thetimein As New DateTime

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
timing.Stop()

InitControls()
End Sub
Private Sub InitControls()
Me.Controls.Add(groupboxin)
Me.Controls.Add(groupboxout)
Me.Controls.Add(valid)
groupboxin.Controls.Add(combohoursin)
groupboxin.Controls.Add(combominsin)
groupboxout.Controls.Add(combohoursout)
groupboxout.Controls.Add(combominsout)
With groupboxin
.Font = New Font("arial", 12, FontStyle.Bold, GraphicsUnit.Pixel)
.Text = "horaire d'entrée"
.BackColor = Color.Linen
End With
With groupboxout
.Font = New Font("arial", 12, FontStyle.Bold, GraphicsUnit.Pixel)
.Text = "horaire de sortie"
.BackColor = Color.Linen
End With


For Each ctrl In groupboxin.Controls
If TypeOf ctrl Is ComboBox Then
DirectCast(ctrl, ComboBox).Font = New Font("arial", 12, FontStyle.Bold, GraphicsUnit.Pixel)
DirectCast(ctrl, ComboBox).BackColor = Color.White
DirectCast(ctrl, ComboBox).DropDownStyle = ComboBoxStyle.DropDownList
DirectCast(ctrl, ComboBox).Width = 60
End If
Next

For Each ctrl In groupboxout.Controls
If TypeOf ctrl Is ComboBox Then
DirectCast(ctrl, ComboBox).Font = New Font("arial", 12, FontStyle.Bold, GraphicsUnit.Pixel)
DirectCast(ctrl, ComboBox).BackColor = Color.White
DirectCast(ctrl, ComboBox).DropDownStyle = ComboBoxStyle.DropDownList
DirectCast(ctrl, ComboBox).Width = 60
End If
Next
With valid
.Font = New Font("arial", 12, FontStyle.Bold, GraphicsUnit.Pixel)
.Text = "valider"
.Enabled = False
End With
Preparelescombos()
groupboxin.Width = combohoursin.Width + 12 + combominsin.Width
groupboxin.Height = combohoursin.Height * 6
groupboxout.Width = combohoursout.Width + 12 + combominsout.Width
groupboxout.Height = combohoursout.Height * 6
combohoursin.Location = New Point(2, 16)
combominsin.Location = New Point(combohoursin.Right + 2, 16)
combohoursout.Location = New Point(2, 16)
combominsout.Location = New Point(combohoursout.Right + 2, 16)
groupboxin.Location = New Point(6, 2)
groupboxout.Location = New Point(groupboxin.Right + 6, 2)
valid.Location = New Point((groupboxout.Right - groupboxin.Left - valid.Width) \ 2, groupboxin.Bottom + 6)
End Sub
Private Sub Preparelescombos()
Dim iter As Integer

For iter = 0 To 23
If iter < 10 Then
combohoursin.Items.Add(iter.ToString.PadLeft(2, "0"c))
Else
combohoursin.Items.Add(iter.ToString)
End If
Next
For iter = 0 To 59
If iter < 10 Then
combominsin.Items.Add(iter.ToString.PadLeft(2, "0"c))
Else
combominsin.Items.Add(iter.ToString)
End If
Next
For iter = 0 To 23
If iter < 10 Then
combohoursout.Items.Add(iter.ToString.PadLeft(2, "0"c))
Else
combohoursout.Items.Add(iter.ToString)
End If
Next
For iter = 0 To 59
If iter < 10 Then
combominsout.Items.Add(iter.ToString.PadLeft(2, "0"c))
Else
combominsout.Items.Add(iter.ToString)
End If
Next



End Sub


Private Sub combohoursin_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles combohoursin.SelectedValueChanged
If DirectCast(sender, ComboBox).Text String.Empty And combominsout.Text String.Empty _
And combohoursout.Text String.Empty And combominsout.Text String.Empty Then
valid.Enabled = True
Else
valid.Enabled = False

End If
End Sub

Private Sub combohoursout_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles combohoursout.SelectedValueChanged
If DirectCast(sender, ComboBox).Text String.Empty And combominsout.Text String.Empty _
And combohoursin.Text String.Empty And combominsin.Text String.Empty Then
valid.Enabled = True
Else
valid.Enabled = False

End If
End Sub

Private Sub combominsin_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles combominsin.SelectedValueChanged
If DirectCast(sender, ComboBox).Text String.Empty And combominsout.Text String.Empty _
And combohoursin.Text String.Empty And combohoursout.Text String.Empty Then
valid.Enabled = True
Else
valid.Enabled = False

End If
End Sub

Private Sub combominsout_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles combominsout.SelectedValueChanged
If DirectCast(sender, ComboBox).Text String.Empty And combominsin.Text String.Empty _
And combohoursin.Text String.Empty And combohoursout.Text String.Empty Then
valid.Enabled = True
Else
valid.Enabled = False

End If
End Sub

Private Sub valid_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles valid.MouseClick
Dim now As New DateTime
now = DateTime.Now
If now.Hour System.Convert.ToInt32(combominsin.SelectedItem) Then
MessageBox.Show("heure passée")
Else If now.Hour = System.Convert.ToInt32(combohoursin.SelectedItem) And now.Minute < System.Convert.ToInt32(combominsin.SelectedItem) Then
timing.Interval = (System.Convert.ToInt32(combohoursin.SelectedItem) - now.Hour) * 3600 * 250 + (System.Convert.ToInt32(combominsin.SelectedItem) - now.Minute) * 60 * 1000 \ 10
timing.Start()
ElseIf now.Hour > System.Convert.ToInt32(combohoursin.SelectedItem) Then
MessageBox.Show("heure passée")
End If







End Sub

Private Sub timing_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timing.Tick
thetimein = DateTime.Now
If Not Form2.Created Then
Try
DirectCast(sender, Timer).Interval = (System.Convert.ToInt32(combohoursin.SelectedItem) - thetimein.Hour) * 3600 * 250 + (System.Convert.ToInt32(combominsin.SelectedItem) - thetimein.Minute) * 60 * 1000 \ 10
If DirectCast(sender, Timer).Interval < 60000 Then
DirectCast(sender, Timer).Interval = 1000
End If
Catch ex As Exception
DirectCast(sender, Timer).Interval = 1000
End Try
End If


If (thetimein.Hour combohoursin.SelectedIndex) And (thetimein.Minute combominsin.SelectedIndex) And Form2.Created = False Then

Form2.Show()
Try
DirectCast(sender, Timer).Interval = (System.Convert.ToInt32(combohoursout.SelectedItem) - thetimein.Hour) * 3600 * 250 + (System.Convert.ToInt32(combominsout.SelectedItem) - thetimein.Minute) * 60 * 1000 \ 10
If DirectCast(sender, Timer).Interval < 60000 Then
DirectCast(sender, Timer).Interval = 1000
End If
Catch ex As Exception
DirectCast(sender, Timer).Interval = 1000
End Try
End If
If (thetimein.Hour combohoursout.SelectedIndex) And (thetimein.Minute combominsout.SelectedIndex) And Form2.Created = True Then
Try
DirectCast(sender, Timer).Interval = (System.Convert.ToInt32(combohoursout.SelectedItem) - thetimein.Hour) * 3600 * 250 + (System.Convert.ToInt32(combominsout.SelectedItem) - thetimein.Minute) * 60 * 1000 \ 10
If DirectCast(sender, Timer).Interval < 60000 Then
DirectCast(sender, Timer).Interval = 1000
End If
Catch ex As Exception
DirectCast(sender, Timer).Interval = 1000
End Try
Formpreface.Close()
DirectCast(sender, Timer).Stop()
End If

End Sub
End Class
0
KcHeY Messages postés 261 Date d'inscription dimanche 23 mai 2004 Statut Membre Dernière intervention 22 septembre 2012
17 déc. 2011 à 01:14
Je me permet de répondre même si je ne suis pas un grand programmeur.
Pourquoi ne pas afficher la date dans un label et si label = la date voulu afficher la forme ?
Et dans un autre label afficher l'heure.
Si labeldate le jour voulu et labelheure 30 minutes après, masquer la forme.
Non ?
0
KcHeY Messages postés 261 Date d'inscription dimanche 23 mai 2004 Statut Membre Dernière intervention 22 septembre 2012
17 déc. 2011 à 01:18
Je viens de relire le titre, si c'est tout les jours même pas besoin d'afficher la date.
T'affiche l'heure dans un label et si le label l'heure voulu, ben tu Form.Show, et si 30minutes après, Form.hide
0
KcHeY Messages postés 261 Date d'inscription dimanche 23 mai 2004 Statut Membre Dernière intervention 22 septembre 2012
17 déc. 2011 à 01:30
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 500
        Timer1.Start()

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = TimeOfDay
        If Label1.Text = ("01:29:00") Then
            Me.Hide()
        ElseIf Label1.Text = ("01:30:00") Then
            Me.Show()
        End If
    End Sub
End Class


un timer(timer1)
un label(label1)

Et ça fonctionne..
0
KcHeY Messages postés 261 Date d'inscription dimanche 23 mai 2004 Statut Membre Dernière intervention 22 septembre 2012
17 déc. 2011 à 01:45
Tiens c'est étrange, quand j'execute le code ci-dessus, et que j'observe la taille du programme dans le gestionnaire des tâches, la taille ne cesse d'augmenter.
Je ne devrai peut-être pas pauser la question ici, si c'est le cas n'hésitez pas à déplacer mes messages voir à les supprimer, mais pourquoi augmente t-il ?
0
Rejoignez-nous