下面的代码生成了这个代码,它顶部有一个标题栏的残余:
使用Windows API在C ++中调查样式选项,但实现了相同的结果。还有其他StackOverflow问题(例如How to create a form with a border, but no title bar? (like volume control on Windows 7))引用了这些相同的选项。 WinAPI调用的相应选项是WS_BORDER | WS_THICKFRAME
通过GWL_STYLE
传递给SetWindowLongPtr
。
我还调查了DWM API和调用DwmExtendFrameIntoClientArea
,在结构中作为参数传递了负边距,但负值似乎调用了窗口的特殊处理,黑色区域变得透明。边框不是我想要的那样。
using System;
using System.Drawing;
using System.Windows.Forms;
namespace StylesTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Text = String.Empty;
BackColor = Color.Black;
ControlBox = false;
FormBorderStyle = FormBorderStyle.SizableToolWindow;
}
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x0084;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT)
m.Result = new IntPtr(HTCAPTION);
}
}
}
答案 0 :(得分:0)
使用以下代码,您将得到以下结果:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace StylesTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Text = String.Empty;
BackColor = Color.Black;
ControlBox = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
}
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x0084;
const int HTCLIENT = 0x01;
const int HTCAPTION = 0x02;
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT)
m.Result = new IntPtr(HTCAPTION);
}
}
}