//private Preview GetPreviewFromIndex(int index) //{// uses panel/button list to get the settings for this line // return (Preview)m_Previews[index * 2].Tag; //} private void PreviewPanel_Paint(object sender, PaintEventArgs e) { Panel panel = (Panel)sender; Preview info = (Preview)(sender as Control).Tag; NetCanvas canvas = new NetCanvas(e.Graphics); //using (var back = canvas.CreateFill( var style = m_Config.ButtonStyle[(int)(info.Style + 2)]; Shape.DrawResources resources = new Shape.DrawResources(1, 255, 255, false, false, canvas, StaticView.InvalidationBuffer.Base, 1); style.PrepareResources(info.State, resources); RectangleF rct = new RectangleF(1, 1, panel.Width - 2, panel.Height - 2); style.Draw(canvas, resources, rct, info.State); using (Brush br = new SolidBrush(style.TextColour[(int)info.State])) e.Graphics.DrawString(Strings.Item("SAW_Settings_StyleSample"), panel.Font, br, rct, GUIUtilities.StringFormatCentreCentre); }
protected void DrawInternalBackground(PaintEventArgs e, bool actionStyle) { // should be called as the first statement in OnPaint, or any overridden version of it ButtonShape.States state = ButtonShape.States.Normal; if (this.DesignMode && GUIUtilities.SystemDPI <= 1) { GUIUtilities.SystemDPI = 96; GUIUtilities.SystemDPIRelative = 1; // NetCanvas requires these, but they are usually set during frmMenu_Load } using (Shape.DrawResources resources = new Shape.DrawResources(1, 255, 255, false, false, new NetCanvas(e.Graphics), StaticView.InvalidationBuffer.Base, 1)) { if (!Enabled) { state = ButtonShape.States.Disabled; } else if (m_SelectionDisplayFraction == 255 && m_Applicable && Enabled) { state = ButtonShape.States.Selected; } else if (m_Hover || Focused) { state = ButtonShape.States.Highlight; } else if (m_NoUser) { resources.FillAlpha = 90; // Need to fade quite a lot, because it is only the background which fades. Even 100 wasnt visible resources.EdgeAlpha = 90; } ButtonStyle style; if (this.DesignMode) { style = ButtonStyle.UserDefaultSelectionInstance; } else { style = Config.UserUser.ButtonStyle[actionStyle ? 0 : 1]; } style.PrepareResources(state, resources); RectangleF border = new RectangleF(0, 0, Width, Height); var styleState = state == ButtonShape.States.Disabled ? ButtonShape.States.Normal : state; // The index for the actual style object used (there isn't one for disabled) // For the default backgrounds (only) it is also necessary to scale the graphics to work in (approximately) mm if (style.ImageType == ButtonStyle.ImageTypes.None) { float scale = e.Graphics.DpiX / Geometry.INCH; border.Width = (border.Width - 1) / scale; // -1 because the graphics need the rectangle to be within the bounds for DrawRectangle border.Height = (border.Height - 1) / scale; // The standard border draws exactly ALONG the rectangle; we need to draw inside! border.Inflate(-style.LineStyle[(int)styleState].Width / 2 - 1, -style.LineStyle[(int)styleState].Width / 2 - 1); e.Graphics.ScaleTransform(scale, scale); } using (NetCanvas canvas = new NetCanvas(e.Graphics)) { style.Draw(canvas, resources, border, state); if (m_SelectionDisplayFraction > 0 && m_SelectionDisplayFraction < 255 && m_Applicable && Enabled) { // fading in the selection colour resources.FillAlpha = m_SelectionDisplayFraction; resources.EdgeAlpha = m_SelectionDisplayFraction; style.Draw(canvas, resources, border, ButtonShape.States.Selected); } } e.Graphics.ResetTransform(); } }