vb.net 如何将自定义边框添加到 FormBorderStyle=None - 表单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14520347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:37:15  来源:igfitidea点击:

Howto add a custom border to a FormBorderStyle=None - form?

vb.netborderformborderstyle

提问by Zoef

I have a form with the property FormBorderStyle set to 'None' and with a custom bar on top side for dragging and buttons.

我有一个表单,其属性 FormBorderStyle 设置为“无”,顶部有一个用于拖动和按钮的自定义栏。

Now I'd like to give the form a border because it's a child form and the parent form has the same background color as the child, so it's hard to see the child form. And no, I can't/won't change the background color.

现在我想给表单一个边框,因为它是一个子表单,父表单与子表单具有相同的背景颜色,所以很难看到子表单。不,我不能/不会改变背景颜色。

Help

帮助

回答by theGD

There is a way without a need to set a background image and/or fixed sized form. So this is the most proper and simple way I guess. Say you have a form named Form1, all you need to do is:

有一种方法不需要设置背景图像和/或固定大小的表单。所以这是我猜的最恰当和最简单的方法。假设您有一个名为 的表单Form1,您需要做的就是:

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Black, ButtonBorderStyle.Solid)
End Sub

An alternative, if you want to use the default border provided by your Windows version:

另一种选择,如果您想使用您的 Windows 版本提供的默认边框:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
    Me.Text = ""
    Me.ControlBox = False
End Sub

回答by Francis Rubio-Salmazan

You can use the Visual Basic .NET Power Packswhich you can download here. It has this Control called LineShapethat you can put onto your border-less form's edges, like this one program that I am currently working on. Notice that the borders of the form are just LineShape.

您可以使用可以在此处下载的Visual Basic .NET Power Packs。它有这个 Control 调用,你可以把它放在你的无边框表单的边缘上,就像我目前正在开发的这个程序一样。LineShapeNotice that the borders of the form are just LineShape.

The north border is just a LineShapewith a BorderWidthset to 60and the other borders' BorderWidths are set to 10.

北边境仅有LineShape一个BorderWidth设置为60与其他边界BorderWidths的设置10

回答by TLearnC

After seeing the answer by theGD, I did the same thing for a TableLayouPanel on a form:

看到theGD的回答后,我对表单上的TableLayouPanel做了同样的事情:

Private Sub TableLayoutPanel1_Paint(sender As Object, e As PaintEventArgs) Handles TableLayoutPanel1.Paint
    ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.DarkOrange, ButtonBorderStyle.Solid)
End Sub

回答by Pure

You can use this on the form paint event:

您可以在表单绘制事件中使用它:

ControlPaint.DrawBorder(e.Graphics, Me.ClientRectangle, Color.Black, ButtonBorderStyle.Solid)

This will draw the client border only, also if you are resizing the form, or maximizing the form use Me.Refresh()on form resize events so that the form redraws its borders.

这将仅绘制客户端边框,如果您正在调整表单大小,或者Me.Refresh()在表单调整大小事件中最大化表单使用,以便表单重绘其边框,也是如此。

回答by SysDragon

Maybe you can use a BackgroundImagetransparent except in the borders.

也许您可以BackgroundImage在边框之外使用透明。