求大神啊~!烦死我啦~!C#实现窗体自动隐藏+Form圆角

博客园铁粉 博客园铁粉 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Drawing.Drawing2D;

namespace AutoApp
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
int formwidth;
int formheight;
public Form1()
{
InitializeComponent();
}
private void form_toolStyle_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
private void form_toolStyle_MouseLeave(object sender, EventArgs e)
{
int nowx = Cursor.Position.X;
int nowy = Cursor.Position.Y;
if (nowx >= (this.Location.X + this.Width) | nowx <= this.Location.X | nowy <= this.Location.Y | nowy >= (this.Location.Y + this.Height))
{
if (this.Location.X == 0)
{
this.Width = 0;
}
if (this.Location.Y == 0)
{
this.Height = 0;
}
}
}
private void form_toolStyle_Move(object sender, EventArgs e)
{
formwidth = this.Width;
formheight = this.Height;
int x = this.Location.X;
int y = this.Location.Y;
if (x <= 0)
{
this.Location = new System.Drawing.Point(0, y);
this.Width = 0;
}
if (y <= 0)
{
this.Location = new System.Drawing.Point(x, 0);
this.Height = 0;
}
}
private void form_toolStyle_MouseEnter(object sender, EventArgs e)
{
this.Width = formwidth;
this.Height = formheight;
}
//public void SetWindowRegion()
//{
//GraphicsPath FormPath;
//FormPath = new System.Drawing.Drawing2D.GraphicsPath();
//Rectangle rect = new Rectangle(-1, -1, this.Width + 1, this.Height);
//FormPath = GetRoundedRectPath(rect, 25);
//this.Region = new Region(FormPath);
//}
//private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
//{
//int diameter = radius;
//Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
//GraphicsPath path = new GraphicsPath();
//path.AddArc(arcRect, 185, 90);
//arcRect.X = rect.Right - diameter;
//path.AddArc(arcRect, 275, 90);
//arcRect.Y = rect.Bottom - diameter;
//path.AddArc(arcRect, 356, 90);
//arcRect.X = rect.Left;
//path.AddArc(arcRect, 90, 90);
//path.CloseFigure();
//return path;
//}
//protected override void OnPaint(PaintEventArgs e)
//{
//base.OnPaint(e);
//SetWindowRegion();
//}
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
}
}
}

额,我知道代码有点多,不过这是全部的了。
不加注释的部分是实现把窗体拖到屏幕上边和右边可以自动隐藏;加注释的部分实现的是窗体边缘呈圆形。
问题是:现在两部分一起用的话,窗体可以变圆角,但是拖到屏幕上方时会有不同的效果。怎么能解决?
...全文

相关推荐

C#实现窗体圆角的一种方法

C#使用Rectangle绘制实现的圆角。 并带有最大化,最小化, 关闭, 拖动的标题控件。

杨友山

C# Windows Forms高级UI设计:圆角窗体与控件实现

Winform应用程序中的控件绘制主要依赖于.NET框架的绘图系统,该系统基于GDI+(Graphics Device Interface Plus)来实现。GDI+是一个提供2D矢量图形、文本、和图像处理功能的应用程序接口。控件绘制的基本流程包括处理WM_PAINT消息,在这个消息的处理函数中,控件通过Graphics对象的DrawXXX系列方法将元素绘制到屏幕上。

喵喵蜜

C# WinForm 实现窗体圆角

其中一个常见的需求是将窗体的边角变为圆角形状,以增加视觉吸引力。请注意,以上代码仅提供了实现窗体圆角效果的基本思路和步骤,并可能需要根据您的具体需求进行适当的调整和优化。接下来,我们需要在窗体的构造函数中添加一些代码,以修改窗体的样式。创建了一个圆角矩形区域,并将窗体的区域设置为该圆角矩形区域。在此代码中,我们设置窗体的边框样式为无,并启用双缓冲,以减少绘制时的闪烁。完成上述步骤后,您的窗体将具有圆角的外观,并且可以通过鼠标拖动进行移动。事件,并检查鼠标按下的位置是否在窗体的边角区域。

TechBlitzZ

C#中窗体Form的美化窗体圆角的处理

C#中窗体Form的美化窗体圆角的处理 C#中窗体Form的美化 VS足够强大,强大到只需动动鼠标就可以写出个基本的界面出来,但是其自带的控件都是千篇一律的样式,对于追求完美的我而言,实在是忍不下去了,只好自己亲自动手对其进行改造----继承已有的控件,再对其相关的消息或事件进行处理。窗体Form作为界面的主体部分,必先对其进行美化,在窗体自绘的过程中,需要使用到GDI+,如若对GDI+不是很了解的同学可移步我的CSDN博客或者搜索下相关的介绍。

sldkfjsldfj

C#窗体winform特效源码,无边框窗体四边阴影,圆角,淡入淡出

网上看到大部分无边框窗体阴影 都是只有右边和底部有阴影的,本源码不仅实现了四边阴影,而且包括圆角,淡入淡出等特效都有。调用非常方便,只要引用类库,需要特效的窗口继承SkinMain就可以了。

皮皮佳
评论 18
收藏 已收藏
分享
返回顶部
博客园铁粉
C# 111,129 成员 642,539 内容