窗体的大小暂时设置为:(598, 362) 涂红的数据根据你的窗体大小改动
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.Drawing.Drawing2D;
using System.Runtime.InteropServices;
namespace WinDemo
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
/// <summary>
/// Button 按钮重绘事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath myPath = new GraphicsPath();
Rectangle rect = new Rectangle(0,0,574,362);//后面2个数据调整窗体大小
myPath.AddRectangle(rect);
this.Region = new Region(myPath);
}
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("User32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
protected override void WndProc(ref System.Windows.Forms.Message m)
{
const int WM_NCPAINT = 0x85;
base.WndProc(ref m);
if (m.Msg == WM_NCPAINT)
{
IntPtr hdc = GetWindowDC(m.HWnd);
if ((int)hdc != 0)
{
Graphics g = Graphics.FromHdc(hdc);
Pen pen1 = new Pen(Color.FromArgb(64,64,64));
Pen pen2 = new Pen(Color.FromArgb(128, 128, 128));
Pen pen3 = new Pen(Color.FromArgb(212, 208, 200));
g.DrawLine(pen1, 573, 0, 573, 360);//最外边
g.DrawLine(pen2, 572, 1, 572, 359);//最外边第二条白色
g.DrawLine(pen3, 571, 2, 571, 359);
g.DrawLine(pen3, 571, 2, 571, 359);
g.Flush();
ReleaseDC(m.HWnd, hdc);
}
}
}
private void Form5_MouseCaptureChanged(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen pen1 = new Pen(Color.FromArgb(64, 64, 64));
Pen pen2 = new Pen(Color.FromArgb(128, 128, 128));
Pen pen3 = new Pen(Color.FromArgb(212, 208, 200));
g.DrawLine(pen1, 573, 0, 573, 360);//最外边
g.DrawLine(pen2, 572, 1, 572, 359);//最外边第二条白色
g.DrawLine(pen3, 571, 2, 571, 359);
g.DrawLine(pen3, 571, 2, 571, 359);
g.Flush();
}
}
}
http://zydcomputer.blog.163.com/blog/static/12427188120121102021528/
-------------------------------------------------------------------------------------------------------------
不能使用最大化窗口:MaximuzeBox 设为False
不能使用最小化窗口:MinimizeBox 设为False
不能使用红叉关闭
using System.Runtime.InteropServices;
[DllImp
internal static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);
[DllImp
internal static extern int GetMenuItemCount(IntPtr hMenu);
[DllImp
internal static extern int RemoveMenu(IntPtr hMenu, int uPosition, int uFlags);
/// <summary>
/// 窗体的关闭按钮失效
/// </summary>
protected void CloseButtonEnable()
{
// 默认窗口去除关闭按钮
const int MF_BYPOSITION = 0x00000400;
IntPtr hWindow = this.Handle;
IntPtr hMenu = GetSystemMenu(hWindow, false);
int count = GetMenuItemCount(hMenu);
RemoveMenu(hMenu, count - 1, MF_BYPOSITION);
RemoveMenu(hMenu, count - 2, MF_BYPOSITION);
}
private void confirm_Load(object sender, EventArgs e)
{
CloseButtonEnable();
}