史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2014-02-05, 07:32 PM   #1
魔術王子
版區管理員
 
魔術王子 的頭像
榮譽勳章
UID - 115097
在線等級: 級別:42 | 在線時長:1985小時 | 升級還需:36小時級別:42 | 在線時長:1985小時 | 升級還需:36小時
註冊日期: 2004-01-13
住址: 魔術學園
文章: 2945
精華: 0
現金: 14765 金幣
資產: 2678395 金幣
預設 程式 - [使用版本VB2008]使用NotifyIcon(TrayIcon)偵測滑鼠有無移動

將程式置於(常駐)NotifyIcon(TrayIcon)偵側滑鼠狀態
若滑鼠3秒沒動,就會出現
https://imagizer.imageshack.us/v2/720x576q90/163/6xbc.jpg
置於(常駐)NotifyIcon(TrayIcon)的圖示
https://imagizer.imageshack.us/v2/720x529q90/543/epda.jpg
引用:
作者: 元件
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
Me.Label1 = New System.Windows.Forms.Label
Me.ContextMenuStrip1 = New System.Windows.Forms.ContextMenuStrip(Me.components)
Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
Me.ContextMenuStrip1.SuspendLayout()
Me.SuspendLayout()
'
'Timer1
'
Me.Timer1.Enabled = True
'
'NotifyIcon1
'
Me.NotifyIcon1.Text = "NotifyIcon1"
Me.NotifyIcon1.Visible = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("標楷體", 50.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
Me.Label1.Location = New System.Drawing.Point(12, 9)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(233, 67)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
'ContextMenuStrip1
'
Me.ContextMenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem1})
Me.ContextMenuStrip1.Name = "ContextMenuStrip1"
Me.ContextMenuStrip1.Size = New System.Drawing.Size(101, 26)
'
'ToolStripMenuItem1
'
Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"
Me.ToolStripMenuItem1.Size = New System.Drawing.Size(100, 22)
Me.ToolStripMenuItem1.Text = "離開"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(501, 189)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Form1"
Me.ContextMenuStrip1.ResumeLayout(False)
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents NotifyIcon1 As System.Windows.Forms.NotifyIcon
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ContextMenuStrip1 As System.Windows.Forms.ContextMenuStrip
Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
引用:
作者: 程式碼
Public Class Form1
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (ByRef lpPoint As POINTAPI) As Long
Private Structure POINTAPI
Dim x As Integer
Dim y As Integer
End Structure

Dim p As POINTAPI, p1 As POINTAPI
Dim dt As Double = My.Computer.Clock.TickCount

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
NotifyIcon1.Icon = Icon
NotifyIcon1.ContextMenuStrip = ContextMenuStrip1
GetCursorPos(p)
End Sub

Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
Close()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
p1 = p
NotifyIcon1.Text = Now().ToLongTimeString
GetCursorPos(p)
If p.x = p1.x And p.y = p1.y Then
If My.Computer.Clock.TickCount - dt > 3000 Then
If Not Me.Visible Then Me.Visible = True
Label1.Text = Now().ToLongDateString & vbCrLf & Now().ToLongTimeString
End If
Else
If Me.Visible Then Me.Visible = False
dt = My.Computer.Clock.TickCount
End If
End Sub

Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
NotifyIcon1.Visible = False
End Sub

Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Timer1.Enabled = False
Me.Visible = True
End Sub

Private Sub NotifyIcon1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
GetCursorPos(p)
ContextMenuStrip1.Show(p.x, p.y)
End Sub
End Class
此段是在檢查,滑鼠有無移動,若滑鼠沒有移動,程式就會開始計數
引用:
If p.x = p1.x And p.y = p1.y Then
If My.Computer.Clock.TickCount - dt > 3000 Then
If Not Me.Visible Then Me.Visible = True
Label1.Text = Now().ToLongDateString & vbCrLf & Now().ToLongTimeString
End If
Else
If Me.Visible Then Me.Visible = False
dt = My.Computer.Clock.TickCount
End If
若滑鼠超過3000沒移動就會顯示表單,若你覺得3秒不夠或太多,可自行更改
引用:
If My.Computer.Clock.TickCount - dt > 3000 Then
If Not Me.Visible Then Me.Visible = True
Label1.Text = Now().ToLongDateString & vbCrLf & Now().ToLongTimeString
End If
魔術王子 目前離線  
送花文章: 1523, 收花文章: 1553 篇, 收花: 3892 次
回覆時引用此帖
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用

相似的主題
主題 主題作者 討論區 回覆 最後發表
程式 - [使用版本VB2008]通訊錄存成Excel檔 魔術王子 程式語言討論區 0 2014-01-27 08:00 PM
程式 - [使用版本VB2008]使用PrintDocument設計通訊錄列印 魔術王子 程式語言討論區 0 2014-01-27 07:44 PM
程式 - [使用版本VB2008]使用DataGridView元件設計菜單 魔術王子 程式語言討論區 0 2014-01-24 10:20 PM
程式 - [使用版本VB2008]ListView元件及Panel元件 魔術王子 程式語言討論區 0 2014-01-23 08:25 PM
程式 - [使用版本VB2008]程式設定選單 魔術王子 程式語言討論區 0 2014-01-22 06:19 AM


所有時間均為台北時間。現在的時間是 09:28 AM


Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.


SEO by vBSEO 3.6.1