本来想早一点把代码贴出来,可是有些人好像认为没用^^^^^^^^^^^
我希望楼上的朋友能做个更好的分享一下……
我是说明了,主要是"QQ窗体停靠"的效果呀
form1代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace QQ
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.contextMenu1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "QQ-水中游版";
this.notifyIcon1.Visible = true;
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2});
this.contextMenu1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "关于";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "退出";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox1.Location = new System.Drawing.Point(175, 5);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(16, 16);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);
this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
this.pictureBox1.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave);
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// pictureBox2
//
this.pictureBox2.BackColor = System.Drawing.Color.Transparent;
this.pictureBox2.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox2.Location = new System.Drawing.Point(141, 5);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(16, 16);
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
this.pictureBox2.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);
this.pictureBox2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseUp);
this.pictureBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(196, 577);
this.ContextMenu = this.contextMenu1;
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Location = new System.Drawing.Point(600, 0);
this.Name = "Form1";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "QQ";
this.TopMost = true;
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);
this.MouseLeave += new System.EventHandler(this.Form1_MouseLeave);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form2());
}
int dx;
int dy;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
int shubiao;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button ==MouseButtons.Left)
{
dx=e.X ;dy=e.Y;
}
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button ==MouseButtons.Left&&this.Size .Height ==577)
{
this.Left =this.Left +(e.X -dx);
this.Top =this.Top +(e.Y -dy);
Application.DoEvents ();/*节省运行资源*/
}
}
private void Form1_MouseEnter(object sender, System.EventArgs e)
{
this.ClientSize = new System.Drawing.Size(196,577);
this.shubiao =1;
}
private void Form1_MouseLeave(object sender, System.EventArgs e)
{
this.shubiao =0;
if(this.Location .Y==0&&this.shubiao ==0 )
this.ClientSize = new System.Drawing.Size(196,2);
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{if(this.Top <0) this.Top =0;
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
MessageBox.Show(" 滨州职业学院-软件工程学院\n计算机信息科学系05级软件-水中游制作\n \t\txcligood@gmail.com","QQ界面程序");
}
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
if(this.WindowState== System.Windows.Forms.FormWindowState.Normal )
{this.WindowState = System.Windows.Forms.FormWindowState.Minimized;this.Opacity =0;}
else {this.WindowState = System.Windows.Forms.FormWindowState.Normal ;
this.Opacity =1;}
}
private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.notifyIcon1.Visible = false;
Application.Exit();
}
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
}
private void pictureBox2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
}
private void pictureBox2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = FormWindowState.Minimized;
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.Opacity =0;
}
private void pictureBox1_MouseLeave(object sender, System.EventArgs e)
{
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.notifyIcon1.Visible = false;
Application.Exit();
}
}
}
锻炼中学习……学习中成长……