窗体无边框设置后无法移动,引用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. 自动化构建工具gradle安装教程(使用sdkman安装)

    gradle是什么?(wiki解释) Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化建构工具.它使用一种基于Groovy的特定领域语言来声明项目设置,而不是传统的 ...

  2. Aspose.Words 将word2中的内容插入到word1中的指定位置

    将word2中的内容插入到word1中的指定位置(经测试可用) 在官网找到的例子,记录一下: public static void InsertDocumentAtBookmark(string da ...

  3. 清理MVC4 Internaet 项目模板清理

    新建项目时选择空的MVC项目 是没有Bundle 引用的非常痛苦,但是如果选择Internet模板 MVC4的模板会帮你添加一堆的JQuery 引用  打开NuGet Console 执行以下指令能帮 ...

  4. 31_网络编程-struct

    一.struct   1.简述  我们可以借助一个模块,这个模块可以把要发送的数据长度转换成固定长度的字节.这样客户端每次接收消息之前只要先接受这个固定长度字节的内容看一看接下来要接收的信息大小,那么 ...

  5. jzoj4229

    按照題意暴力模擬即可 #include<bits/stdc++.h> using namespace std; int m; typedef long long ll; ll a1,q,n ...

  6. 牛客第二场 C.message(计算几何+二分)

    题目传送:https://www.nowcoder.com/acm/contest/140/C 题意:有n个云层,每个云层可以表示为y=ax+b.每个飞机的航线可以表示为时间x时,坐标为(x,cx+d ...

  7. kafka java.rmi.server.ExportException: Port already in use

    当你在kafka-run-class.sh中添加了export JMX_PORT=9300 开启了 jmx 后, 在使用 kafka bin/目录下的脚本时会报如下错误: java.rmi.serve ...

  8. CentOS的ssh sftp配置及权限设置[转载-验证可用]

    从技术角度来分析,几个要求:1.从安全方面看,sftp会更安全一点2.线上服务器提供在线服务,对用户需要控制,只能让用户在自己的home目录下活动3.用户只能使用sftp,不能ssh到机器进行操作 提 ...

  9. postgresql-清空shared_buffers

    清空os缓存,shared_buffers 1.停止数据库 pg_ctl -m fast -D /pgdata stop 2.清空高速缓存前尝试将数据刷新至磁盘 sync 3.清空缓存 echo 3 ...

  10. postgresql-pg_prewarm数据预加载。

    pg_prewarm数据预加载. http://francs3.blog.163.com/blog/static/405767272014419114519709/   https://www.kan ...