//控件圆角 private void SetReion() { if (base.Region != null) { base.Region.Dispose(); } if (RoundStyle != SkinClass.RoundStyle.None) { SkinTools.CreateRegion(this, this.ClientRectangle, Radius, RoundStyle); } }
//重绘 protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; //取得当前需要绘画的图像 Bitmap btm = null; switch (_controlState) { case ControlState.Pressed: btm = (Bitmap)DownBack; break; case ControlState.Hover: btm = (Bitmap)MouseBack; break; default: btm = (Bitmap)NormlBack; break; } if (btm != null) { //是否启用九宫绘图 if (Palace) { ImageDrawRect.DrawRect(g, btm, new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height), Rectangle.FromLTRB(BackRectangle.X, BackRectangle.Y, BackRectangle.Width, BackRectangle.Height), 1, 1); } else { g.DrawImage(btm, this.ClientRectangle); } } //绘制圆角 SkinTools.CreateRegion(this, this.ClientRectangle, radius, RoundStyle); base.OnPaint(e); }
protected override void OnPaint(PaintEventArgs e) { //设置圆角矩形窗体 SkinTools.CreateRegion(this, 4); base.OnPaint(e); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); base.OnPaintBackground(e); //变量与初始化 Graphics g = e.Graphics; Rectangle rc = this.ClientRectangle; g.SmoothingMode = SmoothingMode.AntiAlias; Color baseColor; Color CpBaseColor = BaseColor; Color borderColor; Color innerBorderColor = Color.FromArgb(200, 255, 255, 255); Bitmap btm = null; //停止当前状态 if (StopState != StopStates.NoStop) { _controlState = (ControlState)StopState; } //获取父容器色调 if (InheritColor) { CpBaseColor = this.Parent.BackColor; } //取得当前需要绘画的图像与色调 switch (_controlState) { case ControlState.Hover: btm = (Bitmap)MouseBack; baseColor = GetColor(CpBaseColor, 0, -13, -8, -3); borderColor = CpBaseColor; break; case ControlState.Pressed: btm = (Bitmap)DownBack; baseColor = GetColor(CpBaseColor, 0, -35, -24, -9); borderColor = CpBaseColor; break; default: btm = (Bitmap)NormlBack; baseColor = CpBaseColor; borderColor = CpBaseColor; break; } if (!this.Enabled) { baseColor = SystemColors.ControlDark; borderColor = SystemColors.ControlDark; } //如果有图则用图绘画 if (btm != null && DrawType == DrawStyle.Img) { //绘制圆角 SkinTools.CreateRegion(this, rc, Radius, RoundStyle); //绘制不规则区域 if (Create && _controlState != states) { SkinTools.CreateControlRegion(this, btm, 1); } //是否启用九宫绘图 if (Palace) { ImageDrawRect.DrawRect(g, btm, rc, Rectangle.FromLTRB(BackRectangle.X, BackRectangle.Y, BackRectangle.Width, BackRectangle.Height), 1, 1); } else { g.DrawImage(btm, 0, 0, this.Width, this.Height); } } else if (DrawType == DrawStyle.Draw) //无图则用色调绘图 { RenderBackgroundInternal( g, rc, baseColor, borderColor, innerBorderColor, RoundStyle, Radius, 0.35f, true, true, LinearGradientMode.Vertical); //执行动画渐变效果 if (FadeGlow) { DrawButtonBackgroundFromBuffer(e.Graphics); } } #region 绘画文字和图像 Image img = null; if (imageButton == null) { imageButton = new Button(); imageButton.Parent = new TransparentControl(); imageButton.SuspendLayout(); imageButton.BackColor = Color.Transparent; imageButton.FlatAppearance.BorderSize = 0; imageButton.FlatStyle = FlatStyle.Flat; } else { imageButton.SuspendLayout(); } imageButton.AutoEllipsis = AutoEllipsis; if (Enabled) { Color txtColor = this.Enabled ? ForeColor : SystemColors.ControlDark; //是否根据背景色决定字体颜色 if (ForeColorSuit) { //如果背景色为暗色 if (SkinTools.ColorSlantsDarkOrBright(CpBaseColor)) { txtColor = Color.White; } else//如果背景色为亮色 { txtColor = Color.Black; } } imageButton.ForeColor = txtColor; } else { imageButton.ForeColor = Color.FromArgb((3 * ForeColor.R + BaseColor.R) >> 2, (3 * ForeColor.G + BaseColor.G) >> 2, (3 * ForeColor.B + BaseColor.B) >> 2); } imageButton.Font = Font; imageButton.RightToLeft = RightToLeft; if (imageButton.Image != Image && imageButton.Image != null) { imageButton.Image.Dispose(); } if (Image != null) { img = this.Image; if (this.ImageList != null && this.ImageIndex != -1) { img = this.ImageList.Images[this.ImageIndex]; } Bitmap map = new Bitmap(img, ImageSize); imageButton.Image = map; if (!Enabled) { using (Graphics gr = Graphics.FromImage(imageButton.Image)) { ControlPaint.DrawImageDisabled(gr, Image, 0, 0, this.BaseColor); } } } imageButton.ImageAlign = ImageAlign; imageButton.ImageIndex = ImageIndex; imageButton.ImageKey = ImageKey; imageButton.ImageList = ImageList; imageButton.Padding = Padding; imageButton.Size = Size; imageButton.Text = Text; imageButton.TextAlign = TextAlign; imageButton.TextImageRelation = TextImageRelation; imageButton.UseCompatibleTextRendering = UseCompatibleTextRendering; imageButton.UseMnemonic = UseMnemonic; imageButton.ResumeLayout(); InvokePaint(imageButton, e); #endregion //储存上一个的样式状态 states = _controlState; }
protected override void OnCreateControl() { //绘制圆角 SkinTools.CreateRegion(this, this.ClientRectangle, radius, RoundStyle); base.OnCreateControl(); }
protected override void OnPaint(PaintEventArgs e) { Rectangle rectangle; Rectangle rectangle2; Color controlDark; Color color3; base.OnPaint(e); base.OnPaintBackground(e); Graphics g = e.Graphics; Rectangle clientRectangle = base.ClientRectangle; this.CalculateRect(out rectangle, out rectangle2); g.SmoothingMode = SmoothingMode.AntiAlias; Color baseColor = this.BaseColor; Color innerBorderColor = Color.FromArgb(200, 0xff, 0xff, 0xff); Bitmap mouseBack = null; int num = 0; if (this.StopState != StopStates.NoStop) { this._controlState = (ControlState)this.StopState; } if (this.InheritColor) { baseColor = base.Parent.BackColor; } switch (this._controlState) { case ControlState.Hover: mouseBack = (Bitmap)this.MouseBack; controlDark = this.GetColor(baseColor, 0, -13, -8, -3); color3 = baseColor; break; case ControlState.Pressed: mouseBack = (Bitmap)this.DownBack; controlDark = this.GetColor(baseColor, 0, -35, -24, -9); color3 = baseColor; num = 1; break; default: mouseBack = (Bitmap)this.NormlBack; controlDark = baseColor; color3 = baseColor; break; } if (!base.Enabled) { controlDark = SystemColors.ControlDark; color3 = SystemColors.ControlDark; } if ((mouseBack != null) && (this.DrawType == DrawStyle.Img)) { SkinTools.CreateRegion(this, clientRectangle, this.Radius, this.RoundStyle); if (this.Create && (this._controlState != this.states)) { SkinTools.CreateControlRegion(this, mouseBack, 1); } if (this.Palace) { ImageDrawRect.DrawRect(g, mouseBack, clientRectangle, Rectangle.FromLTRB(this.BackRectangle.X, this.BackRectangle.Y, this.BackRectangle.Width, this.BackRectangle.Height), 1, 1); } else { g.DrawImage(mouseBack, 0, 0, base.Width, base.Height); } } else if (this.DrawType == DrawStyle.Draw) { this.RenderBackgroundInternal(g, clientRectangle, controlDark, color3, innerBorderColor, this.RoundStyle, this.Radius, 0.35f, true, true, LinearGradientMode.Vertical); if (this.FadeGlow) { this.DrawButtonBackgroundFromBuffer(e.Graphics); } } Image image = null; Size empty = Size.Empty; if (base.Image != null) { if (string.IsNullOrEmpty(this.Text)) { image = base.Image; empty = new Size(image.Width, image.Height); clientRectangle.Inflate(-4, -4); if ((empty.Width * empty.Height) != 0) { Rectangle withinThis = clientRectangle; withinThis = ImageDrawRect.HAlignWithin(empty, withinThis, base.ImageAlign); withinThis = ImageDrawRect.VAlignWithin(empty, withinThis, base.ImageAlign); if (!base.Enabled) { ControlPaint.DrawImageDisabled(g, image, withinThis.Left, withinThis.Top, this.BackColor); } else { g.DrawImage(image, withinThis.Left + num, withinThis.Top + num, image.Width, image.Height); } } } else { g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.DrawImage(base.Image, rectangle, -num, -num, base.Image.Width, base.Image.Height, GraphicsUnit.Pixel); } } else if ((base.ImageList != null) && (base.ImageIndex != -1)) { image = base.ImageList.Images[base.ImageIndex]; } Color foreColor = base.Enabled ? this.ForeColor : SystemColors.ControlDark; if (this.ForeColorSuit) { if (SkinTools.ColorSlantsDarkOrBright(baseColor)) { foreColor = Color.White; } else { foreColor = Color.Black; } } TextRenderer.DrawText(g, this.Text, this.Font, rectangle2, foreColor, GetTextFormatFlags(this.TextAlign, this.RightToLeft == RightToLeft.Yes)); this.states = this._controlState; }