搜档网
当前位置:搜档网 › c#实现无标题窗口的移动,IrisSkin2.dll的使用方法

c#实现无标题窗口的移动,IrisSkin2.dll的使用方法

一·实现无标题窗口的移动
第一种方法:
1.定义成员变量:
private Point ptMouseCurrrnetPos, ptMouseNewPos,ptFormPos, ptFormNewPos;
private bool blnMouseDown = false;

2.添加鼠标事件:
在窗口的属性面板中的事件选项卡中为form窗口增加如下事件
鼠标左键按下的事件:
private void Form2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
blnMouseDown = true;
// Save window position and mouse position
ptMouseCurrrnetPos = Control.MousePosition;
ptFormPos = Location;
}

}
鼠标移动的事件:
private void Form2_MouseMove(object sender, MouseEventArgs e)
{
if (blnMouseDown)
{
//Get the current position of the mouse in the screen
ptMouseNewPos = Control.MousePosition;
//Set window position
ptFormNewPos.X = ptMouseNewPos.X - ptMouseCurrrnetPos.X + ptFormPos.X;
ptFormNewPos.Y = ptMouseNewPos.Y - ptMouseCurrrnetPos.Y + ptFormPos.Y;
//Save window position
Location = ptFormNewPos;
ptFormPos = ptFormNewPos;
//Save mouse position
ptMouseCurrrnetPos = ptMouseNewPos;

}
}
鼠标放开的事件:
private void Form2_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
//Return back signal
blnMouseDown = false;
}


第二种方法:
(添加System.Runtime.InteropServices;名字空间)
添加如下代码:
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd,int wMsg,int wParam,int lParam);

public const int WM_SYSCOMMAND=0x0112;
public const int SC_MOVE=0xF010;
public const int HTCAPTION=0x0002;

private void Form2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION, 0);
}






二·IrisSkin2.dll的使用方法
1.添加控件IrisSkin2.dll。
方法:
直接将IrisSkin2.dll文件托到工具箱的常规选项卡上,然后放开鼠标,这时会出现一个SkinEngine的控件,将该控件拖放到form窗体中,第一步完成。

2.把皮肤文件中以ssk为后缀名的文件放在bin文件夹的debug文件夹里。

3.添加代码。
双击form窗体的边框,添加如下代码,
private void Form1_Load(object sender, EventArgs e)
{
skinEngine1.SkinFile = Application.StartupPath + @"\皮肤文件名称.ssk";
}

相关主题