vb.net - 如何删除单击时出现的按钮周围的白线
问题描述
它工作正常,直到我单击它并弹出一个文件对话框,然后它周围出现白线。
我不知道如何删除这些丑陋的线条。
唯一的代码是openFileDialog1.ShowDialog()
.
它是一个按钮,它FlatStyle
是一个图像flat
,它BackgroundImage
是一个PNG
图像。
之后出现白线,如果我单击表单,它将消失。
解决方案
一个简单的解决方法是将 ButtonFlatAppearance.BorderColor
设置为其Parent.BackColor
. 它将覆盖焦点矩形。该MouseUp
事件可用于设置值,它将在新窗口打开之前引发(Control.Leave
永远不会引发该事件):
Private Sub SomeButton_MouseUp(sender As Object, e As MouseEventArgs) Handles SomeButton.MouseUp
Dim ctl As Button = DirectCast(sender, Button)
ctl.FlatAppearance.BorderColor = ctl.Parent.BackColor
End Sub
使用该Control.Paint
事件,我们还可以使用该Control.BackColor
属性来绘制边框,均使用ControlPaint类DrawBorder
方法(比使用ButtonRenderer类更简单):
Private Sub SomeButton_Paint(sender As Object, e As PaintEventArgs) Handles SomeButton.Paint
Dim ctl As Button = DirectCast(sender, Button)
ControlPaint.DrawBorder(e.Graphics, ctl.ClientRectangle, ctl.BackColor, ButtonBorderStyle.Solid)
End Sub
并自己绘制控件的边框:(
请注意,在尺寸和尺寸ClientRectangle
上,尺寸必须缩小 1 个像素。这是设计使然)。Width
Height
Private Sub SomeButton_Paint(sender As Object, e As PaintEventArgs) Handles SomeButton.Paint
Dim ctl As Control = DirectCast(sender, Control)
Dim r As Rectangle = ctl.ClientRectangle
Using pen As Pen = New Pen(ctl.BackColor, 1)
e.Graphics.DrawRectangle(pen, r.X, r.Y, r.Width - 1, r.Height - 1)
End Using
End Sub
推荐阅读
- apache-kafka-streams - 部署相同的 spring boot kafka 流应用程序有时可以工作,有时它会返回 HostInfo{host='unavailable', port=-1}
- c++ - 一个继承的类可以有多少个构造函数?
- reactjs - 反应中从孩子到父母的数据流
- php - PHP 在 JSON 上抛出 JSON_ERROR_STATE_MISMATCH,检查每个在线验证器是否有效
- sql - 使用 NOT 关键字时如何使用内连接
- java - 使用来自 Raspberry Pi Zero W 的自定义数据广播 BLE 广告,将其用作外围设备
- elixir - 使用动态运算符创建 Ecto 查询
- wagtail - 用于获取子页面的 Wagtail Admin api 调用在资源管理器中返回 0
- gams-math - 在 MIP 海运库存路由建模期间,无法在决策变量之间分配条件
- db2 - 这在 DB2 中意味着什么:DECLARE CONTINUE HANDLER FOR NOT FOUND..?