本文整理汇总了C#中System.Drawing.Drawing2D.LinearGradientBrush类的典型用法代码示例。如果您正苦于以下问题:C# LinearGradientBrush类的具体用法?C# LinearGradientBrush怎么用?C# LinearGradientBrush使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinearGradientBrush类属于System.Drawing.Drawing2D命名空间,在下文中一共展示了LinearGradientBrush类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EDSToolTip_Draw
void EDSToolTip_Draw(object sender, DrawToolTipEventArgs e)
{
if (e.ToolTipText.Trim() != "")
{
//e.DrawBackground();
Graphics g = e.Graphics;
//draw background
LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(Point.Empty, e.Bounds.Size), Color.FromArgb(250, 252, 253), Color.FromArgb(206, 220, 240), LinearGradientMode.Vertical);
g.FillRectangle(lgb, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
lgb.Dispose();
//Console.WriteLine(e.ToolTipText);
//draw border
ControlPaint.DrawBorder(g, e.Bounds, SystemColors.GrayText, ButtonBorderStyle.Dashed);
//draw Image
g.DrawImage(image, new Point(5, 5));
// Draw the custom text.
// The using block will dispose the StringFormat automatically.
using (StringFormat sf = new StringFormat())
{
using (Font f = new Font("Tahoma", 8))
{
e.Graphics.DrawString(e.ToolTipText, f,
Brushes.Black, e.Bounds.X + 25, e.Bounds.Y + 30, StringFormat.GenericTypographic);
}
}
}
}
示例2: OnPaint
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
//base.OnPaint(e);
Graphics g = e.Graphics;
g.Clear(this.Parent.BackColor);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(Point.Empty, e.ClipRectangle.Size);
rect.Width -= 1;
rect.Height -= 1;
Color coutBorder;
Color cinnerBorder;
Color cbackgroundTop;
Color cbackgroundBottom;
Color ctext;
if (mouseover)
{
coutBorder = ButtonColor.HoverOutBorder;
cinnerBorder = ButtonColor.HoverInnerBorder;
cbackgroundTop = ButtonColor.HoverBackgroundTop;
cbackgroundBottom = ButtonColor.HoverBackgroundBottom;
ctext = mousedown ? Color.Black : ButtonColor.HoverText;
}
else
{
coutBorder = ButtonColor.OutBorder;
cinnerBorder = ButtonColor.InnerBorder;
cbackgroundTop = ButtonColor.BackgroundTop;
cbackgroundBottom = ButtonColor.BackgroundBottom;
ctext = ButtonColor.Text;
}
using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(rect, 2))
{
using (LinearGradientBrush lgBrush = new LinearGradientBrush(Point.Empty, new Point(rect.Width, rect.Height),
cbackgroundTop, cbackgroundBottom))
{
g.FillPath(lgBrush, path);
}
g.DrawPath(new Pen(coutBorder), path);
rect.Inflate(-1, -1);
using (GraphicsPath path2 = GraphicsTools.CreateRoundRectangle(rect, 2))
{
g.DrawPath(new Pen(cinnerBorder), path2);
}
}
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
g.DrawString(this.Text, this.Font, new SolidBrush(ctext), e.ClipRectangle, sf);
UpdateBounds(this.Location.X, this.Location.Y, this.Width, this.Height, e.ClipRectangle.Width, e.ClipRectangle.Height);
}
示例3: VerifyPictureMaker
//�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡι��캯��
public VerifyPictureMaker(int width, int height, PictureBox target)
{
m_obPic = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(m_obPic);
g.Clear(Color.White);
if (target != null)
{
target.Width = width;
target.Height = height;
target.Image = m_obPic;
}
//�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡα�������
for (int i = 0; i < 25; i++)
{
int x1 = m_obRandom.Next(m_obPic.Width);
int x2 = m_obRandom.Next(m_obPic.Width);
int y1 = m_obRandom.Next(m_obPic.Height);
int y2 = m_obRandom.Next(m_obPic.Height);
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
//�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ��ַ�����
Font font = new Font("Arial", 12, (FontStyle.Bold | FontStyle.Italic));
string code = getVerifyCode(5);
LinearGradientBrush brush
= new LinearGradientBrush(new Rectangle(0, 0, m_obPic.Width, m_obPic.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(code, font, brush, 2, 0);
//�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ�ǰ������
for (int i = 0; i < 100; i++)
{
int x = m_obRandom.Next(m_obPic.Width);
int y = m_obRandom.Next(m_obPic.Height);
m_obPic.SetPixel(x, y, Color.FromArgb(m_obRandom.Next()));
}
}
示例4: paintshit
void paintshit(List<double> datta, int numPoints, double mulX, double mulY, int bw, int bh, Graphics g, LinearGradientBrush grad, Color cbase)
{
PointF[] points = new PointF[numPoints];
lock (datta)
{
int s = 0;
int samples = datta.Count;
for (; s < (points.Length - 2) - samples; s++)
{
points[s + 1] = new PointF((float)(s * mulX), bh);
}
int ofs = (points.Length - 2) - samples;
s = Math.Max(0, samples - (points.Length - 2));
for (; s < samples; s++)
{
points[s + ofs + 1] = new PointF((float)((s + ofs) * mulX),
(float)(bh - datta[s] * mulY));
}
points[0] = new PointF(0f, bh);
points[points.Length - 1] = new PointF(bw, bh);
}
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points);
g.FillPath(grad, gp);
g.DrawPath(new Pen(cbase, 2f), gp);
}
示例5: GetBrush
public static System.Drawing.Brush GetBrush(this Brush brush, Rect frame)
{
var cb = brush as SolidBrush;
if (cb != null) {
return new System.Drawing.SolidBrush (cb.Color.GetColor ());
}
var lgb = brush as LinearGradientBrush;
if (lgb != null) {
var s = lgb.Absolute ? lgb.Start : frame.Position + lgb.Start * frame.Size;
var e = lgb.Absolute ? lgb.End : frame.Position + lgb.End * frame.Size;
var b = new System.Drawing.Drawing2D.LinearGradientBrush (GetPointF (s), GetPointF (e), System.Drawing.Color.Black, System.Drawing.Color.Black);
var bb = BuildBlend (lgb.Stops);
if (bb != null) {
b.InterpolationColors = bb;
}
return b;
}
var rgb = brush as RadialGradientBrush;
if (rgb != null) {
var r = rgb.GetAbsoluteRadius (frame);
var c = rgb.GetAbsoluteCenter (frame);
var path = new GraphicsPath ();
path.AddEllipse (GetRectangleF (new Rect (c - r, 2 * r)));
var b = new PathGradientBrush (path);
var bb = BuildBlend (rgb.Stops, true);
if (bb != null) {
b.InterpolationColors = bb;
}
return b;
}
throw new NotImplementedException ("Brush " + brush);
}
示例6: OnRenderSeparator
protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
{
// base.OnRenderSeparator(e);
if (!e.Item.IsOnDropDown)
{
int top = 9;
int left = e.Item.Width / 2; left--;
int height = e.Item.Height - top * 2;
RectangleF separator = new RectangleF(left, top, 0.5f, height);
using (LinearGradientBrush b = new LinearGradientBrush(
separator.Location,
new Point(Convert.ToInt32(separator.Left), Convert.ToInt32(separator.Bottom)),
Color.Red, Color.Black))
{
ColorBlend blend = new ColorBlend();
blend.Colors = new Color[] { ToolStripColorTable.ToolStripSplitButtonTop, ToolStripColorTable.ToolStripSplitButtonMiddle, ToolStripColorTable.ToolStripSplitButtonMiddle, ToolStripColorTable.ToolStripSplitButtonBottom };
blend.Positions = new float[] { 0.0f, 0.22f, 0.78f, 1.0f };
b.InterpolationColors = blend;
e.Graphics.FillRectangle(b, separator);
}
}
}
示例7: CreateCheckCodeImage
private void CreateCheckCodeImage(string checkCode)
{
checkCode = checkCode ?? string.Empty;
if (!string.IsNullOrEmpty(checkCode))
{
Bitmap image = new Bitmap(80, 15);
Graphics graphics = Graphics.FromImage(image);
try
{
Random random = new Random();
graphics.Clear(Color.White);
Font font = new Font("Fixedsys", 12f, FontStyle.Bold);
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.FromArgb(random.Next(0xff), random.Next(0xff), random.Next(0xff)), Color.FromArgb(random.Next(200), random.Next(200), random.Next(200)), 1.2f, true);
graphics.DrawString(checkCode, font, brush, (float)-3f, (float)-2f);
for (int i = 0; i < 80; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Gif);
base.Response.ClearContent();
base.Response.ContentType = "image/Gif";
base.Response.BinaryWrite(stream.ToArray());
}
finally
{
graphics.Dispose();
image.Dispose();
}
}
}
示例8: CaptchaResult
/// <summary>
/// Creates an action result containing the file contents of a png/image with the captcha chars
/// </summary>
public static ActionResult CaptchaResult(SessionWrapper session)
{
var randomText = GenerateRandomText(6);
var hash = Utils.GetMd5Hash(randomText + GetSalt(), Encoding.ASCII);
session.CaptchaHash = hash;
var rnd = new Random();
var fonts = new[] { "Verdana", "Times New Roman" };
float orientationAngle = rnd.Next(0, 359);
const int height = 30;
const int width = 120;
var index0 = rnd.Next(0, fonts.Length);
var familyName = fonts[index0];
using (var bmpOut = new Bitmap(width, height))
{
var g = Graphics.FromImage(bmpOut);
var gradientBrush = new LinearGradientBrush(new Rectangle(0, 0, width, height),
Color.White, Color.DarkGray,
orientationAngle);
g.FillRectangle(gradientBrush, 0, 0, width, height);
DrawRandomLines(ref g, width, height);
g.DrawString(randomText, new Font(familyName, 18), new SolidBrush(Color.Gray), 0, 2);
var ms = new MemoryStream();
bmpOut.Save(ms, ImageFormat.Png);
var bmpBytes = ms.GetBuffer();
bmpOut.Dispose();
ms.Close();
return new FileContentResult(bmpBytes, "image/png");
}
}
示例9: DrawFromAlphaMainPart
/// <summary>
/// 绘制窗体主体部分白色透明层
/// </summary>
/// <param name="form"></param>
/// <param name="g"></param>
public static void DrawFromAlphaMainPart(Form form, Graphics g)
{
Color[] colors =
{
Color.FromArgb(5, Color.White),
Color.FromArgb(30, Color.White),
Color.FromArgb(145, Color.White),
Color.FromArgb(150, Color.White),
Color.FromArgb(30, Color.White),
Color.FromArgb(5, Color.White)
};
float[] pos =
{
0.0f,
0.04f,
0.10f,
0.90f,
0.97f,
1.0f
};
ColorBlend colorBlend = new ColorBlend(6);
colorBlend.Colors = colors;
colorBlend.Positions = pos;
RectangleF destRect = new RectangleF(0, 0, form.Width, form.Height);
using (LinearGradientBrush lBrush = new LinearGradientBrush(destRect, colors[0], colors[5], LinearGradientMode.Vertical))
{
lBrush.InterpolationColors = colorBlend;
g.FillRectangle(lBrush, destRect);
}
}
示例10: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle bounds = this.ClientRectangle;
float percent = this.Percent;
bounds.Width = (int)(bounds.Width * percent);
PointF p1 = new PointF(0, 0);
PointF p2 = new PointF(bounds.Width, 0);
PointF p3 = new PointF(bounds.Width, bounds.Height / 2);
PointF p4 = new PointF(0, bounds.Height / 2);
g.ResetClip();
g.Clear(this.BackColor);
if ((bounds.Width != 0) && (bounds.Height != 0))
//using (PathGradientBrush b = new PathGradientBrush(new PointF[] { p1, p2, p3, p4 }, WrapMode.TileFlipY))
//{
// b.CenterColor = Color.Gray;
// b.SurroundColors = new Color[] { Color.Transparent, Color.Transparent, Color.Turquoise, Color.Turquoise };
// g.FillRectangle(b, bounds);
//}
using (LinearGradientBrush b = new LinearGradientBrush(p1, p2, Color.Red, Color.Blue))
{
g.FillRectangle(b, bounds);
}
g.Flush();
}
示例11: DrawFormBackgroud
public void DrawFormBackgroud(Graphics g, Rectangle r)
{
drawing = new Bitmap(this.Width, this.Height, g);
gg = Graphics.FromImage(drawing);
Rectangle shadowRect = new Rectangle(r.X, r.Y, r.Width, 10);
Rectangle gradRect = new Rectangle(r.X, r.Y + 9, r.Width, 42);
//LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 41, 61), Color.FromArgb(47, 64, 94), LinearGradientMode.Vertical);
LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 41), Color.FromArgb(47, colorR, 64), LinearGradientMode.Vertical);
//LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.FromArgb(47, 64, 94), Color.FromArgb(49, 66, 95), LinearGradientMode.Vertical);
LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.Green, Color.DarkGreen, LinearGradientMode.Vertical);
ColorBlend blend = new ColorBlend();
// Set multi-color gradient
blend.Positions = new[] { 0.0f, 0.35f, 0.5f, 0.65f, 1.0f };
//blend.Colors = new[] { Color.FromArgb(47, 64, 94), Color.FromArgb(64, 88, 126), Color.FromArgb(66, 90, 129), Color.FromArgb(64, 88, 126), Color.FromArgb(49, 66, 95) };
blend.Colors = new[] { Color.FromArgb(47,colorR, 64), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(66, colorR+35, 90), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(49, colorR+1, 66) };
grad.InterpolationColors = blend;
Font myf=new System.Drawing.Font(this.Font.FontFamily,16);
// Draw basic gradient and shadow
//gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gg.FillRectangle(grad, gradRect);
gg.FillRectangle(shadow, shadowRect);
gg.DrawString("Добавить один ПК", myf, Brushes.GhostWhite, new PointF(55, 15));
gg.DrawImage(Properties.Resources.singleAdd1.ToBitmap(), 10, 10,32,32);
g.DrawImageUnscaled(drawing, 0, 0);
gg.Dispose();
// Draw checkers
//g.FillRectangle(checkers, r);
}
示例12: GDIpLines_Paint
void GDIpLines_Paint(object sender, PaintEventArgs e)
{
var lines = LineInfo.GenerateRandom(new Rectangle(Point.Empty, this.ClientSize));
var sw = new Stopwatch();
sw.Start();
var g = e.Graphics;
g.Clear(Color.Black);
foreach (var line in lines) {
using (var b = new LinearGradientBrush(line.Pa, line.Pb, line.Ca, line.Cb))
using (var p = new Pen(b, 1f)) {
g.DrawLine(p, line.Pa, line.Pb);
}
}
sw.Stop();
Program.Info(
"{0}: {1} [ms], {2} [line], {3:.00} [line/ms], {4} * {5}",
this.Text,
sw.ElapsedMilliseconds,
lines.Length,
lines.Length / (float)sw.ElapsedMilliseconds,
this.ClientSize.Width, this.ClientSize.Height
);
}
示例13: OnPaint
/// <summary>
/// Raises the Paint event.
/// </summary>
/// <param name="e">A PaintEventArgs that contains the event data.</param>
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
// Fill the background.
if (ApplicationManager.ApplicationStyle.TabPageCommandBarTopColor == ApplicationManager.ApplicationStyle.TabPageCommandBarBottomColor)
using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.TabPageCommandBarTopColor))
e.Graphics.FillRectangle(solidBrush, VirtualClientRectangle);
else
using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(VirtualClientRectangle, ApplicationManager.ApplicationStyle.TabPageCommandBarTopColor, ApplicationManager.ApplicationStyle.TabPageCommandBarBottomColor, LinearGradientMode.Vertical))
e.Graphics.FillRectangle(linearGradientBrush, VirtualClientRectangle);
// Draw the bottom line highlight color.
using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.TabPageCommandBarHighlightColor))
e.Graphics.FillRectangle(solidBrush, 0, 0, 1, VirtualHeight-1);
// Draw the bottom line lowlight color.
using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.TabPageCommandBarLowlightColor))
e.Graphics.FillRectangle(solidBrush, 0, VirtualHeight-2, VirtualWidth, 1);
// Draw the bottom line highlight color.
using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.TabPageCommandBarHighlightColor))
e.Graphics.FillRectangle(solidBrush, 0, VirtualHeight-1, VirtualWidth, 1);
// Call the base class's method so that registered delegates receive the event.
base.OnPaint(e);
}
示例14: Generate
/// <summary>
/// 生成验证码
/// </summary>
/// <returns></returns>
public static byte[] Generate(Action<string> saveCode)
{
int width = 35;
int height = 16;
int len = 4;
Bitmap img = new Bitmap(width, height);
MemoryStream ms = new MemoryStream();
Graphics g = Graphics.FromImage(img);
Rectangle r = new Rectangle(0, 0, img.Width, img.Height);
Font font = new Font("Arial", 11, FontStyle.Bold);
LinearGradientBrush brush = new LinearGradientBrush(r, Color.Red, Color.Orange, 90);
Random random = new Random();
StringBuilder code = new StringBuilder(len);
for (int i = 0; i < len; i++) code.Append(random.Next(10));
g.Clear(Color.White);
g.DrawString(code.ToString(), font, brush, 0, 0);
saveCode(code.ToString());
for (int i = 0; i < 20; i++)
{
int x = random.Next(img.Width);
int y = random.Next(img.Height);
img.SetPixel(x, y, Color.FromArgb(random.Next()));
}
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
g.Dispose();
ms.Dispose();
img.Dispose();
return ms.ToArray();
}
示例15: DrawRoundRect
public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius)
{
try
{
p.Width = 6;
Rectangle r = this.ClientRectangle;
// r.Width--; r.Height--;
using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius))
{
using (System.Drawing.Drawing2D.LinearGradientBrush gradBrush = new System.Drawing.Drawing2D.LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 90, false))
{
ColorBlend cb = new ColorBlend();
cb.Positions = new[] { 0, 1f };
cb.Colors = new[] { Color.Transparent, Color.Transparent };
gradBrush.InterpolationColors = cb;
// rotate
gradBrush.RotateTransform(0);
// paint
//g.FillPath(gradBrush, rr);
g.DrawPath(p, rr);
}
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}