1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > C#如何实现窗体背景颜色渐变?

C#如何实现窗体背景颜色渐变?

时间:2018-11-11 04:30:57

相关推荐

C#如何实现窗体背景颜色渐变?

如下图,如何才能实现窗体颜色渐变?

实现窗体颜色渐变需要用到Color结构的FormArgb方法,该方法可以重载。

实现的主要代码如下

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace 窗体背景颜色渐变{public partial class Form1 : Form{public Form1(){InitializeComponent();}protected override void OnPaintBackground(PaintEventArgs e){int intLocation, intHeight;//定义两个int型的变量intLocation、intHeightintLocation = this.ClientRectangle.Location.Y;//为变量intLocation赋值intHeight = this.ClientRectangle.Height / 200;//为变量intHeight赋值for (int i = 255; i >= 0; i--){Color color = new Color();//定义一个Color类型的实例color//为实例color赋值color = Color.FromArgb(0, i, 0);SolidBrush SBrush = new SolidBrush(color);//实例化一个单色画笔类对象SBrushPen pen = new Pen(SBrush, 1);//实例化一个用于绘制直线和曲线的对象pene.Graphics.DrawRectangle(pen, this.ClientRectangle.X, intLocation, this.Width, intLocation + intHeight);//绘制图形intLocation = intLocation + intHeight;//重新为变量intLocation赋值}}}}

原文地址:/index.php/post/33.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。