渐变矩形c语言代码,C#绘制渐变矩形代码

C#绘制渐变矩形代码

更新时间:2017/3/17 22:55:00  浏览量:680  手机版

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace gaolinglong35jianbiantuxing

{ public partial class Form1 : Form

{ public Form1()

{ InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{ ColorDialog dlg1 = new ColorDialog();

dlg1.Color = this.button3.BackColor;

if (dlg1.ShowDialog() == DialogResult.OK)

this.button3.BackColor = dlg1.Color;

}

private void button2_Click(object sender, EventArgs e)

{ ColorDialog dlg2 = new ColorDialog();

dlg2.Color = this.button4.BackColor;

if (dlg2.ShowDialog() == DialogResult.OK)

this.button4.BackColor = dlg2.Color;

}

private void Form1_Load(object sender, EventArgs e)

{ button3.Text = "";

button3.Enabled = false;

button3.ForeColor = this.BackColor;

button4.Text = "";

button4.Enabled = false;

button4.ForeColor = this.BackColor;

checkBox1.Checked = true;

}

private void Form1_Paint(object sender, PaintEventArgs e)

{

}

private void radioButton1_Click(object sender, EventArgs e)

{ if (checkBox1.Checked)

{ if (radioButton1.Checked)

{ Brush brush1 = new LinearGradientBrush(new Point(10, 10), new Point(10, 50), this.button3.BackColor, this.button4.BackColor);

Graphics g;

g = this.CreateGraphics();

g.FillRectangle(brush1, 20, 60, 220, 180);

brush1.Dispose();

}

}

}

private void radioButton2_Click(object sender, EventArgs e)

{ if (checkBox1.Checked)

{ if (radioButton2.Checked)

{ Brush brush1 = new LinearGradientBrush(new Point(10, 10), new Point(50, 10), this.button3.BackColor, this.button4.BackColor);

Graphics g;

g = this.CreateGraphics();

g.FillRectangle(brush1, 20, 60, 220, 180);

brush1.Dispose();

}

}

}

private void radioButton3_Click(object sender, EventArgs e)

{ if (checkBox1.Checked)

{ if (radioButton3.Checked)

{ Brush brush1 = new LinearGradientBrush(new Point(10, 10), new Point(50, 50), this.button3.BackColor, this.button4.BackColor);

Graphics g;

g = this.CreateGraphics();

g.FillRectangle(brush1, 20, 60, 220, 180);

brush1.Dispose();

}

}

}

private void radioButton4_Click(object sender, EventArgs e)

{ if (checkBox1.Checked)

{ if (radioButton4.Checked)

{ Brush brush1 = new LinearGradientBrush(new Point(10, 10), new Point(50, 50), this.button4.BackColor, this.button3.BackColor);

Graphics g;

g = this.CreateGraphics();

g.FillRectangle(brush1, 20, 60, 220, 180);

brush1.Dispose();

}

}

}

}

}

运行结果如下图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值