C# 无边框窗体边框阴影效果
通过下面代码在构造函数中调用方法 SetShadow();
即可实现无边框窗体的阴影效果了
需要添加命名空间 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); private void SetShadow()
{
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
}
这边这给出一个写好的Form的基类,功能Form阴影和Form的移动功能。怎么用应该都知道吧...
把自己的Form继承该BaseForm即可实现功能
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices; namespace MQXS
{
public class BaseForm:Form
{
public BaseForm()
{
Initialize();
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
_IsMouseDown = true;
_startPoint = Control.MousePosition;
_oldLocation = this.Location;
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (!_IsMouseDown) return;
Point p=Control.MousePosition;
this.Location = new Point(p.X - _startPoint.X + _oldLocation.X, p.Y - _startPoint.Y + _oldLocation.Y);
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
_IsMouseDown = false;
}
/// <summary>
///
/// </summary>
private void Initialize()
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.StartPosition = FormStartPosition.CenterScreen;
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW); //API函数加载,实现窗体边框阴影效果
} private Point _oldLocation;
private Point _startPoint;
private bool _IsMouseDown; #region 窗体边框阴影效果变量申明 private const int CS_DropSHADOW = 0x20000;
private const int GCL_STYLE = (-);
//声明Win32 API
[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); #endregion
}
}
效果图:


模拟API自绘阴影源码下载 如上图
C# 无边框窗体边框阴影效果的更多相关文章
- 【C#】使用DWM实现无边框窗体阴影或全透窗体
1.无边框窗体阴影,win7(需要开启Aero效果)及以上系统 public class LdwmForm : Form { public LdwmForm() { Initialize(); } / ...
- 无边框窗体和timer控件
一.无边框窗体 1.控制按钮如何制作就是放置可以点击的控件,不局限于使用按钮或是什么别的,只要放置的控件可以点击能触发点击事件就可以了 做的好看一点,就是鼠标移入(pictureBox1_MouseE ...
- winfrom 无边框窗体移动和阴影
无边框窗体移动: //窗体移动API [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [ ...
- winform(无边框窗体与timer)
一.无边框窗体 1.控制按钮如何制作就是放置可以点击的控件,不局限于使用按钮或是什么别的,只要放置的控件可以点击能触发点击事件就可以了 做的好看一点,就是鼠标移入(pictureBox1_MouseE ...
- 【WPF】无边框窗体
之前写了一个支持尺寸变换的无边框窗体的一个基窗体,代码如下: public class LBaseWindow : Window { /// <summary> /// 基窗体 /// & ...
- 【转】【WPF】 WPF 调用API修改窗体风格实现真正的无边框窗体
WPF中设置无边框窗体似乎是要将WindowStyle设置为None,AllowTransparency=true,这样才能达到WinForm中无边框窗体的样式.但是AllowTransparency ...
- C#中无边框窗体移动
拖动无边框窗体Form至桌面任何位置 首先建一个Windows应用程序将Form1的 FormBorderStyle属性设置为Noe Point mouseOff;//鼠标移动位置变量 bool le ...
- Qt 无边框窗体改变大小 完美实现(全部自己实现)
近期,做项目用到无边框窗体,令人蛋疼的是无边框窗体大小的改变要像右边框那样,上下左右四周,而且要流畅. 网上也找了些代码,发现居然还要连接到windows事件,这显然不合常理,后来自己新建了demo, ...
- 无边框窗体、用户控件、Timer控件
一.无边框窗体1 最大化.最小化以及关闭按钮制作实际上就是更换点击前.指向时.点击时的图片 (1)将图片放在该文件夹的Debug中,获取图片的路径Application.StartupPath + & ...
随机推荐
- Swift开发第四篇——柯里化
本篇分为两部分: 一.柯里化的基本使用 二.柯里化的使用场景 一.柯里化的基本使用 柯里化(Currying):也就是把接受多个参数的方法变换成接受第一个参数的方法,并且返回接受余下的参数并且返回结果 ...
- OC语言-02-OC语言-基础知识
一.基础语法 1> OC语言和C语言 C语言是面向过程的语言,OC语言是面向对象的语言 OC语言继承了C语言,并增加了面向对象的思想 以下内容只介绍OC语言与C语言的不同之处 2> 关键字 ...
- 关于配置并发访问的服务器apache、nginx
一. apache,nginx比较 关于Apache与Nginx的优势比较 (apache计算密集型 nginx io密集型 各有优势,不存在谁取代谁) 二.nginx 基于nginx ...
- 问题解决——Group Box控件遮挡其他控件
转载请保持文章的完整性并显要地注明出处 本文链接:http://blog.csdn.net/wlsgzl/article/details/38042301 ====================== ...
- oracle定时任务
一.简介 当我们需要oracle数据库定时自动执行一些脚本,或进行数据库备份.数据库的性能优化,包括重建索引等工作是需要使用到定时任务. 定时任务可以使用以下两种完成. 1.操作系统级的定时任务,wi ...
- PL/SQL之--函数
一.函数 函数是作为数据库对象存储在oracle数据库中,函数又被称为PL/SQL子程序.oracle处理使用系统提供的函数之外,用户还可以自己定义函数.函数通常被作为一个表达式来调用或存储过程的一个 ...
- jQuery form插件的使用--处理server返回的JSON, XML,HTML数据
详细代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> & ...
- Post-office 树状数组
Post office 题目描述 There are N(N<=1000) villages along a straight road, numbered from 1 to N for si ...
- EasyUI DataGrid单选如何取消选中
EasyUI DataGrid在多选时,选中某行,可以取消:而在单选时,并不能取消选中某一行. 可以通过修改源码来完成. 在其源码中找到 opts.singleSelect==true 将代码做如下修 ...
- hdu 1398 Square Coins(简单dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Pro ...