Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows 10中的Winform窗体边框问题_C#_Winforms - Fatal编程技术网

C# windows 10中的Winform窗体边框问题

C# windows 10中的Winform窗体边框问题,c#,winforms,C#,Winforms,我是WinForms新手,因此需要您就我在Windows10Pro环境中部署Winform应用程序时面临的问题提供专家建议。我看到,将FormBorderStyle设置为SizableToolWindow(或FixedToolWindow)的对话框窗体除了在顶部之外,不会在窗口的所有侧面绘制边框 FormBorderStyle设置为SizableToolWindow时的边框问题 当FormBorderStyle设置为FixedSingle时,可以看到边框 完整代码示例如下所示: public

我是WinForms新手,因此需要您就我在Windows10Pro环境中部署Winform应用程序时面临的问题提供专家建议。我看到,将FormBorderStyle设置为SizableToolWindow(或FixedToolWindow)的对话框窗体除了在顶部之外,不会在窗口的所有侧面绘制边框

FormBorderStyle设置为SizableToolWindow时的边框问题

当FormBorderStyle设置为FixedSingle时,可以看到边框

完整代码示例如下所示:

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时,客户端站点仅显示并具有完整的边框,但标题栏不可见。

好吧,我认为行为和呈现取决于操作系统,我认为没有真正的答案回答您的问题

但是,您可以创建自定义窗体/窗口,并且可以将其用作工具窗口或以任何方式使用

首先,需要将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);
        }
结果将如下图所示:

请注意,您必须注意其他事项,如允许此表单四处移动,确保添加自定义关闭按钮等

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

该自定义表格的完整代码为:

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();
        }
    }
}

我希望这会有所帮助。

如果将鼠标指针放在边缘上,当FormBorderStyle设置为SizableToolWindow时,它将显示调整大小光标,这不是工具窗口的外观吗?嗨,EpicKip,工具箱的顶部不应该有最小化和最大化按钮,但活动窗口边框应该位于所有三面(左、右、下)我认为这是Win10的问题,你对此无能为力。我遇到过这样的问题。我发现,根据大小,用鼠标调整窗口的大小会使其消失并重新出现。为了修复此问题,我更改了窗体的高度(form.ClientSize)。可能在其他计算机上,它有时仍然不会显示。似乎是唯一合乎逻辑的方法。谢谢你的回答