ToolStripProfessionalRenderer 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
사용자 지정 색상표와 효율적인 스타일을 적용하여 ToolStrip 개체의 그리기 기능을 처리합니다.
public ref class ToolStripProfessionalRenderer : System::Windows::Forms::ToolStripRenderer
public class ToolStripProfessionalRenderer : System.Windows.Forms.ToolStripRenderer
type ToolStripProfessionalRenderer = class
inherit ToolStripRenderer
Public Class ToolStripProfessionalRenderer
Inherits ToolStripRenderer
- 상속
예제
다음 코드 예제에서는 비슷한 복합 컨트롤을 만드는 방법을 보여 줍니다 합니다 탐색 창 Microsoft® Outlook®에서 제공 합니다. 전체 코드 목록은 참조 하세요 방법: 전문적인 스타일의 ToolStrip 컨트롤 만들기합니다.
internal class StackRenderer : ToolStripProfessionalRenderer
{
private static Bitmap titleBarGripBmp;
private static string titleBarGripEnc = @"Qk16AQAAAAAAADYAAAAoAAAAIwAAAAMAAAABABgAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAAuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5ANj+RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5ANj+RzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMANj+";
// Define titlebar colors.
private static Color titlebarColor1 = Color.FromArgb(89, 135, 214);
private static Color titlebarColor2 = Color.FromArgb(76, 123, 204);
private static Color titlebarColor3 = Color.FromArgb(63, 111, 194);
private static Color titlebarColor4 = Color.FromArgb(50, 99, 184);
private static Color titlebarColor5 = Color.FromArgb(38, 88, 174);
private static Color titlebarColor6 = Color.FromArgb(25, 76, 164);
private static Color titlebarColor7 = Color.FromArgb(12, 64, 154);
private static Color borderColor = Color.FromArgb(0, 0, 128);
static StackRenderer()
{
titleBarGripBmp = StackView.DeserializeFromBase64(titleBarGripEnc);
}
public StackRenderer()
{
}
private void DrawTitleBar(Graphics g, Rectangle rect)
{
// Assign the image for the grip.
Image titlebarGrip = titleBarGripBmp;
// Fill the titlebar.
// This produces the gradient and the rounded-corner effect.
g.DrawLine(new Pen(titlebarColor1), rect.X, rect.Y, rect.X + rect.Width, rect.Y);
g.DrawLine(new Pen(titlebarColor2), rect.X, rect.Y + 1, rect.X + rect.Width, rect.Y + 1);
g.DrawLine(new Pen(titlebarColor3), rect.X, rect.Y + 2, rect.X + rect.Width, rect.Y + 2);
g.DrawLine(new Pen(titlebarColor4), rect.X, rect.Y + 3, rect.X + rect.Width, rect.Y + 3);
g.DrawLine(new Pen(titlebarColor5), rect.X, rect.Y + 4, rect.X + rect.Width, rect.Y + 4);
g.DrawLine(new Pen(titlebarColor6), rect.X, rect.Y + 5, rect.X + rect.Width, rect.Y + 5);
g.DrawLine(new Pen(titlebarColor7), rect.X, rect.Y + 6, rect.X + rect.Width, rect.Y + 6);
// Center the titlebar grip.
g.DrawImage(
titlebarGrip,
new Point(rect.X + ((rect.Width / 2) - (titlebarGrip.Width / 2)),
rect.Y + 1));
}
// This method handles the RenderGrip event.
protected override void OnRenderGrip(ToolStripGripRenderEventArgs e)
{
DrawTitleBar(
e.Graphics,
new Rectangle(0, 0, e.ToolStrip.Width, 7));
}
// This method handles the RenderToolStripBorder event.
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
DrawTitleBar(
e.Graphics,
new Rectangle(0, 0, e.ToolStrip.Width, 7));
}
// This method handles the RenderButtonBackground event.
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
{
Graphics g = e.Graphics;
Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size);
Color gradientBegin = Color.FromArgb(203, 225, 252);
Color gradientEnd = Color.FromArgb(125, 165, 224);
ToolStripButton button = e.Item as ToolStripButton;
if (button.Pressed || button.Checked)
{
gradientBegin = Color.FromArgb(254, 128, 62);
gradientEnd = Color.FromArgb(255, 223, 154);
}
else if (button.Selected)
{
gradientBegin = Color.FromArgb(255, 255, 222);
gradientEnd = Color.FromArgb(255, 203, 136);
}
using (Brush b = new LinearGradientBrush(
bounds,
gradientBegin,
gradientEnd,
LinearGradientMode.Vertical))
{
g.FillRectangle(b, bounds);
}
e.Graphics.DrawRectangle(
SystemPens.ControlDarkDark,
bounds);
g.DrawLine(
SystemPens.ControlDarkDark,
bounds.X,
bounds.Y,
bounds.Width - 1,
bounds.Y);
g.DrawLine(
SystemPens.ControlDarkDark,
bounds.X,
bounds.Y,
bounds.X,
bounds.Height - 1);
ToolStrip toolStrip = button.Owner;
ToolStripButton nextItem = button.Owner.GetItemAt(
button.Bounds.X,
button.Bounds.Bottom + 1) as ToolStripButton;
if (nextItem == null)
{
g.DrawLine(
SystemPens.ControlDarkDark,
bounds.X,
bounds.Height - 1,
bounds.X + bounds.Width - 1,
bounds.Height - 1);
}
}
}
Friend Class StackRenderer
Inherits ToolStripProfessionalRenderer
Private Shared titleBarGripBmp As Bitmap
Private Shared titleBarGripEnc As String = "Qk16AQAAAAAAADYAAAAoAAAAIwAAAAMAAAABABgAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAAuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5ANj+RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5ANj+RzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMANj+"
' Define titlebar colors.
Private Shared titlebarColor1 As Color = Color.FromArgb(89, 135, 214)
Private Shared titlebarColor2 As Color = Color.FromArgb(76, 123, 204)
Private Shared titlebarColor3 As Color = Color.FromArgb(63, 111, 194)
Private Shared titlebarColor4 As Color = Color.FromArgb(50, 99, 184)
Private Shared titlebarColor5 As Color = Color.FromArgb(38, 88, 174)
Private Shared titlebarColor6 As Color = Color.FromArgb(25, 76, 164)
Private Shared titlebarColor7 As Color = Color.FromArgb(12, 64, 154)
Private Shared borderColor As Color = Color.FromArgb(0, 0, 128)
Shared Sub New()
titleBarGripBmp = StackView.DeserializeFromBase64(titleBarGripEnc)
End Sub
Public Sub New()
End Sub
Private Sub DrawTitleBar(ByVal g As Graphics, ByVal rect As Rectangle)
' Assign the image for the grip.
Dim titlebarGrip As Image = titleBarGripBmp
' Fill the titlebar.
' This produces the gradient and the rounded-corner effect.
g.DrawLine(New Pen(titlebarColor1), rect.X, rect.Y, rect.X + rect.Width, rect.Y)
g.DrawLine(New Pen(titlebarColor2), rect.X, rect.Y + 1, rect.X + rect.Width, rect.Y + 1)
g.DrawLine(New Pen(titlebarColor3), rect.X, rect.Y + 2, rect.X + rect.Width, rect.Y + 2)
g.DrawLine(New Pen(titlebarColor4), rect.X, rect.Y + 3, rect.X + rect.Width, rect.Y + 3)
g.DrawLine(New Pen(titlebarColor5), rect.X, rect.Y + 4, rect.X + rect.Width, rect.Y + 4)
g.DrawLine(New Pen(titlebarColor6), rect.X, rect.Y + 5, rect.X + rect.Width, rect.Y + 5)
g.DrawLine(New Pen(titlebarColor7), rect.X, rect.Y + 6, rect.X + rect.Width, rect.Y + 6)
' Center the titlebar grip.
g.DrawImage(titlebarGrip, New Point(rect.X + (rect.Width / 2 - titlebarGrip.Width / 2), rect.Y + 1))
End Sub
' This method handles the RenderGrip event.
Protected Overrides Sub OnRenderGrip(e As ToolStripGripRenderEventArgs)
DrawTitleBar(e.Graphics, New Rectangle(0, 0, e.ToolStrip.Width, 7))
End Sub
' This method handles the RenderToolStripBorder event.
Protected Overrides Sub OnRenderToolStripBorder(e As ToolStripRenderEventArgs)
DrawTitleBar(e.Graphics, New Rectangle(0, 0, e.ToolStrip.Width, 7))
End Sub
' This method handles the RenderButtonBackground event.
Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs)
Dim g As Graphics = e.Graphics
Dim bounds As New Rectangle(Point.Empty, e.Item.Size)
Dim gradientBegin As Color = Color.FromArgb(203, 225, 252)
Dim gradientEnd As Color = Color.FromArgb(125, 165, 224)
Dim button As ToolStripButton = CType(e.Item, ToolStripButton)
If button.Pressed OrElse button.Checked Then
gradientBegin = Color.FromArgb(254, 128, 62)
gradientEnd = Color.FromArgb(255, 223, 154)
ElseIf button.Selected Then
gradientBegin = Color.FromArgb(255, 255, 222)
gradientEnd = Color.FromArgb(255, 203, 136)
End If
Dim b = New LinearGradientBrush(bounds, gradientBegin, gradientEnd, LinearGradientMode.Vertical)
Try
g.FillRectangle(b, bounds)
Finally
b.Dispose()
End Try
e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, bounds)
g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Y, bounds.Width - 1, bounds.Y)
g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Y, bounds.X, bounds.Height - 1)
Dim toolStrip As ToolStrip = button.Owner
Dim nextItem As ToolStripButton = CType(button.Owner.GetItemAt(button.Bounds.X, button.Bounds.Bottom + 1), ToolStripButton)
If nextItem Is Nothing Then
g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Height - 1)
End If
End Sub
End Class
설명
ToolStripProfessionalRenderer 펜과 호출을 대체할 수 있는 색 테이블을 기반으로 하는 브러시를 만듭니다 ProfessionalColorTable합니다.
생성자
ToolStripProfessionalRenderer() |
ToolStripProfessionalRenderer 클래스의 새 인스턴스를 초기화합니다. |
ToolStripProfessionalRenderer(ProfessionalColorTable) |
ToolStripProfessionalRenderer 클래스의 새 인스턴스를 초기화합니다. |
속성
ColorTable |
그리기에 사용할 색상표를 가져옵니다. |
RoundedEdges |
컨트롤의 가장자리를 사각형이나 날카로운 모양이 아니라 둥근 모양으로 표시할지를 나타내는 값을 가져오거나 설정합니다. |
메서드
이벤트
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET