2017-04-03 110 views
0

我是WinForms的新手,因此当我在Window 10 Pro环境中部署Winform应用程序时,需要有关于此问题的专家建议。我发现将FormBorderStyle设置为SizableToolWindow(或者FixedToolWindow)的对话框不会在窗口的所有边上绘制边框,除非是顶部。Windows 10中的Winform窗体边框问题

时,当FormBorderStyle设置为FixedSingle
Border is seen when FormBorderStyle is set to FixedSingle

样品完整代码如下FormBorderStyle设置为SizableToolWindow
Border Issue when FormBorderStyle is set to SizableToolWindow

边境被看作

边界问题:

public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      Form form = new Form(); 
      form.FormBorderStyle = FormBorderStyle.FixedSingle; 
      form.ShowDialog(); 
     } 
    } 

有没有可以覆盖这种行为的解决方案,可能只适用于Windows 10?

编辑:我观察到,当我将窗体的ControlBox属性设置为false时,客户端网站仅显示并具有完整边框,但标题栏不可见。

+0

如果将鼠标指针放在边上,当FormBorderStyle设置为SizableToolWindow时,它将显示调整大小的光标 –

+1

是不是工具窗口应该看起来如何? – EpicKip

+0

嗨EpicKip,工具箱不应该在顶部有最小化和最大化按钮,但活动窗口边框应该出现在所有三面(左,右和底部) – Shanks

回答

0

那么,我会说行为和渲染取决于操作系统,我认为你的问题没有真正的答案。

但是,您可以创建自定义表单/窗口,并且可以将其用作工具窗口或您想要的。

首先,你需要将FormBorderStyle设置为无

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 

然后你可以重写OnPaint方法有画你的边界像下面

protected override void OnPaint(PaintEventArgs e) 
     { 
      Rectangle borderRectangle = new Rectangle(1, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 2); 

      e.Graphics.DrawRectangle(Pens.Blue, borderRectangle); 
      base.OnPaint(e); 
     } 

结果会是这样的代码如下图所示: enter image description here

请注意,您将不得不照顾其他事情,如givi如果要移动此表单的功能,请确保添加了自定义关闭按钮等。

完成此操作后,可以将此表单用作基类,并从该表单继承未来的表单类。

的自定义表单的完整代码如下:

using System; 
using System.Drawing; 
using System.Windows.Forms; 

namespace CustomForm 
{ 
    public partial class CustomBorderForm : Form 
    { 
     public CustomBorderForm() 
     { 
      InitializeComponent(); 
     } 

     protected override void OnPaint(PaintEventArgs e) 
     { 
      Rectangle borderRectangle = new Rectangle(1, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 2); 

      e.Graphics.DrawRectangle(Pens.Blue, borderRectangle); 
      base.OnPaint(e); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      this.Close(); 
     } 
    } 
} 

我希望这是有帮助的。

+0

似乎是唯一合乎逻辑的方法。感谢你的回答 – Shanks