public static MvcHtmlString UxCheckbox(this HtmlHelper htmlHelper, string label, string group, string value = "", bool selected = false, LabelPosition position = null, CheckColor color = CheckColor.Blue, bool disabled = false, string clientId = null) { var check = new Checkbox(label, group, value, selected, position, color, disabled, clientId); return htmlHelper.RenderUxControl(check); }
public RadioButton(string label, string group, string value = "", bool selected = false, LabelPosition position = null, CheckColor color = CheckColor.Blue, bool disabled = false, string clientId = null) : base("_RadioButton",clientId) { SetGroup(group) .SetSelected(selected) .SetLabel(label, position) .SetColor(color) .SetValue(value) .SetDisabled(disabled); }
void DrawCheckFilled(SKPaintSurfaceEventArgs e) { var imageInfo = e.Info; var canvas = e?.Surface?.Canvas; using (var checkfill = new SKPaint { Style = SKPaintStyle.Fill, Color = FillColor.ToSKColor(), StrokeJoin = SKStrokeJoin.Round, IsAntialias = true }) { if (Shape == Shape.Circle) { canvas.DrawCircle(imageInfo.Width / 2, imageInfo.Height / 2, (imageInfo.Width / 2) - (OutlineWidth / 2), checkfill); } else { canvas.DrawRoundRect(OutlineWidth, OutlineWidth, imageInfo.Width - (OutlineWidth * 2), imageInfo.Height - (OutlineWidth * 2), OutlineWidth, OutlineWidth, checkfill); } } using (var checkPath = new SKPath()) { checkPath.MoveTo(.275f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.425f * imageInfo.Width, .65f * imageInfo.Height); checkPath.LineTo(.725f * imageInfo.Width, .375f * imageInfo.Height); using (var checkStroke = new SKPaint { Style = SKPaintStyle.Stroke, Color = CheckColor.ToSKColor(), StrokeWidth = (float)OutlineWidth, StrokeCap = SKStrokeCap.Round, IsAntialias = true }) { canvas.DrawPath(checkPath, checkStroke); } } }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.Paint(Graphics)"/> protected override void Paint(Graphics gr) { Rectangle butarea = ClientRectangle; GLMenuStrip p = Parent as GLMenuStrip; bool ica = IconAreaEnable && p != null; if (ica) { butarea.Width -= p.IconAreaWidth; butarea.X += p.IconAreaWidth; } if (Enabled && (Highlighted || (Hover && !DisableHoverHighlight))) { base.PaintButtonFace(ClientRectangle, gr, MouseOverColor); } else { if (ica) { using (Brush br = new SolidBrush(p.IconStripBackColor)) { gr.FillRectangle(br, new Rectangle(0, 0, p.IconAreaWidth, ClientHeight)); } } base.PaintButtonFace(butarea, gr, Enabled ? ButtonFaceColour : ButtonFaceColour.Multiply(BackDisabledScaling)); } //using (Brush inner = new SolidBrush(Color.Red)) gr.FillRectangle(inner, butarea); // Debug base.PaintButtonTextImageFocus(butarea, gr, false); // don't paint the image if (ica) { int reduce = (int)(p.IconAreaWidth * TickBoxReductionRatio); Rectangle tickarea = new Rectangle((p.IconAreaWidth - reduce) / 2, (ClientHeight - reduce) / 2, reduce, reduce); if (CheckState != CheckStateType.Unchecked) { float discaling = Enabled ? 1.0f : BackDisabledScaling; Color checkboxbordercolour = CheckBoxBorderColor.Multiply(discaling); //(Enabled && Hover) ? MouseOverBackColor : Color backcolour = (Enabled && Hover) ? MouseOverColor : ButtonFaceColour.Multiply(discaling); using (Brush inner = new System.Drawing.Drawing2D.LinearGradientBrush(tickarea, CheckBoxInnerColor.Multiply(discaling), backcolour, 225)) gr.FillRectangle(inner, tickarea); // fill slightly over size to make sure all pixels are painted using (Pen outer = new Pen(checkboxbordercolour)) // paint over to ensure good boundary gr.DrawRectangle(outer, tickarea); } tickarea.Inflate(-1, -1); // reduce it around the drawn box above if (Image != null) // if we have an image, draw it into the tick area { base.DrawImage(Image, tickarea, gr, (Enabled) ? drawnImageAttributesEnabled : drawnImageAttributesDisabled); } else { base.DrawTick(tickarea, Color.FromArgb(200, CheckColor.Multiply(Enabled ? 1.0F : ForeDisabledScaling)), CheckState, gr); } } }
void DrawCheckFilled(SKPaintSurfaceEventArgs e) { var imageInfo = e.Info; var canvas = e?.Surface?.Canvas; using (var checkfill = new SKPaint { Style = SKPaintStyle.Fill, Color = FillColor.ToSKColor(), StrokeJoin = SKStrokeJoin.Round, IsAntialias = true }) { var shape = Design == Design.Unified ? Shape : DEFAULT_SHAPE; if (shape == Shape.Circle) { canvas.DrawCircle(imageInfo.Width / 2, imageInfo.Height / 2, (imageInfo.Width / 2) - (OutlineWidth / 2), checkfill); } else { var cornerRadius = Design == Design.Native && Device.RuntimePlatform == Device.UWP ? 0 : OutlineWidth; canvas.DrawRoundRect(OutlineWidth, OutlineWidth, imageInfo.Width - (OutlineWidth * 2), imageInfo.Height - (OutlineWidth * 2), cornerRadius, cornerRadius, checkfill); } } using (var checkPath = new SKPath()) { if (Design == Design.Unified) { checkPath.MoveTo(.275f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.425f * imageInfo.Width, .65f * imageInfo.Height); checkPath.LineTo(.725f * imageInfo.Width, .375f * imageInfo.Height); } else { switch (Device.RuntimePlatform) { case Device.iOS: checkPath.MoveTo(.2f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.375f * imageInfo.Width, .675f * imageInfo.Height); checkPath.LineTo(.75f * imageInfo.Width, .3f * imageInfo.Height); break; case Device.Android: checkPath.MoveTo(.2f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.425f * imageInfo.Width, .7f * imageInfo.Height); checkPath.LineTo(.8f * imageInfo.Width, .275f * imageInfo.Height); break; case Device.UWP: checkPath.MoveTo(.15f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.375f * imageInfo.Width, .75f * imageInfo.Height); checkPath.LineTo(.85f * imageInfo.Width, .25f * imageInfo.Height); break; default: break; } } using (var checkStroke = new SKPaint { Style = SKPaintStyle.Stroke, Color = CheckColor.ToSKColor(), StrokeWidth = OutlineWidth, IsAntialias = true }) { checkStroke.StrokeCap = Design == Design.Unified ? SKStrokeCap.Round : SKStrokeCap.Butt; canvas.DrawPath(checkPath, checkStroke); } } }
protected override void OnPaint(PaintEventArgs e) { if (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard) { base.OnPaint(e); } else { bool hasimages = Image != null; using (Brush br = new SolidBrush(this.BackColor)) e.Graphics.FillRectangle(br, ClientRectangle); if (Appearance == Appearance.Button) { if (Enabled) { Rectangle marea = ClientRectangle; marea.Inflate(-2, -2); if (mouseover) { using (Brush mover = new SolidBrush(MouseOverColor)) e.Graphics.FillRectangle(mover, marea); } else if (CheckState == CheckState.Checked) { using (Brush mover = new SolidBrush(CheckColor)) e.Graphics.FillRectangle(mover, marea); } } if (hasimages) { DrawImage(ClientRectangle, e.Graphics); } var txalign = Environment.OSVersion.Platform == PlatformID.Win32NT ? RtlTranslateAlignment(TextAlign) : TextAlign; // MONO Bug cover over using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(txalign)) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; DrawText(ClientRectangle, e.Graphics, fmt); e.Graphics.SmoothingMode = SmoothingMode.Default; } } else { Rectangle tickarea = ClientRectangle; Rectangle textarea = ClientRectangle; int reduce = (int)(tickarea.Height * TickBoxReductionRatio); tickarea.Y += (tickarea.Height - reduce) / 2; tickarea.Height = reduce; tickarea.Width = tickarea.Height; if (CheckAlign == ContentAlignment.MiddleRight) { tickarea.X = ClientRectangle.Width - tickarea.Width; textarea.Width -= tickarea.Width; } else { textarea.X = tickarea.Width; textarea.Width -= tickarea.Width; } float discaling = Enabled ? 1.0f : CheckBoxDisabledScaling; Color checkboxbasecolour = (Enabled && mouseover) ? MouseOverColor : CheckBoxColor.Multiply(discaling); if (!hasimages) // draw the over box of the checkbox if no images { using (Pen outer = new Pen(checkboxbasecolour)) e.Graphics.DrawRectangle(outer, tickarea); } tickarea.Inflate(-1, -1); Rectangle checkarea = tickarea; checkarea.Width++; checkarea.Height++; // convert back to area // System.Diagnostics.Debug.WriteLine("Owner draw " + Name + checkarea + rect); if (hasimages) { if (Enabled && mouseover) // if mouse over, draw a nice box around it { using (Brush mover = new SolidBrush(MouseOverColor)) { e.Graphics.FillRectangle(mover, checkarea); } } } else { // in no image, we draw a set of boxes using (Pen second = new Pen(CheckBoxInnerColor.Multiply(discaling), 1F)) e.Graphics.DrawRectangle(second, tickarea); tickarea.Inflate(-1, -1); if (FlatStyle == FlatStyle.Flat) { using (Brush inner = new SolidBrush(checkboxbasecolour.Multiply(discaling))) e.Graphics.FillRectangle(inner, tickarea); // fill slightly over size to make sure all pixels are painted } else { using (Brush inner = new LinearGradientBrush(tickarea, CheckBoxInnerColor.Multiply(discaling), checkboxbasecolour, 225)) e.Graphics.FillRectangle(inner, tickarea); // fill slightly over size to make sure all pixels are painted } using (Pen third = new Pen(checkboxbasecolour.Multiply(discaling), 1F)) e.Graphics.DrawRectangle(third, tickarea); } e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; using (StringFormat fmt = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.FitBlackBox }) DrawText(textarea, e.Graphics, fmt); if (hasimages) { DrawImage(checkarea, e.Graphics); } else { Color c1 = Color.FromArgb(200, CheckColor.Multiply(discaling)); if (CheckState == CheckState.Checked) { Point pt1 = new Point(checkarea.X + 2, checkarea.Y + checkarea.Height / 2 - 1); Point pt2 = new Point(checkarea.X + checkarea.Width / 2 - 1, checkarea.Bottom - 2); Point pt3 = new Point(checkarea.X + checkarea.Width - 2, checkarea.Y); using (Pen pcheck = new Pen(c1, 2.0F)) { e.Graphics.DrawLine(pcheck, pt1, pt2); e.Graphics.DrawLine(pcheck, pt2, pt3); } } else if (CheckState == CheckState.Indeterminate) { Size cb = new Size(checkarea.Width - 5, checkarea.Height - 5); if (cb.Width > 0 && cb.Height > 0) { using (Brush br = new SolidBrush(c1)) { e.Graphics.FillRectangle(br, new Rectangle(new Point(checkarea.X + 2, checkarea.Y + 2), cb)); } } } } e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; } } }
public RadioButton SetColor(CheckColor color) { Color = color; return this; }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.Paint(Graphics)"/> protected override void Paint(Graphics gr) { bool hasimages = Image != null; float backdisscaling = Enabled ? 1.0f : BackDisabledScaling; float foredisscaling = Enabled ? 1.0f : ForeDisabledScaling; if (Appearance == CheckBoxAppearance.Button) { if (Enabled) { Rectangle marea = ClientRectangle; marea.Inflate(-2, -2); if (Hover) { using (var b = new LinearGradientBrush(marea, MouseOverColor, MouseOverColor.Multiply(FaceColorScaling), 90)) gr.FillRectangle(b, marea); } else if (CheckState == CheckStateType.Checked) { using (var b = new LinearGradientBrush(marea, ButtonFaceColour, ButtonFaceColour.Multiply(FaceColorScaling), 90)) gr.FillRectangle(b, marea); } } if (hasimages) { DrawImage(ClientRectangle, gr); } if (Text.HasChars()) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) DrawText(ClientRectangle, gr, fmt); } } else if (Appearance == CheckBoxAppearance.Normal) { Rectangle tickarea = ClientRectangle; Rectangle textarea = ClientRectangle; int reduce = (int)(tickarea.Height * TickBoxReductionRatio); tickarea.Y += (tickarea.Height - reduce) / 2; tickarea.Height = tickarea.Width = reduce; if (CheckAlign == ContentAlignment.MiddleRight) { tickarea.X = ClientWidth - tickarea.Width; textarea.Width -= tickarea.Width; } else { textarea.X += tickarea.Width; textarea.Width -= tickarea.Width; } if (!Text.HasChars() && ShowFocusBox) // normally, text has focus box, but if there are none, surround box { if (Focused) { using (Pen p1 = new Pen(CheckBoxBorderColor) { DashStyle = DashStyle.Dash }) { gr.DrawRectangle(p1, tickarea); } } tickarea.Inflate(-1, -1); } if (Text.HasChars()) { using (StringFormat fmt = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.FitBlackBox }) DrawText(textarea, gr, fmt); } if (!hasimages) { Color back = !Enabled?CheckBoxInnerColor.Multiply(backdisscaling) : (MouseButtonsDown == GLMouseEventArgs.MouseButtons.Left) ? MouseDownColor : Hover ? MouseOverColor : CheckBoxInnerColor; using (Brush inner = new SolidBrush(back)) gr.FillRectangle(inner, tickarea); // fill slightly over size to make sure all pixels are painted using (Pen outer = new Pen(CheckBoxBorderColor)) gr.DrawRectangle(outer, tickarea); tickarea.Inflate(-1, -1); Rectangle checkarea = tickarea; checkarea.Width++; checkarea.Height++; // convert back to area DrawTick(checkarea, Color.FromArgb(200, CheckColor.Multiply(foredisscaling)), CheckState, gr); } else { DrawImage(tickarea, gr); } } else { // RADIO Rectangle tickarea = ClientRectangle; tickarea.Height -= 6; tickarea.Y += 2; tickarea.Width = tickarea.Height; Rectangle textarea = ClientRectangle; textarea.X += tickarea.Width; textarea.Width -= tickarea.Width; if (!Text.HasChars() && ShowFocusBox) // normally, text has focus box, but if there are none, surround box { if (Focused) { using (Pen p1 = new Pen(MouseDownColor) { DashStyle = DashStyle.Dash }) { gr.DrawRectangle(p1, tickarea); } } tickarea.Inflate(-1, -1); } if (Text.HasChars()) { using (StringFormat fmt = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center }) DrawText(textarea, gr, fmt); } if (!hasimages) { using (Brush outer = new SolidBrush(CheckBoxBorderColor)) gr.FillEllipse(outer, tickarea); tickarea.Inflate(-1, -1); Color back = !Enabled?CheckBoxInnerColor.Multiply(backdisscaling) : (MouseButtonsDown == GLMouseEventArgs.MouseButtons.Left) ? MouseDownColor : Hover ? MouseOverColor : CheckBoxInnerColor; //System.Diagnostics.Debug.WriteLine($"{Name} back {back}"); using (Brush second = new SolidBrush(back)) gr.FillEllipse(second, tickarea); tickarea.Inflate(-2, -2); if (Checked) { using (Brush second = new SolidBrush(CheckColor.Multiply(foredisscaling))) gr.FillEllipse(second, tickarea); } } else { DrawImage(tickarea, gr); } } }
private void Awake() { instance = this; ApplySavedColor(); }
public Checkbox SetColor(CheckColor color) { Color = color; return this; }
private void GetView() { Content = new NControlView((ICanvas canvas, Rect rect) => { if (CheckThickness <= 0) { CheckThickness = WidthRequest / 10; } canvas.DrawRectangle(rect, new NGraphics.Size(-5), pen: new Pen(BorderColor.ToNColor(), BorderThickness), brush: new SolidBrush(FillColor.ToNColor())); if (IsChecked) { canvas.DrawLine(new NGraphics.Point(rect.Width.PerctPoint(20), rect.Height.PerctPoint(50d)), new NGraphics.Point(rect.Width.PerctPoint(40), rect.Height.PerctPoint(80)), new Pen(CheckColor.ToNColor(), CheckThickness)); canvas.DrawLine(new NGraphics.Point(rect.Width.PerctPoint(35), rect.Height.PerctPoint(80)), new NGraphics.Point(rect.Width.PerctPoint(80), rect.Height.PerctPoint(30)), new Pen(CheckColor.ToNColor(), CheckThickness)); } }); }