ButtonRenderer.DrawParentBackground(Graphics, Rectangle, Control) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Draws the background of a control's parent in the specified area.
public:
static void DrawParentBackground(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::Control ^ childControl);
public static void DrawParentBackground (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.Control childControl);
static member DrawParentBackground : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.Control -> unit
Public Shared Sub DrawParentBackground (g As Graphics, bounds As Rectangle, childControl As Control)
Parameters
- bounds
- Rectangle
The Rectangle in which to draw the parent control's background. This rectangle should be inside the child control's bounds.
- childControl
- Control
The control whose parent's background will be drawn.
Examples
The following code example uses the DrawParentBackground method to paint over an area of a custom control. This code example is part of a larger example provided for the ButtonRenderer class.
// Draw the large or small button, depending on the current state.
protected:
virtual void OnPaint(PaintEventArgs^ e) override
{
__super::OnPaint(e);
// Draw the smaller pressed button image
if (state == PushButtonState::Pressed)
{
// Set the background color to the parent if visual styles
// are disabled, because DrawParentBackground will only paint
// over the control background if visual styles are enabled.
if (Application::RenderWithVisualStyles)
{
this->BackColor = Color::Azure;
}
else
{
this->BackColor = this->Parent->BackColor;
}
// If you comment out the call to DrawParentBackground,
// the background of the control will still be visible
// outside the pressed button, if visual styles are enabled.
ButtonRenderer::DrawParentBackground(e->Graphics,
ClientRectangle, this);
ButtonRenderer::DrawButton(e->Graphics, ClickRectangle,
this->Text, this->Font, true, state);
}
// Draw the bigger unpressed button image.
else
{
ButtonRenderer::DrawButton(e->Graphics, ClientRectangle,
this->Text, this->Font, false, state);
}
}
// Draw the large or small button, depending on the current state.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Draw the smaller pressed button image
if (state == PushButtonState.Pressed)
{
// Set the background color to the parent if visual styles
// are disabled, because DrawParentBackground will only paint
// over the control background if visual styles are enabled.
this.BackColor = Application.RenderWithVisualStyles ?
Color.Azure : this.Parent.BackColor;
// If you comment out the call to DrawParentBackground,
// the background of the control will still be visible
// outside the pressed button, if visual styles are enabled.
ButtonRenderer.DrawParentBackground(e.Graphics,
ClientRectangle, this);
ButtonRenderer.DrawButton(e.Graphics, ClickRectangle,
this.Text, this.Font, true, state);
}
// Draw the bigger unpressed button image.
else
{
ButtonRenderer.DrawButton(e.Graphics, ClientRectangle,
this.Text, this.Font, false, state);
}
}
' Draw the large or small button, depending on the current state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
' Draw the smaller pressed button image.
If state = PushButtonState.Pressed Then
' Set the background color to the parent if visual styles
' are disabled, because DrawParentBackground will only paint
' over the control background if visual styles are enabled.
If Application.RenderWithVisualStyles Then
Me.BackColor = Color.Azure
Else
Me.BackColor = Me.Parent.BackColor
End If
' If you comment out the call to DrawParentBackground,
' the background of the control will still be visible
' outside the pressed button, if visual styles are enabled.
ButtonRenderer.DrawParentBackground(e.Graphics, _
Me.ClientRectangle, Me)
ButtonRenderer.DrawButton(e.Graphics, ClickRectangle, _
Me.Text, Me.Font, True, state)
' Draw the bigger unpressed button image.
Else
ButtonRenderer.DrawButton(e.Graphics, Me.ClientRectangle, _
Me.Text, Me.Font, False, state)
End If
End Sub
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET