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();
}
}
}
}
}
运行结果如下图: