以编程方式中添加datagrid



我一直在Internet上搜索如何在编程中将梯度放入数据杂志中,但不幸的是,我找不到这个问题的好来源。您如何在C#代码中进行此操作?

快速谷歌搜索为我提供了MSDN的解决方案。它具有线性涂度刷类别的对象,然后将其应用于数据网格背景。非常简单干净!您可以根据需要更改梯度的起点和终点。在MSDN链接上也很好地解释了。

LinearGradientBrush myLinearGradientBrush =
new LinearGradientBrush();
myLinearGradientBrush.StartPoint = new Point(0, 0);
myLinearGradientBrush.EndPoint = new Point(1, 1);
myLinearGradientBrush.GradientStops.Add(
new GradientStop(Colors.Yellow, 0.0));
myLinearGradientBrush.GradientStops.Add(
new GradientStop(Colors.Red, 0.25));
myLinearGradientBrush.GradientStops.Add(
new GradientStop(Colors.Blue, 0.75));
myLinearGradientBrush.GradientStops.Add(
new GradientStop(Colors.LimeGreen, 1.0));
// Use the brush to paint the datagrid .
dg.Background = myLinearGradientBrush; //dg is my datagrid name.

最新更新