通过下面代码在构造函数中调用方法 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# 无边框窗体边框阴影效果的更多相关文章

  1. 【C#】使用DWM实现无边框窗体阴影或全透窗体

    1.无边框窗体阴影,win7(需要开启Aero效果)及以上系统 public class LdwmForm : Form { public LdwmForm() { Initialize(); } / ...

  2. 无边框窗体和timer控件

    一.无边框窗体 1.控制按钮如何制作就是放置可以点击的控件,不局限于使用按钮或是什么别的,只要放置的控件可以点击能触发点击事件就可以了 做的好看一点,就是鼠标移入(pictureBox1_MouseE ...

  3. winfrom 无边框窗体移动和阴影

    无边框窗体移动: //窗体移动API [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [ ...

  4. winform(无边框窗体与timer)

    一.无边框窗体 1.控制按钮如何制作就是放置可以点击的控件,不局限于使用按钮或是什么别的,只要放置的控件可以点击能触发点击事件就可以了 做的好看一点,就是鼠标移入(pictureBox1_MouseE ...

  5. 【WPF】无边框窗体

    之前写了一个支持尺寸变换的无边框窗体的一个基窗体,代码如下: public class LBaseWindow : Window { /// <summary> /// 基窗体 /// & ...

  6. 【转】【WPF】 WPF 调用API修改窗体风格实现真正的无边框窗体

    WPF中设置无边框窗体似乎是要将WindowStyle设置为None,AllowTransparency=true,这样才能达到WinForm中无边框窗体的样式.但是AllowTransparency ...

  7. C#中无边框窗体移动

    拖动无边框窗体Form至桌面任何位置 首先建一个Windows应用程序将Form1的 FormBorderStyle属性设置为Noe Point mouseOff;//鼠标移动位置变量 bool le ...

  8. Qt 无边框窗体改变大小 完美实现(全部自己实现)

    近期,做项目用到无边框窗体,令人蛋疼的是无边框窗体大小的改变要像右边框那样,上下左右四周,而且要流畅. 网上也找了些代码,发现居然还要连接到windows事件,这显然不合常理,后来自己新建了demo, ...

  9. 无边框窗体、用户控件、Timer控件

    一.无边框窗体1 最大化.最小化以及关闭按钮制作实际上就是更换点击前.指向时.点击时的图片 (1)将图片放在该文件夹的Debug中,获取图片的路径Application.StartupPath + & ...

随机推荐

  1. Oracle LPAD/RPAD函数在处理中文时的注意事项

    首先看下Oracle官方对函数的定义: The RPAD function returns an expression, right-padded to a specified length with ...

  2. SharePoint通过stsadm备份和还原子网站(不是网站集)

    大家都知道SharePoint的stsadm命令提供了很多便捷甚至是唯一的操作方法! 这里列出的所有命令:http://www.cnblogs.com/dadongzuo/archive/2013/0 ...

  3. UIViewController的edgesForExtendedLayout属性

    UIViewController的edgesForExtendedLayout属性 想必大家都遇到一种情况,明明y坐标设置的是0,但是总是被讨厌的导航栏给遮住.比如下面这个情况: UILabel *l ...

  4. [Nginx][HttpUpstreamModule]翻译负载均衡

    英文原文地址:http://nginx.org/en/docs/http/ngx_http_upstream_module.html 大纲: 示例 指令 嵌入变量 ngx_http_upstream_ ...

  5. android network develop(1)----doing network background

    Develop network with HttpURLConnection & HttpClient. HttpURLConnection  is lightweight with Http ...

  6. sql2008备份集中的数据库备份与现有的xxx数据库不同解决方法

    原文链接:http://wncbl.cn/posts/1993c22/ 问题描述 今天在配置一个 ASP 站点时,导入以前的数据库备份文件,提示:sql2008备份集中的数据库备份与现有的xxx数据库 ...

  7. redis中set命令的源码分析

    首先在源码中的redis.c文件中有一个结构体:redisCommand redisCommandTable[],这个结构体中定义了每个命令对应的函数,源码中的set命令对应的函数是setComman ...

  8. redis的简单安装配置

    一.简介 Redis是一种高级key-value数据库,数据可以持久化,支持的数据类型很丰富,有字符串,哈希,链表,集合和有序集合5种数据类型 Redis支持在服务器端计算集合的并,交和补集(diff ...

  9. 【mysql】关于innodb_file_format

    一.几条mysql命令 通过以下命令看一下mysql中 innodb_file_format的配置 mysql> show engines; +--------------------+---- ...

  10. 使用dbms_logmnr查看日志文件

    大多为了寻找被意外修改的数据或者那条sql修改了哪些数据 如果是在线重做日志的话需要该日志是inactive模式下的 查询v$log和v$logfile获取相关信息 执行exec dbms_logmn ...