没有控制框的Windows窗体对话框图标

我想知道有没有办法在我的自定义对话框的左上角有图标,而控制框,最小化框和最大化框被禁用? 单击图标(关闭,关闭,移动等)时,我不需要任何function。 我只是希望它看起来更漂亮。

没有控制箱=>没有图标……

当ControlBox被禁用时,窗体windowstyle WS_SYSMENU标志(以某种方式远远超出)被丢弃,因此Windows无法显示图标。 实际上我还没有找到关于为什么(以及如何)右上角图标继续存在而没有WS_SYSMENU的最终解释……但是找到了一个更适合您需求的好方案)

private const int GWL_STYLE = -16; private const int WS_CLIPSIBLINGS = 1 << 26; [DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")] public static extern IntPtr SetWindowLongPtr32(HandleRef hWnd, int nIndex, HandleRef dwNewLong); [DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "GetWindowLong")] public static extern IntPtr GetWindowLong32(HandleRef hWnd, int nIndex); protected override void OnLoad(EventArgs e) { int style = (int)((long)GetWindowLong32(new HandleRef(this, this.Handle), GWL_STYLE)); SetWindowLongPtr32(new HandleRef(this, this.Handle), GWL_STYLE, new HandleRef(null, (IntPtr)(style & ~WS_CLIPSIBLINGS))); base.OnLoad(e); } 

您可以将ControlBox属性设置为false。 控制框 ,最大化,最小化按钮将不会显示在对话框中。

 Form1.ControlBox = false; 

或者,如果您不愿意禁用整个控制框,则可以这样设置。 您可以将ShowIcon属性设置为true。

 Form1.MaximizeBox = false; Form1.MinimizeBox = false; Form1.ShowIcon=true; 

您始终可以在左上角添加图像控件并为其指定图标。 那会有帮助吗?