托盘显示信息

像迅雷那样,鼠标移到托盘那里的时候它会显示下载的信息,它是如何做到的?答非所问... 像迅雷那样,鼠标移到托盘那里的时候它会显示下载的信息,它是如何做到的?
答非所问
展开
 我来答
百度网友dcdbb9d
2008-04-22 · TA获得超过1179个赞
知道大有可为答主
回答量:977
采纳率:0%
帮助的人:977万
展开全部
mousemove事件触发的

示例
[Visual Basic, C#, C++] 下面的示例演示使用不同的鼠标事件在 Panel 上绘制鼠标路径。对于发生的每个 MouseMove 和 MouseDown 事件,都将一个线段添加到 GraphicsPath。要更新该图形,请为每个 MouseDown 和 MouseUp 事件上的 Panel 调用 Invalidate 方法。此外,当 MouseWheel 事件发生时,图形路径将向上滚动或向下滚动。其他鼠标事件(如 MouseHover)也在屏幕上标识。同时屏幕上还显示有关 SystemInformation 类中鼠标的其他信息。

[Visual Basic]
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Namespace MouseEvent
' Summary description for Form1.
Public NotInheritable Class Form1
Inherits System.Windows.Forms.Form

Friend WithEvents panel1 As System.Windows.Forms.Panel
Private label1 As System.Windows.Forms.Label
Private label2 As System.Windows.Forms.Label
Private label3 As System.Windows.Forms.Label
Private label4 As System.Windows.Forms.Label
Private label5 As System.Windows.Forms.Label
Private label6 As System.Windows.Forms.Label
Private label7 As System.Windows.Forms.Label
Private label8 As System.Windows.Forms.Label
Private label9 As System.Windows.Forms.Label
Friend WithEvents clearButton As System.Windows.Forms.Button
Private mousePath As System.Drawing.Drawing2D.GraphicsPath
Private groupBox1 As System.Windows.Forms.GroupBox

Private fontSize As Integer = 20

<System.STAThread()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1())
End Sub 'Main

Public Sub New()

mousePath = New System.Drawing.Drawing2D.GraphicsPath()

Me.panel1 = New System.Windows.Forms.Panel()
Me.label1 = New System.Windows.Forms.Label()
Me.clearButton = New System.Windows.Forms.Button()
Me.label2 = New System.Windows.Forms.Label()
Me.label3 = New System.Windows.Forms.Label()
Me.label4 = New System.Windows.Forms.Label()
Me.label5 = New System.Windows.Forms.Label()
Me.label6 = New System.Windows.Forms.Label()
Me.label7 = New System.Windows.Forms.Label()
Me.label8 = New System.Windows.Forms.Label()
Me.label9 = New System.Windows.Forms.Label()
Me.groupBox1 = New System.Windows.Forms.GroupBox()

' Mouse Events Label
Me.label1.Location = New System.Drawing.Point(24, 504)
Me.label1.Size = New System.Drawing.Size(392, 23)
' DoubleClickSize Label
Me.label2.AutoSize = True
Me.label2.Location = New System.Drawing.Point(24, 48)
Me.label2.Size = New System.Drawing.Size(35, 13)
' DoubleClickTime Label
Me.label3.AutoSize = True
Me.label3.Location = New System.Drawing.Point(24, 72)
Me.label3.Size = New System.Drawing.Size(35, 13)
' MousePresent Label
Me.label4.AutoSize = True
Me.label4.Location = New System.Drawing.Point(24, 96)
Me.label4.Size = New System.Drawing.Size(35, 13)
' MouseButtons Label
Me.label5.AutoSize = True
Me.label5.Location = New System.Drawing.Point(24, 120)
Me.label5.Size = New System.Drawing.Size(35, 13)
' MouseButtonsSwapped Label
Me.label6.AutoSize = True
Me.label6.Location = New System.Drawing.Point(320, 48)
Me.label6.Size = New System.Drawing.Size(35, 13)
' MouseWheelPresent Label
Me.label7.AutoSize = True
Me.label7.Location = New System.Drawing.Point(320, 72)
Me.label7.Size = New System.Drawing.Size(35, 13)
' MouseWheelScrollLines Label
Me.label8.AutoSize = True
Me.label8.Location = New System.Drawing.Point(320, 96)
Me.label8.Size = New System.Drawing.Size(35, 13)
' NativeMouseWheelSupport Label
Me.label9.AutoSize = True
Me.label9.Location = New System.Drawing.Point(320, 120)
Me.label9.Size = New System.Drawing.Size(35, 13)

' Mouse Panel
Me.panel1.Anchor = System.Windows.Forms.AnchorStyles.Top Or _
System.Windows.Forms.AnchorStyles.Left Or _
System.Windows.Forms.AnchorStyles.Right
Me.panel1.BackColor = System.Drawing.SystemColors.ControlDark
Me.panel1.Location = New System.Drawing.Point(16, 160)
Me.panel1.Size = New System.Drawing.Size(664, 320)

' Clear Button
Me.clearButton.Anchor = System.Windows.Forms.AnchorStyles.Top Or _
System.Windows.Forms.AnchorStyles.Right
Me.clearButton.Location = New System.Drawing.Point(592, 504)
Me.clearButton.TabIndex = 1
Me.clearButton.Text = "Clear"

' GroupBox
Me.groupBox1.Anchor = System.Windows.Forms.AnchorStyles.Top Or _
System.Windows.Forms.AnchorStyles.Left Or _
System.Windows.Forms.AnchorStyles.Right
Me.groupBox1.Location = New System.Drawing.Point(16, 24)
Me.groupBox1.Size = New System.Drawing.Size(664, 128)
Me.groupBox1.Text = "System.Windows.Forms.SystemInformation"

' Set up how the form should be displayed and add the controls to the form.
Me.ClientSize = New System.Drawing.Size(696, 534)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.label9, _
Me.label8, Me.label7, Me.label6, Me.label5, Me.label4, _
Me.label3, Me.label2, Me.clearButton, Me.panel1, Me.label1, Me.groupBox1})

Me.Text = "Mouse Event Example"

' Display information about the system mouse.
label2.Text = "SystemInformation.DoubleClickSize: " + SystemInformation.DoubleClickSize.ToString()
label3.Text = "SystemInformation.DoubleClickTime: " + SystemInformation.DoubleClickTime.ToString()
label4.Text = "SystemInformation.MousePresent: " + SystemInformation.MousePresent.ToString()
label5.Text = "SystemInformation.MouseButtons: " + SystemInformation.MouseButtons.ToString()
label6.Text = "SystemInformation.MouseButtonsSwapped: " + SystemInformation.MouseButtonsSwapped.ToString()
label7.Text = "SystemInformation.MouseWheelPresent: " + SystemInformation.MouseWheelPresent.ToString()
label8.Text = "SystemInformation.MouseWheelScrollLines: " + SystemInformation.MouseWheelScrollLines.ToString()
label9.Text = "SystemInformation.NativeMouseWheelSupport: " + SystemInformation.NativeMouseWheelSupport.ToString()
End Sub 'New

Private Sub panel1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseDown
' Update the mouse path with the mouse information
Dim mouseDownLocation As New Point(e.X, e.Y)

Dim eventString As String = Nothing
Select Case e.Button
Case MouseButtons.Left
eventString = "L"
Case MouseButtons.Right
eventString = "R"
Case MouseButtons.Middle
eventString = "M"
Case MouseButtons.XButton1
eventString = "X1"
Case MouseButtons.XButton2
eventString = "X2"
Case MouseButtons.None:
eventString = Nothing
End Select

If Not (eventString Is Nothing) Then
mousePath.AddString(eventString, FontFamily.GenericSerif, CInt(FontStyle.Bold), fontSize, mouseDownLocation, StringFormat.GenericDefault)
Else
mousePath.AddLine(mouseDownLocation, mouseDownLocation)
End If

panel1.Focus()
panel1.Invalidate()
End Sub

Private Sub panel1_MouseEnter(sender As Object, e As System.EventArgs) Handles panel1.MouseEnter
' Update the mouse event label to indicate the MouseEnter event occurred.
label1.Text = sender.GetType().ToString() + ": MouseEnter"
End Sub

Private Sub panel1_MouseHover(sender As Object, e As System.EventArgs) Handles panel1.MouseHover
' Update the mouse event label to indicate the MouseHover event occurred.
label1.Text = sender.GetType().ToString() + ": MouseHover"
End Sub

Private Sub panel1_MouseLeave(sender As Object, e As System.EventArgs) Handles panel1.MouseLeave
' Update the mouse event label to indicate the MouseLeave event occurred.
label1.Text = sender.GetType().ToString() + ": MouseLeave"
End Sub

Private Sub panel1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseMove
' Update the mouse path that is drawn onto the Panel.
Dim mouseX As Integer = e.X
Dim mouseY As Integer = e.Y

mousePath.AddLine(mouseX, mouseY, mouseX, mouseY)
End Sub
Private Sub panel1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseWheel
' Update the drawing based upon the mouse wheel scrolling.
Dim numberOfTextLinesToMove As Integer = e.Delta * SystemInformation.MouseWheelScrollLines / 120 ' WHEEL_DATA
Dim numberOfPixelsToMove As Integer = numberOfTextLinesToMove * fontSize

If numberOfPixelsToMove <> 0 Then
Dim translateMatrix As New System.Drawing.Drawing2D.Matrix()
translateMatrix.Translate(0, numberOfPixelsToMove)
mousePath.Transform(translateMatrix)
End If

panel1.Invalidate()
End Sub
Private Sub panel1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseUp
Dim mouseUpLocation = New System.Drawing.Point(e.X, e.Y)

' Show the number of clicks in the path graphic.
Dim numberOfClicks As Integer = e.Clicks
mousePath.AddString(" " + numberOfClicks.ToString(), _
FontFamily.GenericSerif, CInt(FontStyle.Bold), _
fontSize, mouseUpLocation, StringFormat.GenericDefault)

panel1.Invalidate()
End Sub

Private Sub panel1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles panel1.Paint
' Perform the painting of the Panel.
e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath)
End Sub

Private Sub clearButton_Click(sender As Object, e As System.EventArgs) Handles clearButton.Click
' Clear the Panel display.
mousePath.Dispose()
mousePath = New System.Drawing.Drawing2D.GraphicsPath()
panel1.Invalidate()
End Sub

End Class 'Form1
End Namespace

[C#]
using System;
using System.Drawing;
using System.Windows.Forms;

namespace MouseEvent
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Button clearButton;
private System.Drawing.Drawing2D.GraphicsPath mousePath;
private System.Windows.Forms.GroupBox groupBox1;

private int fontSize = 20;

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

public Form1()
{
mousePath = new System.Drawing.Drawing2D.GraphicsPath();

this.panel1 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.clearButton = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();

// Mouse Events Label
this.label1.Location = new System.Drawing.Point(24, 504);
this.label1.Size = new System.Drawing.Size(392, 23);
// DoubleClickSize Label
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(24, 48);
this.label2.Size = new System.Drawing.Size(35, 13);
// DoubleClickTime Label
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(24, 72);
this.label3.Size = new System.Drawing.Size(35, 13);
// MousePresent Label
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(24, 96);
this.label4.Size = new System.Drawing.Size(35, 13);
// MouseButtons Label
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(24, 120);
this.label5.Size = new System.Drawing.Size(35, 13);
// MouseButtonsSwapped Label
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(320, 48);
this.label6.Size = new System.Drawing.Size(35, 13);
// MouseWheelPresent Label
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(320, 72);
this.label7.Size = new System.Drawing.Size(35, 13);
// MouseWheelScrollLines Label
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(320, 96);
this.label8.Size = new System.Drawing.Size(35, 13);
// NativeMouseWheelSupport Label
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(320, 120);
this.label9.Size = new System.Drawing.Size(35, 13);

// Mouse Panel
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.panel1.BackColor = System.Drawing.SystemColors.ControlDark;
this.panel1.Location = new System.Drawing.Point(16, 160);
this.panel1.Size = new System.Drawing.Size(664, 320);
this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
this.panel1.MouseEnter += new System.EventHandler(this.panel1_MouseEnter);
this.panel1.MouseHover += new System.EventHandler(this.panel1_MouseHover);
this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
this.panel1.MouseLeave += new System.EventHandler(this.panel1_MouseLeave);
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
this.panel1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);
。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式