Advertisement
Advertisement
| 04.16.2008 at 03:16PM PDT, ID: 23329115 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: |
private void GradientFill(Control paintedObject, Color firstColor, Color secondColor, LinearGradientMode linearGradientMode, bool symmetric) {
int width = paintedObject.Width;
int height = paintedObject.Height;
Bitmap bmp = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmp);
if (symmetric) {
int widthHalf = width / 2;
int heightHalf = height / 2;
Rectangle firstBrushRectangle;
Rectangle firstFillRectangle;
Rectangle secondBrushRectangle;
Rectangle secondFillRectangle;
if (linearGradientMode == LinearGradientMode.Vertical) {
firstBrushRectangle = new Rectangle(0, 0, width, heightHalf);
firstFillRectangle = new Rectangle(0, 0, width, heightHalf);
secondBrushRectangle = new Rectangle(0, heightHalf, width, height - heightHalf);
secondFillRectangle = new Rectangle(0, heightHalf, width, height - heightHalf);
} else {
firstBrushRectangle = new Rectangle(0, 0, widthHalf, height);
firstFillRectangle = new Rectangle(0, 0, widthHalf, height);
secondBrushRectangle = new Rectangle(widthHalf, 0, width - widthHalf, height);
secondFillRectangle = new Rectangle(widthHalf, 0, width - widthHalf, height);
}
LinearGradientBrush firstGradientBrush = new LinearGradientBrush(firstBrushRectangle, firstColor, secondColor, linearGradientMode);
LinearGradientBrush secondGradientBrush = new LinearGradientBrush(secondBrushRectangle, secondColor, firstColor, linearGradientMode);
g.FillRectangle(firstGradientBrush, firstFillRectangle);
g.FillRectangle(secondGradientBrush, secondFillRectangle);
} else {
Rectangle baseRectangle = new Rectangle(0, 0, width, height);
LinearGradientBrush gradientBrush = new LinearGradientBrush(baseRectangle, firstColor, secondColor, linearGradientMode);
g.FillRectangle(gradientBrush, baseRectangle);
}
paintedObject.BackgroundImage = bmp;
}
private void panel1_Resize(object sender, EventArgs e) {
GradientFill((Control)sender, Color.BlueViolet, Color.LimeGreen, LinearGradientMode.Vertical, true);
textBox1.Text = panel1.Height.ToString();
}
|