Aqui posteo un programa hecho por mi, escrito en Visual basic.Net y trata de un temporizador, usando bucles anidados y condicionales, y para que se vea bien añadi un NotifyIcon... Y k es eso?
Pues esto:
Que tal se ve?
Bueno les adjunto el codigo del programa, esta escrito en Visual Basic.Net 2005.
________________________________________________________________________
Pasos a seguir:
1)Creas un formulario común y silvestre.
2)Añades 3 combobox
3)Añades 2 botones.
Los nombres están dentro del codigo.
4)Creas una clase con el nombre "Visibilidad".
Código del programa:
Public Class Form1
Private WithEvents notificador As New NotifyIcon()
Private contextual As New ContextMenu()
Public h, m, s As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To 23
horas.Items.Add(i)
Next
For i = 0 To 59
minutos.Items.Add(i)
segundos.Items.Add(i)
Next
Visibilidad.SiempreEncima(Me.Handle.ToInt32)
Try
Me.Icon = New Icon("app.ico")
Catch ex As Exception
End Try
Try
With contextual
.MenuItems.Add("Restaurar", New EventHandler(AddressOf restaurar))
.MenuItems(0).DefaultItem = True
.MenuItems.Add("-")
.MenuItems.Add("Acerca de...", New EventHandler(AddressOf acerca))
.MenuItems.Add("-")
.MenuItems.Add("Salir", New EventHandler(AddressOf salir))
End With
With notificador
.Icon = Me.Icon
.ContextMenu = Me.contextual
.Text = "AutoDetecter v1.0"
.Visible = False
End With
Catch ex As Exception
MsgBox("Error al generar addons.", MsgBoxStyle.Exclamation, "Error 0x000008")
End Try
End Sub
Private Sub regresion_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles regresion.Tick
If s > 0 Then
s = s - 1
real()
ElseIf s = 0 Then
If m > 0 Then
m = m - 1
s = 59
real()
ElseIf m = 0 Then
If h > 0 Then
h = h - 1
m = 59
s = 59
real()
ElseIf h = 0 Then
regresion.Enabled = False
Call alarma()
End If
End If
End If
End Sub
Private Sub real()
Me.Text = h & " : " & m & " : " & s
End Sub
Private Sub alarma()
MsgBox("El tiempo ha finalizado" & Chr(13) & "Mayteelson Guerra, todos los derechos reservados." & Chr(13) & "www.elblogdemayteelsonguerra.blogspot.com", MsgBoxStyle.Critical, "Tiempo de espera finalizado")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
regresion.Enabled = True
h = horas.SelectedItem
m = minutos.SelectedItem
s = segundos.SelectedItem
End Sub
Private Sub mostrador()
With notificador
.Visible = True
.BalloonTipIcon = ToolTipIcon.Warning
.BalloonTipText = "Tiempo restante " & h & " : " & m & " : " & s
.BalloonTipTitle = "Count-Down v1.0"
.ShowBalloonTip(5)
End With
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.Visible = False
mostrador()
End If
End Sub
Private Sub restaurar(ByVal sender As Object, ByVal e As EventArgs) Handles notificador.DoubleClick
Me.Show()
WindowState = FormWindowState.Normal
notificador.Visible = False
End Sub
Private Sub salir(ByVal sender As Object, ByVal e As EventArgs)
Me.Close()
End Sub
Private Sub acerca(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("Mayteelson Guerra, todos los derechos reservados" & Chr(13) & "Web: www.elblogdemayteelsonguerra.blogspot.com" & Chr(13) & "Mail: thecracker_007@hotmail.com", MsgBoxStyle.Information, "Count-Down v1.0")
End Sub
Private Sub shower_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles shower.Tick
If (h = 0 & m = 0 & s = 0) Then
Else
mostrador()
End If
End Sub
End Class
--------------------------------------------------------------------------------------------------------------------------------
Código de la clase:
Imports Microsoft.VisualBasic
Imports System
Imports System.Runtime.InteropServices
Public Class Visibilidad
' Constantes para SetWindowsPos
' Valores de wFlags
Const SWP_NOSIZE As Integer = &H1
Const SWP_NOMOVE As Integer = &H2
Const SWP_NOACTIVATE As Integer = &H10
Const wFlags As Integer = SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE
' Valores de hwndInsertAfter
Const HWND_TOPMOST As Integer = -1
Const HWND_NOTOPMOST As Integer = -2
'
'''
''' Para mantener la ventana siempre visible
'''
''' No utilizamos el valor devuelto
Private Shared Sub SetWindowPos( _
ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, _
ByVal X As Integer, ByVal Y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer)
End Sub
Public Shared Sub SiempreEncima(ByVal handle As Integer)
SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, wFlags)
End Sub
Public Shared Sub NoSiempreEncima(ByVal handle As Integer)
SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, wFlags)
End Sub
End Class
---------------------------------------------------------------------------------------------------------------------------
Bueno eso es todo, espero sus preguntas y comentarios ok.
Y Aqui les adjunto la solucion completa, para aquellos que no les gusta escribir.
Mayteelson Guerra
0 comentarios:
Publicar un comentario