Вот вообщем сделал форму которая регионом выводит часики на рабочем столе, и все былобы прекрасно если бы таймер не останавливался!! я так думаю надо сделать так что бы программа работала в фоновом режиме вот терь вопрос как это сделать!!? Добавлено @ 14:43 вот основой текст формы!!! что надо сюда добавить!!?
Код |
Imports System.io Public Class FormOne Inherits System.Windows.Forms.Form Private IconTrey As System.Windows.Forms.NotifyIcon Private timer As System.Timers.Timer Private offset As Point Private fsize As Integer = 40 Private txt1 As String = " " Private txt As String Private ff As String Private popUpMenu As ContextMenu Private chkColor As MenuItem Private chkFont As MenuItem Private chkOnTop As MenuItem Private chkOptions As MenuItem Private fnt As New Font("times new roman", fsize, FontStyle.Bold) Private fd As New System.Windows.Forms.FontDialog Private cd As New ColorDialog
Public Sub New() MyBase.New() Me.Name = "FrmONE" Me.Text = "One" Me.FormBorderStyle = FormBorderStyle.None Me.ShowInTaskbar = False 'Me.TopMost = True Me.Height = 200 Me.Width = 500 txt = 1
End Sub Public Shared Sub main() Application.Run(New FormOne) End Sub
Private Sub formONE_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim gp As New System.Drawing.Drawing2D.GraphicsPath gp.StartFigure() If txtShow = True Then gp.AddString(txt1, New FontFamily(ff), fnt.Style, (fsize / 3), New Point(40, fsize + 6), StringFormat.GenericTypographic) End If gp.AddString(txt, New FontFamily(ff), fnt.Style, fsize, New Point(0, 0), StringFormat.GenericDefault)
' gp.AddPath(patch, True) Dim rec As New Rectangle(0, 0, MyBase.ClientSize.Width, MyBase.ClientSize.Height) Dim patch As New System.Drawing.Drawing2D.GraphicsPath patch.AddRectangle(rec) Dim pdg As New Drawing2D.PathGradientBrush(patch) Dim colors() As Color = {Color.FromArgb(MyBase.BackColor.A, MyBase.BackColor.R, MyBase.BackColor.G, MyBase.BackColor.B)} pdg.SurroundColors = colors pdg.CenterColor = Color.FromArgb(255, 0, 0, 0) pdg.SetSigmaBellShape(0.8F) e.Graphics.FillPath(pdg, patch)
gp.CloseFigure()
MyBase.Region = New Region(gp)
End Sub
Private Sub formONE_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load timer = New System.Timers.Timer AddHandler timer.Elapsed, AddressOf onTimedEvent timer.Interval = 100 timer.Enabled = True timer.AutoReset = True timer.Start()
Dim file As New FileInfo("max.lom") Dim sw As StreamReader = file.OpenText Dim q, w, r, t As Integer ff = sw.ReadLine sw.ReadLine() fsize = sw.ReadLine() t = sw.ReadLine q = sw.ReadLine w = sw.ReadLine r = sw.ReadLine MyBase.BackColor = Color.FromArgb(t, q, w, r) q = sw.ReadLine w = sw.ReadLine MyBase.SetDesktopLocation(q, w) timeShow = sw.ReadLine DateShow = sw.ReadLine sutTime = sw.ReadLine txtShow = sw.ReadLine cahFix = sw.ReadLine errors = sw.ReadLine sw.Close() IconTrey = New System.Windows.Forms.NotifyIcon AddHandler IconTrey.MouseMove, AddressOf icTre_move IconTrey.Icon = New Icon("1.ico") IconTrey.InitializeLifetimeService() IconTrey.Visible = True ConstructorPopup() SetStyle(ControlStyles.CacheText, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.DoubleBuffer, True)
End Sub Private Sub icTre_move(ByVal sender As Object, ByVal e As MouseEventArgs) Dim d As New DateTime d = Now IconTrey.Text = d.ToLongTimeString & " " & d.ToShortDateString
End Sub
Private Sub formONE_unLoad(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Dim file As New FileInfo("max.lom") Dim sw As StreamWriter = file.CreateText sw.WriteLine(fnt.FontFamily.Name) sw.WriteLine(fnt.Style) sw.WriteLine(fsize) sw.WriteLine(MyBase.BackColor.A) sw.WriteLine(MyBase.BackColor.R) sw.WriteLine(MyBase.BackColor.G) sw.WriteLine(MyBase.BackColor.B) sw.WriteLine(MyBase.DesktopLocation.X) sw.WriteLine(MyBase.DesktopLocation.Y) sw.WriteLine(timeShow) sw.WriteLine(DateShow) sw.WriteLine(sutTime) sw.WriteLine(txtShow) sw.WriteLine(cahFix) sw.WriteLine(errors) sw.Close() End Sub Public Sub ConstructorPopup() popUpMenu = New ContextMenu popUpMenu.MenuItems.Add("Цвет", New EventHandler(AddressOf popup)) popUpMenu.MenuItems.Add("Шрифт", New EventHandler(AddressOf popup)) popUpMenu.MenuItems.Add("-", New EventHandler(AddressOf popup)) popUpMenu.MenuItems.Add("Всегда с верху", New EventHandler(AddressOf popup)) popUpMenu.MenuItems.Add("-", New EventHandler(AddressOf popup)) popUpMenu.MenuItems.Add("Параметры", New EventHandler(AddressOf popup)) IconTrey.ContextMenu = popUpMenu chkColor = IconTrey.ContextMenu.MenuItems(0) chkFont = IconTrey.ContextMenu.MenuItems(1) chkOnTop = IconTrey.ContextMenu.MenuItems(3) chkOptions = IconTrey.ContextMenu.MenuItems(5) End Sub Private Sub popup(ByVal sender As Object, ByVal e As EventArgs)
If sender Is chkColor Then cd.FullOpen = False cd.Color = MyBase.BackColor If cd.ShowDialog <> DialogResult.Cancel Then MyBase.BackColor = cd.Color End If End If If sender Is chkFont Then fd.ShowEffects = True fd.MaxSize = 90 fd.MinSize = 10 fd.Font = fnt If fd.ShowDialog <> DialogResult.Cancel Then ff = fd.Font.FontFamily.Name fnt = fd.Font fsize = fd.Font.Size MyBase.Height = fsize * 35 MyBase.Width = fsize * 35 End If End If If sender Is chkOptions Then Dim formaOP As New Form1 formaOP.Show() End If If sender Is chkOnTop Then If chkOnTop.Checked = False Then MyClass.TopMost = True chkOnTop.Checked = True
ElseIf chkOnTop.Checked = True Then MyClass.TopMost = False chkOnTop.Checked = False End If End If End Sub Public Sub onTimedEvent(ByVal sourse As Object, ByVal e As System.Timers.ElapsedEventArgs)
Dim d As New DateTime d = Now txt = "" If timeShow = True Then txt = d.ToLongTimeString End If If DateShow = True Then txt = txt & " " & d.ToShortDateString End If
Select Case d.Hour Case 6 To 9 txt1 = "Доброе утро" Case 10 To 17 txt1 = "Добрый день" Case 18 To 23 txt1 = "Добрый вечер" Case 0 To 5 txt1 = "Доброй ночи" End Select Dim se As New FormOne MyClass.Invalidate() If sutTime.ToLongTimeString = d.ToLongTimeString And errors = True Then Dim ExitWindows As New ExitWindwos ExitWindows.ShutDown() Me.Close() End End If End Sub Private Sub formONE_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown offset = New Point(-e.X, -e.Y)
End Sub Private Sub formONE_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove If e.Button = MouseButtons.Left And cahFix = False Then Dim pos As Point = Control.MousePosition pos.Offset(offset.X, offset.Y) MyBase.Location = pos End If 'timer = New System.Timers.Timer 'AddHandler timer.Elapsed, AddressOf onTimedEvent timer.Interval = 100 timer.Enabled = True timer.AutoReset = True timer.Start() End Sub Private Sub frmOne_onDoubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick MyBase.Close() End Sub Private Sub InitializeComponent() ' 'FormOne ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Name = "FormOne"
End Sub Protected Overloads Overrides Sub dispose(ByVal disposing As Boolean) If disposing Then MyClass.IconTrey.Dispose() End If MyBase.Dispose(disposing) End Sub
Protected Overrides Sub Finalize() MyBase.Finalize() End Sub End Class[code=vb]
| |