2017-06-29 26 views

答えて

2

デフォルトのButtonでは色付きの境界線が使用できないため、これを行う方法はあまり明白ではありません。

まず、ButtonFlatStyleプロパティをFlatStyle.Flatに設定する必要があります。次に、ButtonFlatAppearance.BorderColorプロパティを選択した色に設定する必要があります。

したい場合は、Visual Studioのフォームデザイナでこれらのものの両方を行うことができ、またはあなたは、このようなコードでそれを行うことができます。

Button1.Flatstyle = FlatStyle.Flat 
Button1.FlatAppearance.BorderColor = Color.Yellow 
2

あなたがこれを行うことができますが、いくつかの異なる方法です。例えば一つのオプション(迅速かつ簡単には)System.Windows.Forms.Buttonクラスをサブクラス化して、OnPaintメソッドをオーバーライドすることです...

Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs) 
     MyBase.OnPaint(pevent) 
     Dim rect As New Rectangle(0, 0, Me.Width, Me.Height) 
     Dim mPen As New Pen(Color.Red, 3) 
     pevent.Graphics.DrawRectangle(mPen, rect) 
    End Sub 

別のオプションは、独自のボタンコントロールを作成することです、これには時間がかかり、あなたが何をしたいと思っているのかをより詳細にコントロールすることができます。あなたのボタンのFlatStyleプロパティが「フラット」に設定されている場合は、そのようなボーダーサイズとなどなど、デザイナーでFlatApperanceプロパティを変更することができます...

1
Button1.BorderColor = Drawing.Color.Red 
-1

次に、あなたを作成System.Windows.Forms.Buttonクラスをサブクラス化することができますそのようなプロテクトメソッドOnPaintをオーバーライドすることで独自の:

Protected Overrides Sub OnPaint _ 
(ByVal pevent As System.Windows.Forms.PaintEventArgs) 
    MyBase.OnPaint(pevent) 
    Dim rect As New Rectangle(0, 0, Me.Width, Me.Height) 
    Dim mypen As New Pen(Color.Green, 5) 
    pevent.Graphics.DrawRectangle(mypen, rect) 
End Sub 

しかし、あなたのボタンのFlatStyleプロパティが「フラット」、あなたはなどボーダーサイズ、ボーダー色

としてデザイナーにFlatApperanceプロパティを変更することができますように設定されている場合
関連する問題