视觉工作室2008中的渐变胜利 [英] Gradient in visual studio 2008 winforms
问题描述
如何将控件的背景颜色设置为渐变而不是单个填充颜色?
Debra有一个问题
How can I make the background color of a control to be a gradient not a single fill color?
Debra has a question
推荐答案
嗨Debra,
Hi Debra,
你可以参考这个帖子:
http://stackoverflow.com/questions/7822514/multi-color-linear-gradient-in-winforms
这里有一个小例子给你启发通过这篇文章
http://www.bobpowell.net/linear.htm(多色混合)
here is a little example for you inspired by this article
http://www.bobpowell.net/linear.htm (Multiple colour blends)
void MainFormPaint(object sender, PaintEventArgs e)
{
LinearGradientBrush br = new LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 0 , false);
ColorBlend cb = new ColorBlend();
cb.Positions = new[] {0, 1/6f, 2/6f, 3/6f, 4/6f, 5/6f, 1};
cb.Colors = new[] {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet};
br.InterpolationColors= cb;
// rotate
br.RotateTransform(45);
// paint
e.Graphics.FillRectangle(br, this.ClientRectangle);
}
这里是结果
或者您可以为winform插入背景图片。 http://msdn.microsoft.com/en-us/library/system.windows.forms.control.backgroundimage(v = VS.100)的.aspx 一>
Or you may insert background image for winform.http://msdn.microsoft.com/en-us/library/system.windows.forms.control.backgroundimage(v=vs.100).aspx
// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
// Create a button and add it to the form.
Button button1 = new Button();
// Anchor the button to the bottom right corner of the form
button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
// Assign a background image.
button1.BackgroundImage = imageList1.Images[0];
// Specify the layout style of the background image. Tile is the default.
button1.BackgroundImageLayout = ImageLayout.Center;
// Make the button the same size as the image.
button1.Size = button1.BackgroundImage.Size;
// Set the button's TabIndex and TabStop properties.
button1.TabIndex = 1;
button1.TabStop = true;
// Add a delegate to handle the Click event.
button1.Click += new System.EventHandler(this.button1_Click);
// Add the button to the form.
this.Controls.Add(button1);
}
Regrads,
Regrads,
这篇关于视觉工作室2008中的渐变胜利的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!