ControlPaint.FillReversibleRectangle(Rectangle, Color) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在螢幕上繪製填滿、可反轉的矩形。
public:
static void FillReversibleRectangle(System::Drawing::Rectangle rectangle, System::Drawing::Color backColor);
public static void FillReversibleRectangle (System.Drawing.Rectangle rectangle, System.Drawing.Color backColor);
static member FillReversibleRectangle : System.Drawing.Rectangle * System.Drawing.Color -> unit
Public Shared Sub FillReversibleRectangle (rectangle As Rectangle, backColor As Color)
參數
範例
下列程式碼範例示範如何使用 FillReversibleRectangle 方法。 若要執行範例,請將下列程式碼貼到表單中。 將名為 Button2
的按鈕新增至表單,並確定所有事件都已連線到其事件處理常式。
//When the mouse hovers over Button2, its ClientRectangle is filled.
void Button2_MouseHover( Object^ sender, System::EventArgs^ /*e*/ )
{
Control^ senderControl = dynamic_cast<Control^>(sender);
Rectangle screenRectangle = senderControl->RectangleToScreen( senderControl->ClientRectangle );
ControlPaint::FillReversibleRectangle( screenRectangle, senderControl->BackColor );
}
// When the mouse leaves Button2, its ClientRectangle is cleared by
// calling the FillReversibleRectangle method again.
void Button2_MouseLeave( Object^ sender, System::EventArgs^ /*e*/ )
{
Control^ senderControl = dynamic_cast<Control^>(sender);
Rectangle screenRectangle = senderControl->RectangleToScreen( senderControl->ClientRectangle );
ControlPaint::FillReversibleRectangle( screenRectangle, senderControl->BackColor );
}
//When the mouse hovers over Button2, its ClientRectangle is filled.
private void Button2_MouseHover(object sender, System.EventArgs e)
{
Control senderControl = (Control) sender;
Rectangle screenRectangle = senderControl.RectangleToScreen(
senderControl.ClientRectangle);
ControlPaint.FillReversibleRectangle(screenRectangle,
senderControl.BackColor);
}
// When the mouse leaves Button2, its ClientRectangle is cleared by
// calling the FillReversibleRectangle method again.
private void Button2_MouseLeave(object sender, System.EventArgs e)
{
Control senderControl = (Control) sender;
Rectangle screenRectangle = senderControl.RectangleToScreen(
senderControl.ClientRectangle);
ControlPaint.FillReversibleRectangle(screenRectangle,
senderControl.BackColor);
}
' When the mouse hovers over Button2, its ClientRectangle is filled.
Private Sub Button2_MouseHover(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button2.MouseHover
Dim senderControl As Control = CType(sender, Control)
Dim screenRectangle As Rectangle = _
senderControl.RectangleToScreen(senderControl.ClientRectangle)
ControlPaint.FillReversibleRectangle(screenRectangle, _
senderControl.BackColor)
End Sub
' When the mouse leaves Button2, its ClientRectangle is cleared by
' calling the FillReversibleRectangle method again.
Private Sub Button2_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button2.MouseLeave
Dim senderControl As Control = CType(sender, Control)
Dim screenRectangle As Rectangle = _
senderControl.RectangleToScreen(senderControl.ClientRectangle)
ControlPaint.FillReversibleRectangle(screenRectangle, _
senderControl.BackColor)
End Sub
備註
參數 backColor
是用來計算矩形的填滿色彩,使其一律會在背景顯示。
這個方法的結果可以透過再次繪製相同的矩形來反轉。 使用此方法繪製矩形類似于反轉螢幕區域,不同之處在于它為更廣泛的色彩提供更好的效能。