public void SetColor(Color color, float shadowStrength, float borderWidth, Color borderColor, float borderShadowStrength) { cleanPenAndBrush(); Color textColor = ColorUtil.GetBWColor(color); float textPenWidth = 2F; if (textFont != null) { textPenWidth = textFont.Height / 20F + 1F; } textPen = new Pen((ColorUtil.GetLuminance(textColor) > 0.5)?ColorUtil.Get("#AA000000"):ColorUtil.Get("#AAFFFFFF"), textPenWidth); textBrush = new SolidBrush(textColor); upperBrush = new SolidBrush(color); lowerBrush = new SolidBrush(ColorUtil.DarkColor(color, shadowStrength)); Color topLeftColor, bottomRightColor; if ((borderColor == ColorUtil.Auto) || (borderColor == ColorUtil.Invalid)) { topLeftColor = ColorUtil.BrightColor(color, 0.6); bottomRightColor = ColorUtil.DarkColor(color, 0.6); } else { topLeftColor = borderColor; bottomRightColor = ColorUtil.DarkColor(borderColor, borderShadowStrength); } topLeftPen = new Pen(topLeftColor, borderWidth); bottomRightPen = new Pen(bottomRightColor, borderWidth); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.SmoothingMode = SmoothingMode.AntiAlias; Color backColor; if (nState <= 0) { // 通常のボタン色 //if(this.UseVisualStyleBackColor) { // backColor = DefaultButtonColor; //} else { backColor = this.BackColor; //} } else { // マルチステートボタン色 if (State <= 0) { backColor = StateColor[0]; } else if (State < nState) { backColor = StateColor[State]; } else { backColor = StateColor[nState - 1]; } } ButtonFace face = new ButtonFace(this.Font, backColor, this.ShadowStrength, this.BorderWidth); if (!this.AutoForeColor) { face.SetTextColor(this.ForeColor); } if (this.UseEnabledColor || this.Enabled) { if ((ButtonStatus == ButtonStatusCode.Hover) && (HoverColor.A > 0)) { face.SetBorderColor(HoverColor); } else if (ButtonStatus == ButtonStatusCode.Clicked) { ButtonFace xface = face.MakePushedFace(); face.Dispose(); face = xface; } else if (this.Focused && (FocusColor.A > 0)) { face.SetBorderColor(FocusColor, ColorUtil.DarkColor(FocusColor, 0.2)); } } else { ButtonFace xface = face.MakeDisabledFace(); face.Dispose(); face = xface; } if (TextAttribute == null) { g.DrawButton(this.ClientRectangle, Radius, this.Text, face); } else { g.DrawButton(this.ClientRectangle, Radius, this.Text, TextAttribute, face); } face.Dispose(); }