本文整理汇总了C#中System.Drawing.Graphics类的典型用法代码示例。如果您正苦于以下问题:C# Graphics类的具体用法?C# Graphics怎么用?C# Graphics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Graphics类属于System.Drawing命名空间,在下文中一共展示了Graphics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(System.Drawing.RectangleF dirtyRect)
{
var g = new Graphics();
// NSView does not have a background color so we just use Clear to white here
g.Clear(Color.White);
//RectangleF ClientRectangle = this.Bounds;
RectangleF ClientRectangle = dirtyRect;
// Calculate the location and size of the drawing area
// within which we want to draw the graphics:
Rectangle rect = new Rectangle((int)ClientRectangle.X, (int)ClientRectangle.Y,
(int)ClientRectangle.Width, (int)ClientRectangle.Height);
drawingRectangle = new Rectangle(rect.Location, rect.Size);
drawingRectangle.Inflate(-offset, -offset);
//Draw ClientRectangle and drawingRectangle using Pen:
g.DrawRectangle(Pens.Red, rect);
g.DrawRectangle(Pens.Black, drawingRectangle);
// Draw a line from point (3,2) to Point (6, 7)
// using the Pen with a width of 3 pixels:
Pen aPen = new Pen(Color.Green, 3);
g.DrawLine(aPen, Point2D(new PointF(3, 2)),
Point2D(new PointF(6, 7)));
g.PageUnit = GraphicsUnit.Inch;
ClientRectangle = new RectangleF(0.5f,0.5f, 1.5f, 1.5f);
aPen.Width = 1 / g.DpiX;
g.DrawRectangle(aPen, ClientRectangle);
aPen.Dispose();
g.Dispose();
}
示例2: DrawPaperSheet
public void DrawPaperSheet(Graphics graphic)
{
if (SingleOffset.Paper == null) { return; }
var comp1 = (int)(SingleOffset.Paper.SizeH / printFormatWidth.Value) * (int)(SingleOffset.Paper.SizeW / printFormatHeight.Value);
var comp2 = (int)(SingleOffset.Paper.SizeH / printFormatHeight.Value) * (int)(SingleOffset.Paper.SizeW / printFormatWidth.Value);
if (comp1 > comp2)
{
var widthUse = (int)(SingleOffset.Paper.SizeW / printFormatHeight.Value);
var heightUse = (int)(SingleOffset.Paper.SizeH / printFormatWidth.Value);
var flipped = widthUse * printFormatHeight.Value > SingleOffset.Paper.SizeW || heightUse * printFormatWidth.Value > SingleOffset.Paper.SizeH;
Drawing.Draw(graphic, SingleOffset.Paper.SizeW, SingleOffset.Paper.SizeH, (int)printFormatHeight.Value, (int)printFormatWidth.Value, heightUse, widthUse, false, false);
usePerSheetLabel.Text = comp1 == usePerSheet.Value ? "" : string.Format("Anzahl Nutzen passt nicht.{0}Empfohlen wären {1} Nutzen.", Environment.NewLine, comp1);
usePerSheetLabel.Update();
}
else
{
var heightUse = (int)(SingleOffset.Paper.SizeH / printFormatHeight.Value);
var widthUse = (int)(SingleOffset.Paper.SizeW / printFormatWidth.Value);
var flipped = widthUse * printFormatWidth.Value > SingleOffset.Paper.SizeW || heightUse * printFormatHeight.Value > SingleOffset.Paper.SizeH;
Drawing.Draw(graphic, SingleOffset.Paper.SizeW, SingleOffset.Paper.SizeH, (int)printFormatWidth.Value, (int)printFormatHeight.Value, widthUse, heightUse, false, false);
usePerSheetLabel.Text = comp2 == usePerSheet.Value ? "" : string.Format("Anzahl Nutzen passt nicht.{0}Empfohlen wären {1} Nutzen.", Environment.NewLine, comp2);
usePerSheetLabel.Update();
}
}
示例3: Paint
protected internal override void Paint(Graphics gr)
{
var hf = CandleView.BAR_WIDTH / 2;
if (m_View.Kind== ViewKind.SideBySide)
{
var hh = Host.Height / Host.Zoom;
gr.FillRectangle(Brushes.Green, this.Left, hh - m_Lay_BuyHeight, hf, m_Lay_BuyHeight);
gr.FillRectangle(Brushes.Red, this.Left+hf, hh - m_Lay_SellHeight, hf, m_Lay_SellHeight);
}
else if (m_View.Kind== ViewKind.Stacked)
{
var hh = Host.Height / Host.Zoom;
gr.FillRectangle(Brushes.Green, this.Left, hh - m_Lay_BuyHeight, CandleView.BAR_WIDTH, m_Lay_BuyHeight);
gr.FillRectangle(Brushes.Red, this.Left, hh - m_Lay_BuyHeight-m_Lay_SellHeight, CandleView.BAR_WIDTH, m_Lay_SellHeight);
}
else//centered
{
var mid = (Host.Height / 2) / Host.Zoom;
gr.FillRectangle(Brushes.Green, this.Left, mid - m_Lay_BuyHeight, CandleView.BAR_WIDTH, m_Lay_BuyHeight);
gr.FillRectangle(Brushes.Red, this.Left, mid, CandleView.BAR_WIDTH, m_Lay_SellHeight);
}
}
示例4: PaintJunk
public void PaintJunk(Graphics g)
{
g.FillRectangle(Brushes.Transparent, 0, 0, 1000, 1000);
using (Font font = new Font("Courier New", 20, FontStyle.Bold))
{
if (bounceCounter == -1) return;
const string str = "DEVELOPER BUILD";
float x = 0;
int timefactor = bounceCounter;
for (int i = 0; i < str.Length; i++)
{
string slice = str.Substring(i, 1);
g.PageUnit = GraphicsUnit.Pixel;
x += g.MeasureString(slice, font).Width - 1;
int offset = -i * 3 + timefactor*3;
int yofs = 0;
if (offset < 0)
{ continue; }
else
if (offset < DigitTable.Length)
yofs = DigitTable[offset];
g.DrawString(slice, font, Brushes.Black, 5 + x, 15 - yofs);
}
}
}
示例5: DoPaint
public override void DoPaint(Graphics g)
{
using (Brush b = new SolidBrush(ZenParams.WindowColor))
{
g.FillRectangle(b, 0, 0, Width, Height);
}
}
示例6: DrawSelf
public override void DrawSelf(Graphics grfx)
{
grfx.Transform = this.TransformMatrix.GetMatrix();
grfx.FillRectangle(new SolidBrush(Color.FromArgb(Transparency, FillColor)), Rectangle);
grfx.DrawRectangle(new Pen(LineColor, LineWidth), Rectangle.X, Rectangle.Y, Rectangle.Width, Rectangle.Height);
grfx.Transform.Reset();
}
示例7: DrawAppointment
public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners)
{
if (appointment == null)
throw new ArgumentNullException("appointment");
if (g == null)
throw new ArgumentNullException("g");
if (rect.Width != 0 && rect.Height != 0)
using (StringFormat format = new StringFormat())
{
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Near;
if ((appointment.Locked) && isSelected)
{
// Draw back
using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.Color))
g.FillRectangle(m_Brush, rect);
}
else
{
// Draw back
using (SolidBrush m_Brush = new SolidBrush(appointment.Color))
g.FillRectangle(m_Brush, rect);
}
if (isSelected)
{
using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
g.DrawRectangle(m_Pen, rect);
Rectangle m_BorderRectangle = rect;
m_BorderRectangle.Inflate(2, 2);
using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
g.DrawRectangle(m_Pen, m_BorderRectangle);
m_BorderRectangle.Inflate(-4, -4);
using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
g.DrawRectangle(m_Pen, m_BorderRectangle);
}
else
{
// Draw gripper
gripRect.Width += 1;
using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor))
g.FillRectangle(m_Brush, gripRect);
using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
g.DrawRectangle(m_Pen, rect);
}
rect.X += gripRect.Width;
g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format);
}
}
示例8: Measure
public override SizeF Measure(Graphics graphics)
{
if (this.Image != null)
{
SizeF size = new Size(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
if (this.Width.HasValue)
size.Width = Math.Max(size.Width, this.Width.Value);
else
size.Width = Math.Max(size.Width, this.Image.Width);
if (this.Height.HasValue)
size.Height = Math.Max(size.Height, this.Height.Value);
else
size.Height = Math.Max(size.Height, this.Image.Height);
return size;
} else
{
var size = new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
if (this.Width.HasValue)
size.Width = Math.Max(size.Width, this.Width.Value);
if (this.Height.HasValue)
size.Height = Math.Max(size.Height, this.Height.Value);
return size;
}
}
示例9: GetCharacterSize
public virtual Size GetCharacterSize( Graphics g, Font font, CharacterCasing casing )
{
const int MeasureCharCount = 10;
Size charSize = new Size( 0, 0 );
for ( char c = '0'; c <= '9'; ++c )
{
Size newSize = TextRenderer.MeasureText( g, new string( c, MeasureCharCount ), font, new Size( 0, 0 ),
_textFormatFlags );
newSize.Width = (int)Math.Ceiling( (double)newSize.Width / (double)MeasureCharCount );
if ( newSize.Width > charSize.Width )
{
charSize.Width = newSize.Width;
}
if ( newSize.Height > charSize.Height )
{
charSize.Height = newSize.Height;
}
}
return charSize;
}
示例10: DrawBrick
static protected void DrawBrick (Graphics graphics, Brush b1, Brush b2, Brush b3)
{
if (graphics == null) return;
graphics.FillPolygon (b1, brickPoints1);
graphics.FillPolygon (b2, brickPoints2);
graphics.FillPolygon (b3, brickPoints3);
}
示例11: CalcReciprocals
private static SizeF CalcReciprocals(Graphics g)
{
switch(g.PageUnit)
{
case GraphicsUnit.World:
case GraphicsUnit.Pixel:
return new SizeF(1f,1f);
case GraphicsUnit.Inch:
return new SizeF(1f/g.DpiX,1f/g.DpiY);
case GraphicsUnit.Millimeter:
return new SizeF(25.4f/g.DpiX,25.4f/g.DpiY);
case GraphicsUnit.Point:
return new SizeF(72f/g.DpiX,72f/g.DpiY);
case GraphicsUnit.Display:
return new SizeF(75f/g.DpiX,75f/g.DpiY);
case GraphicsUnit.Document:
return new SizeF(300f/g.DpiX,300f/g.DpiY);
}
return new SizeF(10,10);//never gets here...
}
示例12: VisibleSurface
public VisibleSurface(Graphics graphics, int wdth, int hght)
: base(wdth, hght)
{
base.DC = graphics;
base.Buffer = new Backbuffer(this);
this.RedrawDirtyRectangleOnly = true;
}
示例13: Paint
/// <summary>
/// Paints the wrapped IOGraph onto the specified viewport. Does nothing if no
/// IOGraph has been provided.
/// </summary>
public void Paint(Graphics g, Rectangle viewportArea, float zoomFactor)
{
if(null != _graph) {
_layoutManager.Layout(_graph, viewportArea.Size);
_graphPainter.PaintNetwork(_graph, g, viewportArea, zoomFactor);
}
}
示例14: PaintVoxel
void PaintVoxel(Graphics graphics, int i, int j)
{
Brush brushVoxel_True = new SolidBrush(Color.FromArgb(181, 230, 29));
Brush brushVoxel_False = new SolidBrush(Color.FromArgb(240, 240, 240));
graphics.FillRectangle(VoxelsData[i, j] ? brushVoxel_True : brushVoxel_False, VoxelSize * i + 1, VoxelSize * j + 1, VoxelSize - 1, VoxelSize - 1);
}
示例15: Draw
internal override void Draw(Graphics g)
{
IsInvalidated = false;
Rectangle r = BaseElement.GetUnsignedRectangle(new Rectangle(location, size));
Point[] points = new Point[5];
points[0] = new Point(r.X + 0, r.Y + 0);
points[1] = new Point(r.X + 0, r.Y + r.Height);
points[2] = new Point(r.X + r.Width, r.Y + r.Height);
//Fold
points[3] = new Point(r.X + r.Width, r.Y + foldSize.Height);
points[4] = new Point(r.X + r.Width - foldSize.Width, r.Y + 0);
//foreach(Point p in points) p.Offset(location.X, location.Y);
g.FillPolygon(GetBrush(r), points, FillMode.Alternate);
g.DrawPolygon(new Pen(borderColor, borderWidth), points);
g.DrawLine(new Pen(borderColor, borderWidth),
new Point(r.X + r.Width - foldSize.Width, r.Y + foldSize.Height),
new Point(r.X + r.Width, r.Y + foldSize.Height));
g.DrawLine(new Pen(borderColor, borderWidth),
new Point(r.X + r.Width - foldSize.Width, r.Y + 0),
new Point(r.X + r.Width - foldSize.Width, r.Y + 0 + foldSize.Height));
}