本文整理汇总了C#中System.Drawing.Brush.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Brush.GetType方法的具体用法?C# Brush.GetType怎么用?C# Brush.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Brush
的用法示例。
在下文中一共展示了Brush.GetType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillRectangle
public void FillRectangle(Brush brushh, RectangleF rectf)
{
if (opengl)
{
float x1 = rectf.X;
float y1 = rectf.Y;
float width = rectf.Width;
float height = rectf.Height;
GL.Begin(PrimitiveType.Quads);
GL.LineWidth(0);
if (((Type)brushh.GetType()) == typeof(LinearGradientBrush))
{
LinearGradientBrush temp = (LinearGradientBrush)brushh;
GL.Color4(temp.LinearColors[0]);
}
else
{
GL.Color4(((SolidBrush)brushh).Color.R / 255f, ((SolidBrush)brushh).Color.G / 255f, ((SolidBrush)brushh).Color.B / 255f, ((SolidBrush)brushh).Color.A / 255f);
}
GL.Vertex2(x1, y1);
GL.Vertex2(x1 + width, y1);
if (((Type)brushh.GetType()) == typeof(LinearGradientBrush))
{
LinearGradientBrush temp = (LinearGradientBrush)brushh;
GL.Color4(temp.LinearColors[1]);
}
else
{
GL.Color4(((SolidBrush)brushh).Color.R / 255f, ((SolidBrush)brushh).Color.G / 255f, ((SolidBrush)brushh).Color.B / 255f, ((SolidBrush)brushh).Color.A / 255f);
}
GL.Vertex2(x1 + width, y1 + height);
GL.Vertex2(x1, y1 + height);
GL.End();
}
else
{
graphicsObjectGDIP.FillRectangle(brushh, rectf);
}
}
示例2: DoInstructions
private void DoInstructions(Font f, StringFormat sf, Brush br, Single recX, Single recY, Single recWidth, Single recHeight, String Text)
{
Color Col = Color.Black;
if (br.GetType().Name.Equals("SolidBrush"))
{
SolidBrush sb = (SolidBrush)br;
Col = sb.Color;
}
PageText pt = new PageText(Text);
pt.X = X + recX * SCALEFACTOR;
pt.Y = Y + recY * SCALEFACTOR;
pt.W = recWidth * SCALEFACTOR;
pt.H = recHeight * SCALEFACTOR;
StyleInfo SI = new StyleInfo();
SI.Color = Col;
SI.Direction = DirectionEnum.LTR;
SI.FontFamily = f.Name;
SI.FontSize = f.Size * SCALEFACTOR;
if (f.Italic) {SI.FontStyle = FontStyleEnum.Italic;}
if (f.Bold) { SI.FontWeight = FontWeightEnum.Bold; }
if (f.Underline) { SI.TextDecoration = TextDecorationEnum.Underline; }
if (sf.LineAlignment == StringAlignment.Center)
{
SI.TextAlign = TextAlignEnum.Center;
}
else if (sf.LineAlignment == StringAlignment.Far)
{
SI.TextAlign = TextAlignEnum.Right;
}
if (sf.Alignment == StringAlignment.Center)
{
SI.VerticalAlign = VerticalAlignEnum.Middle;
}
else if (sf.Alignment == StringAlignment.Far)
{
SI.VerticalAlign = VerticalAlignEnum.Bottom;
}
if ((sf.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
{
SI.WritingMode = WritingModeEnum.tb_rl;
}
else
{
SI.WritingMode = WritingModeEnum.lr_tb;
}
pt.SI = SI;
items.Add(pt);
//r = Math.Round((r / 255), 3);
//g = Math.Round((g / 255), 3);
//b = Math.Round((b / 255), 3);
//string pdfFont = fonts.GetPdfFont(f.Name);
////need a graphics object...
//Bitmap bm = new Bitmap(1, 1);
//Graphics gr = Graphics.FromImage(bm);
//Font scaleFont = new Font(f.Name, (f.Size * ScaleY) * 1.5f, f.Style, f.Unit);
//SizeF TextSize = gr.MeasureString(Text.Substring(0, Text.Length), scaleFont, (int)(recWidth * ScaleX), sf);
//float textwidth = TextSize.Width;
//float textHeight = TextSize.Height;
//float startX = X + recX * ScaleX;
//float startY = Y + Height - recY * ScaleY - (scaleFont.Size);
//if ((sf.FormatFlags & StringFormatFlags.DirectionVertical) != StringFormatFlags.DirectionVertical)
//{
// if (sf.LineAlignment == StringAlignment.Center)
// {
// startX = (startX + (recWidth * ScaleX) / 2) - (textwidth / 4);
// }
// else if (sf.LineAlignment == StringAlignment.Far)
// {
// startX = (startX + recWidth * ScaleX) - (textwidth / 1.8f);
// }
//}
//else
//{
// startX += textwidth / 4;
// if (sf.LineAlignment == StringAlignment.Center)
// {
// startY = (startY - (recHeight * ScaleY) / 2) + (textHeight / 4);
// }
// else if (sf.LineAlignment == StringAlignment.Far)
// {
// startY = (startY - recHeight * ScaleY) + (textHeight / 1.8f);
// }
//}
//Lines.Append("\r\nq\t");
//string newtext = PdfUtility.UTF16StringQuoter(Text);
//if ((sf.FormatFlags & StringFormatFlags.DirectionVertical) != StringFormatFlags.DirectionVertical)
//{
// Lines.AppendFormat(System.Globalization.NumberFormatInfo.InvariantInfo,
// "\r\nBT/{0} {1} Tf\t{5} {6} {7} rg\t{2} {3} Td \t({4}) Tj\tET\tQ\t",
// pdfFont, scaleFont.SizeInPoints, startX, startY, newtext, r, g, b);
//}
//else
//{
//.........这里部分代码省略.........
示例3: SaveXmlBrush
static internal void SaveXmlBrush(XmlDocument doc, XmlElement newElement, Brush brush)
{
if (brush.GetType() == typeof(SolidBrush))
{
XmlElement color = doc.CreateElement("Color");
SaveXmlColor(doc, color, ((SolidBrush) brush).Color);
newElement.AppendChild(color);
}
else
throw new NotImplementedException("Cannot save this brush!");
}
示例4: DoInstructions
private void DoInstructions(Single recX, Single recY, Single recWidth, Single recHeight, Brush b, Single StartAngle, Single SweepAngle)
{
PagePie pl = new PagePie();
pl.StartAngle = StartAngle;
pl.SweepAngle = SweepAngle;
StyleInfo SI = new StyleInfo();
pl.X = X + recX * SCALEFACTOR;
pl.Y = Y + recY * SCALEFACTOR;
pl.W = recWidth * SCALEFACTOR;
pl.H = recHeight * SCALEFACTOR;
switch (b.GetType().Name)
{
case "SolidBrush":
System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b;
SI.Color = theBrush.Color;
SI.BackgroundColor = theBrush.Color;
break;
case "LinearGradientBrush":
System.Drawing.Drawing2D.LinearGradientBrush linBrush = (System.Drawing.Drawing2D.LinearGradientBrush)b;
SI.BackgroundGradientType = BackgroundGradientTypeEnum.LeftRight;
SI.BackgroundColor = linBrush.LinearColors[0];
SI.BackgroundGradientEndColor = linBrush.LinearColors[1];
break;
case "HatchBrush":
System.Drawing.Drawing2D.HatchBrush hatBrush = (System.Drawing.Drawing2D.HatchBrush)b;
SI.BackgroundColor = hatBrush.BackgroundColor;
SI.Color = hatBrush.ForegroundColor;
SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle);
break;
default:
break;
}
pl.SI = SI;
items.Add(pl);
}
示例5: DrawLegendLineMarker
internal void DrawLegendLineMarker(Graphics g, Brush b, Pen p, ChartMarkerEnum marker, int x, int y, int mSize)
{
if (b.GetType() == typeof(System.Drawing.Drawing2D.HatchBrush))
{
System.Drawing.Drawing2D.HatchBrush hb = ( System.Drawing.Drawing2D.HatchBrush) b;
b = new SolidBrush(hb.ForegroundColor);
}
Pen p2;
PointF[] points;
switch (marker)
{
case ChartMarkerEnum.Bubble:
case ChartMarkerEnum.Circle:
g.FillEllipse(b, x, y, mSize, mSize);
break;
case ChartMarkerEnum.Square:
g.FillRectangle(b, x, y, mSize, mSize);
break;
case ChartMarkerEnum.Plus:
p2 = new Pen(b, 2.0f);
g.DrawLine(p2, new Point(x + (mSize + 1) / 2, y), new Point(x + (mSize + 1) / 2, y + mSize));
//g.DrawLine(p2, new Point(x + (mSize + 1) / 2, y + (mSize + 1) / 2), new Point(x + mSize, y + (mSize + 1) / 2));
break;
case ChartMarkerEnum.Diamond:
points = new PointF[5];
points[0] = points[4] = new PointF(x + (mSize + 1) / 2, y); // starting and ending point
points[1] = new PointF(x, y + (mSize + 1) / 2);
points[2] = new PointF(x + (mSize + 1) / 2, y + mSize);
points[3] = new PointF(x + mSize, y + (mSize + 1) / 2);
g.FillPolygon(b, points);
break;
case ChartMarkerEnum.Triangle:
points = new PointF[4];
points[0] = points[3] = new PointF(x + (mSize + 1) / 2, y); // starting and ending point
points[1] = new PointF(x, y + mSize);
points[2] = new PointF(x + mSize, y + mSize);
g.FillPolygon(b, points);
break;
case ChartMarkerEnum.X:
p2 = new Pen(b, 2.0f);
g.DrawLine(p2, new Point(x, y), new Point(x + mSize, y + mSize));
g.DrawLine(p2, new Point(x, y + mSize), new Point(x + mSize, y));
break;
}
return;
}
示例6: DrawLineBetweenPoints
void DrawLineBetweenPoints(Graphics g, Report rpt, Brush brush, Point[] points,int intLineSize)
{
if (points.Length <= 1) // Need at least 2 points
return;
Pen p = null;
try
{
if (brush.GetType() == typeof(System.Drawing.Drawing2D.HatchBrush))
{
System.Drawing.Drawing2D.HatchBrush tmpBrush = (System.Drawing.Drawing2D.HatchBrush)brush;
p = new Pen(new SolidBrush(tmpBrush.ForegroundColor), intLineSize); //1.5F); // todo - use line from style ????
}
else
{
p = new Pen(brush, intLineSize);
}
if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Smooth && points.Length > 2)
g.DrawCurve(p, points, 0.5F);
else
g.DrawLines(p, points);
}
finally
{
if (p != null)
p.Dispose();
}
return;
}
示例7: DrawBubble
void DrawBubble(Report rpt, Graphics g, Brush brush, Point p, int iRow, int iCol, double bmin, double bmax, double bv,double xv,double yv)
{
Pen pen=null;
int diameter = BubbleSize(rpt, iRow, iCol, bmin, bmax, bv); // set diameter of bubble
int radius= diameter /2;
try
{
if (this.ChartDefn.Type == ChartTypeEnum.Scatter &&
brush.GetType() == typeof(System.Drawing.Drawing2D.HatchBrush))
{
System.Drawing.Drawing2D.HatchBrush tmpBrush = (System.Drawing.Drawing2D.HatchBrush)brush;
SolidBrush br = new SolidBrush(tmpBrush.ForegroundColor);
pen = new Pen(new SolidBrush(tmpBrush.ForegroundColor));
DrawLegendMarker(g, br, pen, SeriesMarker[iCol - 1], p.X - radius, p.Y - radius, diameter);
DrawDataPoint(rpt, g, new Point(p.X - 3, p.Y + 3), iRow, iCol);
}
else
{
pen = new Pen(brush);
DrawLegendMarker(g, brush, pen, ChartMarkerEnum.Bubble, p.X - radius, p.Y - radius, diameter);
DrawDataPoint(rpt, g, new Point(p.X - 3, p.Y + 3), iRow, iCol);
}
//Add a metafilecomment to use as a tooltip GJL 26092008
if (_showToolTips || _showToolTipsX)
{
string display = "";
if (_showToolTipsX) display = xv.ToString(_tooltipXFormat);
if (_showToolTips)
{
if (display.Length > 0) display += " , ";
display += yv.ToString(_tooltipYFormat);
}
String val = "ToolTip:" + display + "|X:" + (int)(p.X - 3) + "|Y:" + (int)(p.Y - 3) + "|W:" + 6 + "|H:" + 6;
g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val));
}
}
finally
{
if (pen != null)
pen.Dispose();
}
return;
}
示例8: HandleBrush
/// <summary>
/// When a GDI instruction with a brush parameter is called, there can be a lot we have to do to emulate the brush. The aim is to return a
/// style that represents the brush.
/// <para>
/// Solid brush is very easy.
/// </para>
/// <para>
/// Linear grad brush: we ignore the blend curve and the transformation (and therefore the rotation parameter if any)
/// Hatch brush:
/// </para>
/// <para>
/// Other types of brushes are too hard to emulate and are rendered pink.
/// </para>
/// </summary>
/// <param name="br"></param>
/// <returns></returns>
private SvgStyle HandleBrush(Brush br)
{
if (br.GetType() == typeof(SolidBrush))
{
return new SvgStyle((SolidBrush)br);
}
if (br.GetType() == typeof(LinearGradientBrush))
{
LinearGradientBrush grbr = (LinearGradientBrush)br;
RectangleF rc = grbr.Rectangle;
SvgLinearGradient grad = new SvgLinearGradient(rc.Left, rc.Top, rc.Right, rc.Bottom);
switch(grbr.WrapMode)
{
//I have not been able to test Clamp because using a clamped gradient appears to crash the process
//under XP (?!?!)
case WrapMode.Clamp:
grad.SpreadMethod = "pad"; grad.GradientUnits = "objectBoundingBox"; break;
case WrapMode.Tile:
grad.SpreadMethod = "repeat"; grad.GradientUnits = "userSpaceOnUse"; break;
default:
grad.SpreadMethod = "reflect"; grad.GradientUnits = "userSpaceOnUse"; break;
}
ColorBlend cb = null;
//GDI dll tends to crash when you try and access some members of gradient brushes that haven't been specified.
try
{
cb = grbr.InterpolationColors;
}
catch(Exception){}
if(cb != null)
{
for(int i = 0; i < grbr.InterpolationColors.Colors.Length; ++i)
{
grad.AddChild(new SvgStopElement(grbr.InterpolationColors.Positions[i], grbr.InterpolationColors.Colors[i]));
}
}
else
{
grad.AddChild(new SvgStopElement("0%", grbr.LinearColors[0]));
grad.AddChild(new SvgStopElement("100%", grbr.LinearColors[1]));
}
grad.Id += "_LinearGradientBrush";
_defs.AddChild(grad);
SvgStyle s = new SvgStyle();
s.Set("fill", new SvgUriReference(grad));
return s;
}
if (br.GetType() == typeof(HatchBrush))
{
HatchBrush habr = (HatchBrush)br;
SvgPatternElement patty = new SvgPatternElement(0,0,8,8, new SvgNumList("4 4 12 12"));
patty.Style.Set("shape-rendering", "crispEdges");
patty.Style.Set("stroke-linecap", "butt");
SvgRectElement rc = new SvgRectElement(0,0,8,8);
rc.Style.Set("fill", new SvgColor(habr.BackgroundColor));
patty.AddChild(rc);
AddHatchBrushDetails(patty, new SvgColor(habr.ForegroundColor), habr.HatchStyle);
patty.Id += "_HatchBrush";
patty.PatternUnits = "userSpaceOnUse";
patty.PatternContentUnits = "userSpaceOnUse";
_defs.AddChild(patty);
SvgStyle s = new SvgStyle();
s.Set("fill", new SvgUriReference(patty));
return s;
}
//most types of brush we can't emulate, but luckily they are quite unusual
return new SvgStyle(new SolidBrush(Color.Salmon));
}
示例9: DoInstructions
private void DoInstructions(PointF[] Ps, Brush b)
{
PagePolygon pl = new PagePolygon();
//pl.X = X * SCALEFACTOR;
//pl.Y = Y * SCALEFACTOR;
pl.Points = Ps;
StyleInfo SI = new StyleInfo();
switch (b.GetType().Name)
{
case "SolidBrush":
System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b;
SI.Color = theBrush.Color;
SI.BackgroundColor = theBrush.Color;
break;
case "LinearGradientBrush":
System.Drawing.Drawing2D.LinearGradientBrush linBrush = (System.Drawing.Drawing2D.LinearGradientBrush)b;
SI.BackgroundGradientType = BackgroundGradientTypeEnum.LeftRight;
SI.BackgroundColor = linBrush.LinearColors[0];
SI.BackgroundGradientEndColor = linBrush.LinearColors[1];
break;
case "HatchBrush":
System.Drawing.Drawing2D.HatchBrush hatBrush = (System.Drawing.Drawing2D.HatchBrush)b;
SI.BackgroundColor = hatBrush.BackgroundColor;
SI.Color = hatBrush.ForegroundColor;
SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle);
break;
default:
break;
}
pl.SI = SI;
items.Add(pl);
}
示例10: FillRectangle
//graphicsObject.FillRectangle(linearBrush, bg);
void FillRectangle(Brush brushh,RectangleF rectf)
{
float x1 = rectf.X;
float y1 = rectf.Y;
float width = rectf.Width;
float height = rectf.Height;
GL.Begin(BeginMode.Quads);
if (((Type)brushh.GetType()) == typeof(LinearGradientBrush))
{
LinearGradientBrush temp = (LinearGradientBrush)brushh;
GL.Color4(temp.LinearColors[0]);
}
else
{
GL.Color4(((SolidBrush)brushh).Color);
}
GL.Vertex2(x1, y1);
GL.Vertex2(x1 + width, y1);
if (((Type)brushh.GetType()) == typeof(LinearGradientBrush))
{
LinearGradientBrush temp = (LinearGradientBrush)brushh;
GL.Color4(temp.LinearColors[1]);
}
else
{
GL.Color4(((SolidBrush)brushh).Color);
}
GL.Vertex2(x1 + width, y1 + height);
GL.Vertex2(x1, y1 + height);
GL.End();
}
示例11: DoInstructions
private void DoInstructions(Single Xp, Single Yp, Single Wid, Single Hgt, Brush b)
{
switch (b.GetType().Name)
{
case "SolidBrush":
System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b;
Color col = theBrush.Color;
PageEllipse pl = new PageEllipse();
pl.X = X + Xp * SCALEFACTOR;
pl.Y = Y + Yp * SCALEFACTOR;
pl.W = Wid * SCALEFACTOR;
pl.H = Hgt * SCALEFACTOR;
StyleInfo SI = new StyleInfo();
SI.BackgroundColor = col;
pl.SI = SI;
items.Add(pl);
//Lines.AppendFormat("\r\n"); //CrLf
//Lines.AppendFormat("q\t"); //Push graphics state onto stack
//Lines.AppendFormat("{0} w\t", 1 * ScaleX); //set width of path
//Lines.AppendFormat("{0} {1} {2} RG\t", Math.Round(theBrush.Color.R / 255.0, 3), Math.Round(theBrush.Color.G / 255.0, 3), Math.Round(theBrush.Color.B / 255.0, 3)); //Set RGB colours
//Lines.AppendFormat("{0} {1} {2} rg\t", Math.Round(theBrush.Color.R / 255.0, 3), Math.Round(theBrush.Color.G / 255.0, 3), Math.Round(theBrush.Color.B / 255.0, 3)); //Set RGB colours
////Need some bezier curves to draw an ellipse.. we can't draw a circle, but we can get close.
//Double k = 0.5522847498;
//Double RadiusX = (Wid / 2.0) * ScaleX;
//Double RadiusY = (Hgt / 2.0) * ScaleY;
//Double Y4 = Y + Height - Yp * ScaleY;
//Double X1 = Xp * ScaleX + X;
//Double Y1 = Y4 - RadiusY;
//Double X4 = X1 + RadiusX;
//Lines.AppendFormat("{0} {1} m\t", X1, Y1);//FirstPoint..
//Double kRy = k * RadiusY;
//Double kRx = k * RadiusX;
////Control Point 1 will be on the same X as point 1 and be -kRy Y
//Double X2 = X1;
//Double Y2 = Y1 + kRy;
//Double X3 = X4 - kRx;
//Double Y3 = Y4;
//Lines.AppendFormat("{0} {1} {2} {3} {4} {5} c\t", X2, Y2, X3, Y3, X4, Y4); //Upper Left Quadrant
//X1 += 2 * RadiusX;
//X2 = X1;
//X3 += 2 * kRx;
//Lines.AppendFormat("{0} {1} {2} {3} {4} {5} c\t", X3, Y3, X2, Y2, X1, Y1); //Upper Right Quadrant
//Y2 -= 2 * kRy;
//Y3 -= 2 * RadiusY;
//Y4 = Y3;
//Lines.AppendFormat("{0} {1} {2} {3} {4} {5} c\t", X2, Y2, X3, Y3, X4, Y4); //Lower Right Quadrant
//X1 -= 2 * RadiusX;
//X2 = X1;
//X3 -= 2 * kRx;
//Lines.AppendFormat("{0} {1} {2} {3} {4} {5} c\t", X3, Y3, X2, Y2, X1, Y1); //Lower Right Quadrant
//Lines.AppendFormat("f\t");//fill path
//Lines.AppendFormat("Q\t");//Pop graphics state from stack
break;
}
}