private void PaintTab(int index, RenderContext renderContext) { bool Selected = (SelectedIndex == index); Rectangle tabRect = GetTabRect(index); if ((Appearance & TabAppearance.Normal) == TabAppearance.Normal) { tabRect.Inflate(0, Selected ? 2 : 1); tabRect.X += 1; } PaletteState State = default(PaletteState); if (Selected) { State = PaletteState.Pressed; } else { State = tabRect.Contains(PointToClient(MousePosition)) ? PaletteState.Tracking : PaletteState.Normal; } VisualOrientation visualOrientation = (VisualOrientation)Alignment; if (m_PaletteTabButtonBackground.GetBackDraw(State) == InheritBool.True) { using (GraphicsPath BackPath = m_Renderer.RenderStandardBorder.GetBackPath(renderContext, tabRect, m_PaletteTabButtonBorder, visualOrientation, State)) { m_MementoTabButtonBackground = m_Renderer.RenderStandardBack.DrawBack(renderContext, tabRect, BackPath, m_PaletteTabButtonBackground, visualOrientation, State, m_MementoTabButtonBackground); } } if (m_PaletteTabButtonBorder.GetBorderDraw(State) == InheritBool.True) { m_Renderer.RenderStandardBorder.DrawBorder(renderContext, tabRect, m_PaletteTabButtonBorder, visualOrientation, State); } else if (Selected) { using (Pen PBorder = new Pen(m_PaletteTabPageBorder.GetBorderColor1(PaletteState.Normal))) { Rectangle RBorder = tabRect; RBorder.Width -= 1; renderContext.Graphics.DrawRectangle(PBorder, RBorder); } } // (TODO: adjust rendering for other Appearance settings) if (ImageList != null) { Image tabImage = null; if (TabPages[index].ImageIndex != -1) { int imageIndex = TabPages[index].ImageIndex; tabImage = ImageList.Images[imageIndex]; } else if (TabPages[index].ImageKey != null) { string imageKey = TabPages[index].ImageKey; tabImage = ImageList.Images[imageKey]; } if (tabImage != null) { int x = tabRect.X + (tabImage.Width / 2); int y = tabRect.Y + (tabRect.Height - tabImage.Height) / 2; renderContext.Graphics.DrawImage(tabImage, x, y); tabRect.X += tabImage.Width; tabRect.Width -= tabImage.Width; } } if (m_TabFont == null || (!object.ReferenceEquals(m_TabFont, g_TabFontBold) & !object.ReferenceEquals(m_TabFont, g_TabFontRegular))) { if (renderContext.Graphics.MeasureString(TabPages[index].Text, g_TabFontBold, tabRect.X, g_StringFormat).Width <= tabRect.Width) { m_TabFont = g_TabFontBold; } else { m_TabFont = g_TabFontRegular; } } renderContext.Graphics.DrawString(TabPages[index].Text, m_TabFont, m_TabBrush, tabRect, g_StringFormat); }
protected override void OnPaint(PaintEventArgs e) { if (_palette != null) { // Get the renderer associated with this palette IRenderer renderer = _palette.GetRenderer(); // Create the rendering context that is passed into all renderer calls using (RenderContext renderContext = new RenderContext(this, e.Graphics, e.ClipRectangle, renderer)) { ///////////////////////////////////////////////////////////////////////////////// // We want to draw the background of the entire control over the entire client // // area. In this example we are using a background style of HeaderPrimary // ///////////////////////////////////////////////////////////////////////////////// using (GraphicsPath path = CreateRectGraphicsPath(ClientRectangle)) { // Set the style we want picked up from the base palette _paletteBack.Style = PaletteBackStyle.HeaderPrimary; // Ask renderer to draw the background _mementoBack1 = renderer.RenderStandardBack.DrawBack(renderContext, ClientRectangle, path, _paletteBack, Orientation, Enabled ? PaletteState.Normal : PaletteState.Disabled, _mementoBack1); } // We want the inner part of the control to act like a button, so // we need to find the correct palette state based on if the mouse // is over the control if the mouse button is pressed down or not. PaletteState buttonState = GetButtonState(); // Create a rectangle inset, this is where we will draw a button Rectangle innerRect = ClientRectangle; innerRect.Inflate(-20, -20); // Set the style of button we want to draw _paletteBack.Style = PaletteBackStyle.ButtonStandalone; _paletteBorder.Style = PaletteBorderStyle.ButtonStandalone; _paletteContent.Style = PaletteContentStyle.ButtonStandalone; // Do we need to draw the background? if (_paletteBack.GetBackDraw(buttonState) == InheritBool.True) { ////////////////////////////////////////////////////////////////////////////////// // In case the border has a rounded effect we need to get the background path // // to draw from the border part of the renderer. It will return a path that is // // appropriate for use drawing within the border settings. // ////////////////////////////////////////////////////////////////////////////////// using (GraphicsPath path = renderer.RenderStandardBorder.GetBackPath(renderContext, innerRect, _paletteBorder, Orientation, buttonState)) { // Ask renderer to draw the background _mementoBack2 = renderer.RenderStandardBack.DrawBack(renderContext, innerRect, path, _paletteBack, Orientation, buttonState, _mementoBack2); } } // Do we need to draw the border? if (_paletteBorder.GetBorderDraw(buttonState) == InheritBool.True) { // Now we draw the border of the inner area, also in ButtonStandalone style renderer.RenderStandardBorder.DrawBorder(renderContext, innerRect, _paletteBorder, Orientation, buttonState); } // Do we need to draw the content? if (_paletteContent.GetContentDraw(buttonState) == InheritBool.True) { // Last of all we draw the content over the top of the border and background renderer.RenderStandardContent.DrawContent(renderContext, innerRect, _paletteContent, _mementoContent, Orientation, buttonState, false, true); } } } base.OnPaint(e); }
//ComponentFactory Palette Painting protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { //Define Bounds Rectangle ButtonBounds = new Rectangle(0, 0, 16, 16); RectangleF ButtonCircleBounds = new RectangleF((float)0, (float)0, (float)15.1, (float)15.1); //Smoothing Mode e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; //Paint Base base.OnPaint(e); if (_palette != null) { //Get the renderer associated with this palette IRenderer Renderer = _palette.GetRenderer(); //Create the rendering context that is passed into all renderer calls using (RenderContext RenderContext = new RenderContext(this, e.Graphics, ButtonBounds, Renderer)) { // Set the style we want picked up from the base palette m_paletteBack.Style = PaletteBackStyle.HeaderPrimary; //Fill The Space using (GraphicsPath Path = GetButtonPath(ButtonBounds)) { // Ask renderer to draw the background m_mementoBack1 = Renderer.RenderStandardBack.DrawBack(RenderContext, ButtonBounds, Path, m_paletteBack, m_orientation, (this.Enabled ? PaletteState.Normal : PaletteState.Disabled), m_mementoBack1); } // We want the inner part of the control to act like a button, so // we need to find the correct palette state based on if the mouse // is over the control if the mouse button is pressed down or not. PaletteState ButtonState = GetButtonState(); // Set the style of button we want to draw m_paletteBack.Style = m_visuallook; m_paletteBorder.Style = (PaletteBorderStyle)m_visuallook; m_paletteContent.Style = (PaletteContentStyle)m_visuallook; // Do we need to draw the background? if (m_paletteBack.GetBackDraw(ButtonState) == InheritBool.True) { using (GraphicsPath Path = GetRoundedSquarePath(ButtonCircleBounds)) { // Ask renderer to draw the background m_mementoBack2 = Renderer.RenderStandardBack.DrawBack(RenderContext, ButtonBounds, Path, m_paletteBack, m_orientation, ButtonState, m_mementoBack2); } } // Do we need to draw the border? if (m_paletteBorder.GetBorderDraw(ButtonState) == InheritBool.True) { // Now we draw the border of the inner area, also in ButtonStandalone style e.Graphics.DrawEllipse(new Pen(m_paletteBorder.GetBorderColor2(ButtonState)), ButtonCircleBounds); } e.Graphics.SmoothingMode = SmoothingMode.None; //Draw Magnifying Sign switch (m_buttonstyle) { case ButtonStyles.MinusButton: Rectangle MinusOuterBounds = new Rectangle(3, (this.Height / 2) - 2, 10, 4); Rectangle MinusInnerBounds = new Rectangle(4, (this.Height / 2) - 1, 8, 2); e.Graphics.FillRectangle(new SolidBrush(m_outerColor), MinusOuterBounds); e.Graphics.FillRectangle(new SolidBrush(m_innerColor), MinusInnerBounds); break; case ButtonStyles.PlusButton: DrawPlusOuter(e.Graphics, m_outerColor); DrawPlusInner(e.Graphics, m_innerColor); break; } } } }