窗体无边框设置后无法移动,引用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; //将方法复制到代码中,在将窗体的MouseDown(按下事件)委托此方法
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, );
}
}

窗体移动API

阴影

、添加命名空间:
using System.Runtime.InteropServices; 、定义常量值及函数:
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); 、构造方法下引用:
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);

窗体阴影API

案例

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
//窗体移动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; //窗体阴影API
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);
} private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, );
}
} }
}

案例、建立一个无边框窗体

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication2
{
public partial class Form4 : Form
{
//窗体移动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; public Form4()
{
InitializeComponent();
} private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, );
}
} //鼠标进入时发生
private void pictureBox2_MouseEnter(object sender, EventArgs e)
{
pictureBox2.BackgroundImage = Image.FromFile(@"e:/c2.png"); //改变背景图
} // @ --字符串的原样输出,加不加都像
//e:/c2.png --图片的地址 //鼠标离开时时发生 -- 刚开始默认图片是c1.png
private void pictureBox2_MouseLeave(object sender, EventArgs e)
{
pictureBox2.BackgroundImage = Image.FromFile(@"e:/c1.png");
} //鼠标按下时发生
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
pictureBox2.BackgroundImage = Image.FromFile(@"e:/c3.png");
} //点击时发生
private void pictureBox2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized; //最大化 // this.Close(); 关闭
} }
}

背景图片的设置

pictureBox1.BackgroundImage = Image.FromFile(" 图片路径地址 " );

winform窗体 小程序【移动窗体和阴影】的更多相关文章

  1. C#WinForm窗体内Panel容器中嵌入子窗体、程序主窗体设计例子

    C#WinForm父级窗体内Panel容器中嵌入子窗体.程序主窗体设计例子 在项目开发中经常遇到父级窗体嵌入子窗体所以写了一个例子程序,顺便大概划分了下界面模块和配色,不足之处还望指点 主窗体窗体采用 ...

  2. winform窗体 小程序【线程】

    线程是进程中执行运算的最小单位,也是执行处理机调度的基本单位.实际上线程是轻量级的进程.那么为什么要使用线程呢? (1)易于调度. (2)提高并发性.通过线程可方便有效地实现并发性.进程可创建多个线程 ...

  3. winform窗体 小程序【登录窗体】【恶搞程序】

    登录窗体 using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; ...

  4. winform窗体 小程序【打开多个窗体、窗体之间传值、打开唯一窗体】

    1.打开多个窗体 2.窗体之间的传值 3打开唯一窗体

  5. winform窗体 小程序【进程】

    进程 一个应用程序就是一个进程,我的理解是,只要是打开应用程序,就会创建进程. 在.NET框架在using.System.Diagnostics名称空间中,有一个类Process,用来创建一个新的进程 ...

  6. winform窗体 小程序【三级联动】

    三级联动[省,市,区] 类似地区选择,当选的某个省份,后面的下拉框相对变成对应省份的区县 实现省市区联动关键是数据库的表,[每个省内区的AreaCode列是同样的] public Form2() { ...

  7. 微信小程序开发-窗体设置

    "window": { "backgroundTextStyle": "light", "navigationBarBackgro ...

  8. JAVA第一个窗体小程序

    import java.awt.*;public class Day1015_Frame{    public static void main(String[] args)    {         ...

  9. Winform截图小程序

    今天闲时做的一个Demo,做得并不好,只是实现了最基本的截图功能 主要的思路就是 先打开一个主窗体,点击"截图按钮" 会出现一个半透明的小窗体(可以拉伸放大缩小) 然后利用Grap ...

随机推荐

  1. Rabbit MQ 入门指南

    rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.他遵循Mozilla Public License开源协议.采用 Erlang 实现的工业级的消息队列(MQ)服务器. Ra ...

  2. 开发 C# OPC 客户端

    编写 opc 客户端的思路 1. 使用OPC Client浏览服务器, 查看测试代码修改后的结果. 2. 根据OPC Client搜集到的服务器信息编写代码和服务器交互 3. OPC Client 操 ...

  3. mac终端常用命令

    1.du #查看文件目录大小 示例:查看DataCenter目录下所有文件/文件夹的大小 everSeeker:DataCenter pingping$ -h .9G ./Books 1.2M ./C ...

  4. Spring Boot log4j多环境日志级别的控制

    之前介绍了在<Spring boot中使用log4j>,仅通过log4j.properties对日志级别进行控制,对于需要多环境部署的环境不是很方便,可能我们在开发环境大部分模块需要采用D ...

  5. .gitignore总结

    git进行管理时,.gitignore是必不可少的,可以指定不需要提交到仓库的资源.最好在git init之后就创建 .gitignore文件,这是个好习惯,常用的配置及说明如下:

  6. 一步步Cobol 400 上手自学入门教程02 - 程序结构

    标识部的格式: 标识部(IDENTIFICATION DIVISION) 用来标识程序名称,记录程序的文档记录住处如作者和日期等. 代码范例: IDENTIFICATION DIVISION.PROG ...

  7. cookie和session的区别,分布式环境怎么保存用户状态

    cookie和session的区别,分布式环境怎么保存用户状态 1.cookie数据存放在客户的浏览器上,session数据放在服务器上. 2.cookie不是很安全,别人可以分析存放在本地的COOK ...

  8. odoo开发笔记 -- 安装Backend debranding去除odoo信息模块后 隐藏开发者模式

    Backend debranding 找到如下文件,将相关灰色代码注释掉. <?xml version="1.0" encoding="UTF-8"?&g ...

  9. JMP地址公式推导

    以上有个问题:为什么同样的汇编指令JMP 12345678却对应不同的机器码呢? 首先,机器码E9表明这是一个近跳转(Near Jmp) 这里需要补充下相关知识: JMP分3种: ①短跳转(Short ...

  10. UTF-8和GBK编码的区别

    UTF-8:对英文使用8位(一个字节).中文使用24位(三个字节)编码.对于英文字符比较多的网站一般用utf-8来编码以节省空间:包含全世界所有国家需要用到的字符,其编码的蚊子可以在各国各种支持utf ...