vb.net - VB.Net - 更改面板的边框颜色
问题描述
我在堆栈溢出中搜索了类似“如何更改面板的边框颜色 vb.net”的内容,但没有找到结果,我删除了 vb.net,然后像这样输入,我找到了结果,但它仅适用于 C#,我没有t C# 好多了,也许我认为我可以翻译,但我只是认为翻译不会100% 准确,所以这就是我提出这个问题的原因。请帮助我如何在VB.Net中更改面板的边框颜色我已经在属性中设置了 BorderStyle FixedSingle 但我仍然无法更改面板的边框颜色。请帮助并告诉我如何更改面板的边框颜色,否则我们不能从属性中做到这一点,我们可以通过编码来做到这一点,然后至少请给我代码。
解决方案
正如您已经提到的,这个问题有一个带有多个答案的c# 版本。
以下是答案的简短摘要:
可能性 1
最简单无代码的方式如下:
- 将
BackColor
of设置Panel1
为所需的边框颜色 - 将
Padding
of设置Panel1
为所需的边框厚度(例如2;2;2;2
) - 创建一个
Panel2
内部Panel1
并将Dock
-property 设置为Fill
- 将
BackColor
of设置Panel2
为所需的背景颜色
警告:不能使用透明背景。
可能性 2
Paint
在事件处理程序
内绘制一个边框。(从这个答案
翻译成 VB.NET 。)
Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
ControlPaint.DrawBorder(e.Graphics, Panel1.ClientRectangle, Color.DarkBlue, ButtonBorderStyle.Solid)
End Sub
可能性 3
创建您自己的Panel
-class 并在客户区绘制边框。
(从这个答案
翻译成 VB.NET 。)
<System.ComponentModel.DesignerCategory("Code")>
Public Class MyPanel
Inherits Panel
Public Sub New()
SetStyle(ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Using brush As SolidBrush = New SolidBrush(BackColor)
e.Graphics.FillRectangle(brush, ClientRectangle)
End Using
e.Graphics.DrawRectangle(Pens.Yellow, 0, 0, ClientSize.Width - 1, ClientSize.Height - 1)
End Sub
End Class
推荐阅读
- range - JFreeChart翻转范围轴方向
- matlab - Matlab 的 libifcoremd.dll 中缺少符号“for_realloc_lhs”
- finance - 雅虎新金融 API
- r - Web3.py HTTPProvider 请求 SSL 证书
- laravel - GeocoderLaravel reverse() 返回 null
- c# - 如何从 url 访问当前路由参数并在 asp.net 视图页面上引用它
- c++ - 复制省略、std::move 和链式函数调用
- javascript - 盖茨比对象内的道具
- wso2esb - 我可以参考使用 WSO2 构建集成的任何文档或示例吗?
- python - 如何使 python 类满足 SWIG 中的接口?