如何消除點擊按鈕時周圍出現的白線?
阿新 • • 發佈:2019-01-08
ros vertica dev screens pen filedia align important pub
事件可以被用來設置其值,它將在新窗口出現前被引發。
方法(比使用ButtonRenderer類簡單)
的
如何消除點擊按鈕時周圍出現的白線?
StackOverFlow使用語言:VB.NET
原網站:
問題描述
在我用鼠標點擊,然後彈出一個文件選擇對話框前,按鈕沒有異常,但之後它的周圍出現了一圈白線。
只有一句代碼openFileDialog1.ShowDialog()
。
按鈕的FlatStyle
屬性為flat
,BackgroundImage
是一張PNG
格式的圖像。
白線出現後,點擊窗體它就會消除。
解答
一個簡單的辦法是把按鈕的FlatAppearance.BorderColor
屬性設置成Parent.BackColor
,即它的“容器”的背景色。這會重寫焦點框。MouseUp
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
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
Width
和Height
必須被縮小1像素)
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
如何消除點擊按鈕時周圍出現的白線?