Замена функции CSS3 повторяющийся линейный градиент() в .NET (WinForms)C#

Место общения программистов C#
Ответить
Anonymous
 Замена функции CSS3 повторяющийся линейный градиент() в .NET (WinForms)

Сообщение Anonymous »


Is there any replacement (analogue) for CSS3 function repeating-linear-gradient() in .NET (WinForms, not WPF)? I need to paint repeating "zebra stripes" (e.g. red, blue, green, red, blue, green, ...) at an angle 45 degrees.

UPD: Following Jimi's advice I managed to solve the problem only partially:

private void DrawRepeatingStripes(int degree, int stripeWidth, Color[] colors, Rectangle rect, Graphics graphics) { using (var img = new Bitmap(colors.Length * stripeWidth, rect.Height)) { using (var g = Graphics.FromImage(img)) { for (int i = 0; i < colors.Length; i++) { // TODO: cache SolidBrush g.FillRectangle(new SolidBrush(colors), stripeWidth * i, 0, stripeWidth, rect.Height); } } using (var tb = new TextureBrush(img, WrapMode.Tile)) { using (var myMatrix = new Matrix()) { myMatrix.Rotate(degree); graphics.Transform = myMatrix; graphics.FillRectangle(tb, rect); graphics.ResetTransform(); } } } } Usage (in some form's code):

protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); DrawRepeatingStripes(45, 10, new Color[] { Color.Red, Color.Yellow, Color.Green }, e.ClipRectangle, e.Graphics); } The problem is that rotation is... well, a rotation, so part of rect is filled with stripes and part is empty. Have no idea how to solve it :(


Источник: https://stackoverflow.com/questions/748 ... t-winforms
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»