WinForm 无边框窗体和timer控件

时间:2022-05-29 23:46:47

一、无边框窗体

1、控制按钮如何制作
就是放置可以点击的控件,不局限于使用按钮或是什么别的,
只要可以点击能触发点击事件就可以了

做的好看一点,就是鼠标移入,移出,按下三个事件会让按钮改变样式

如何获取图片的相对路径
Application.StartupPath + "\\..\\..\\images\\btn_close_highlight.png"

\..\文件夹名称... 向上翻一个文件夹

2、如何让窗体动起来
调用窗体移动的API

如果有其它控件覆盖了窗体,那么写好鼠标按下的事件委托就可以了

    //窗体移动API
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
[DllImport("user32")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
private const int WM_SETREDRAW = 0xB; private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, );
}
}

3、如何让窗体有阴影

  

  //窗体二边阴影
  public partial class Form1 : Form//窗体的类
{
private const int CS_DropSHADOW = 0x20000;
private const int GCL_STYLE = (-); [DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex); public Form1()//窗体本身的构造函数
{
InitializeComponent();//构造函数自带语句 SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW); }
}

  窗体四边阴影:http://bbs.csdn.net/topics/390069539?page=1#post-395227949

二、timer控件 简单通讯
timer在组件里:
Enabled - 此控件是否启用
Interval - 间隔时间,毫秒
Tick事件 - 间隔指定时间后要执行的代码段

timer就是个线程,这个线程默认可以跨线程访问对象