窗体无边框设置后无法移动,引用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. [C#]剖析异步编程语法糖: async和await

    一.难以被接受的async 自从C#5.0,语法糖大家庭又加入了两位新成员: async和await. 然而从我知道这两个家伙之后的很长一段时间,我甚至都没搞明白应该怎么使用它们,这种全新的异步编程模 ...

  2. GoLang学习控制语句之switch

    基本结构 相比较 C 和 Java 等其它语言而言,Go 语言中的 switch 结构使用上更加灵活.它接受任意形式的表达式,例如: switch var1 { case val1: ... case ...

  3. 解决 canvas 绘图在高清屏中的模糊问题

    解决 canvas 绘图在高清屏中的模糊问题 为什么模糊 CSS 像素是一个抽象单位(1 px),浏览器根据某种规则将 css 像素转化为屏幕需要的实际像素值. 在高清屏之前,屏幕上显示一个像素点需要 ...

  4. Testing - 软件测试知识梳理 - 软件可靠性测试

    软件可靠性的基本概念 错误,缺陷,故障和失效 错误:指的是软件在生命周期中各个阶段的状态和行为与人们的期待不一致的偏差,不单单是软件系统本身,中间产品的偏差也算是软件错误 缺陷:指的是软件中一切不好的 ...

  5. 解放双手 | Jenkins + gitlab + maven 自动打包部署项目

    前言 记录 Jenkins + gitlab + maven 自动打包部署后端项目详细过程! 需求背景 不会偷懒的程序员不是好码农,传统的项目部署,有时候采用本地手动打包,再通过ssh传到服务器部署运 ...

  6. Linux inode空间占满 “no space left on device”

    Linux inode空间占满 提示 “no space left on device” 中文环境:“无法创建XXX目录,设备没有空间” Linux系统iNode耗尽硬盘无法写入文件怎么办?df -h ...

  7. 常用处理数据用法es6 语法糖总结

    一 循环(数组 ,集合)   1 forEach-----------可以遍历得到vaue和index   const arr = ['red', 'green', 'blue'];arr.forEa ...

  8. CentOS6.7-64bit编译hadoop2.6.4

    1.下载maven(apache-maven-3.3.3-bin.tar.gz) http://archive.apache.org/dist/maven/maven-3/3.3.3/binaries ...

  9. vue使用代理实现开发阶段跨域

    在config/index.js找到 proxyTable对象,添加键值对即可. "/api":{ target:"http://192.168.1.1", c ...

  10. JavaScript与CSS相对路径引用的差异

    转自:http://blog.csdn.net/luohuidong01/article/details/74938652 JS跟CSS相对路径引用的差异在于他们的参考点不一样,下面举个例子说明一下. ...