本文整理汇总了C#中System.Drawing.Graphics.DrawRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.DrawRectangle方法的具体用法?C# Graphics.DrawRectangle怎么用?C# Graphics.DrawRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.DrawRectangle方法的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: Draw
/// <summary>
/// Draws the Card at its location
/// </summary>
/// <param name="g">The Graphics object to draw on</param>
public override void Draw(Graphics g)
{
Color colour = this.GetColor();
g.FillRectangle(new SolidBrush(colour), _rekt); // Fill
if (Selected)
{
g.DrawRectangle(new Pen(Brushes.Black, 2), _rekt); // Draw outline
}
else
{
g.DrawRectangle(new Pen(Brushes.White, 4), _rekt); // White 4pt
g.DrawRectangle(new Pen(Brushes.Black, 1), _rekt); // Black border 1pt
}
// The number
int fontHeight = _rekt.Height / 4;
Font arial = new Font("Arial", fontHeight, FontStyle.Bold);
// Fancy Centering
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
g.DrawString(this.Value.ToString(), arial, Brushes.Black, _rekt, stringFormat); // Black text (the number)
}
示例3: 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);
}
}
示例4: DrawBackground
protected void DrawBackground(Graphics g, DrawState state)
{
Rectangle rc = ClientRectangle;
// Draw background
if (state == DrawState.Normal || state == DrawState.Disable)
{
g.FillRectangle(new SolidBrush(SystemColors.Control), rc);
using (SolidBrush rcBrush = state == DrawState.Disable ?
new SolidBrush(SystemColors.ControlDark) :
new SolidBrush(SystemColors.ControlDarkDark))
{
// Draw border rectangle
g.DrawRectangle(new Pen(rcBrush), rc.Left, rc.Top, rc.Width - 1, rc.Height - 1);
}
}
else if ( state == DrawState.Hot || state == DrawState.Pressed )
{
// Erase whaterver that was there before
if ( state == DrawState.Hot )
g.FillRectangle(new SolidBrush(ColorUtil.VSNetSelectionColor), rc);
else
g.FillRectangle(new SolidBrush(ColorUtil.VSNetPressedColor), rc);
// Draw border rectangle
g.DrawRectangle(SystemPens.Highlight, rc.Left, rc.Top, rc.Width-1, rc.Height-1);
}
}
示例5: drawnShap
public override void drawnShap(Graphics pe)
{
Brush CurrentBrush = initBrush();
if (this.State.Shift1 == true)
{
calcShift();
//Tính toán lại điểm kết thúc
findSecondPointWhenShift();
pe.DrawRectangle(new Pen(State.CurrentColor, State.LineWidth), State.StartPoint.X, State.StartPoint.Y, State.Width1, State.Width1);
if (State.IsBrushFill)
{
pe.FillRectangle(CurrentBrush, State.StartPoint.X, State.StartPoint.Y, State.Width1, State.Width1);
}
}
else
{
calcHeightWidth();
pe.DrawRectangle(new Pen(State.CurrentColor, State.LineWidth), State.StartPoint.X, State.StartPoint.Y, State.Width1, State.Height1);
if (State.IsBrushFill)
{
pe.FillRectangle(CurrentBrush, State.StartPoint.X, State.StartPoint.Y, State.Width1, State.Height1);
}
}
}
示例6: DrawButtons
/// <summary>
///
/// </summary>
/// <param name="g"></param>
public void DrawButtons(Graphics g)
{
int pad = 20;
int left = pad;
int top = 20;
Pen pen = new Pen(Color.LightGray);
for (int i = Constants.EMPTY; i <= Constants.FINISH; i++)
{
switch (i)
{
case 0:
break;
case 1:
g.FillRectangle(Brushes.White, left + 1, top + 1, 19, 19);
break;
case 2:
pen = new Pen(Color.Green);
break;
case 3:
pen = new Pen(Color.Red);
break;
}
g.DrawRectangle(pen, left, top, 20, 20);
left += pad + 20;
}
g.DrawRectangle(new Pen(Color.LightGray), left, top, 24, 20);
g.DrawString("Go", new Font("Times New Roman", 12), Brushes.White, left + 1, top + 1);
}
示例7: paint
}//end constructor
//call the paint method
public override void paint (Graphics graphics)
{
try
{
//save the old value of the rectangle position
previousLeftPosition = leftPosition;
previousTopPosition = topPosition;
//put this thread to sleep
Thread.Sleep(speed);
//lock thread to prevent thread from running back on itself
lock(typeof(Thread))
{
leftPosition = leftPosition + base.directionX;
topPosition = topPosition + base.directionY;
base.CheckCoordinates();
//grouped the drawing functions together like this to slightly reduce flickering
graphics.DrawRectangle(new System.Drawing.Pen(Color.White), previousLeftPosition, previousTopPosition, width, height);
graphics.DrawRectangle(new System.Drawing.Pen(shapeColor), leftPosition, topPosition, width, height);
}
}
catch
{
//force the thread to end, but only after removing the shape from the screen
graphics.Clear(Color.White);
Thread.CurrentThread.Abort();
}
}//end paint
示例8: Draw
public override void Draw(Graphics graphics)
{
if (graphics == null) return;
#region Panel
graphics.FillRectangle(shadowBrush, 1, 14, 10.5f, 1.5f);
graphics.FillRectangle(shadowBrush, 10, 6, 1.5f, 9);
graphics.FillRectangle(panelBrush, 0, 5, 10, 9);
graphics.DrawRectangle(panelPen, 0, 5, 10, 9);
graphics.FillRectangle(linesBrush, 1.5f, 9, 2, 1);
graphics.FillRectangle(linesBrush, 5, 9, 3, 1);
graphics.FillRectangle(linesBrush, 1.5f, 11, 2, 1);
graphics.FillRectangle(linesBrush, 5, 11, 3, 1);
#endregion
#region Hand
//TODO - improve the hand, choose better colors
graphics.FillPolygon(handBrush, handPoints);
graphics.DrawPolygon(handPen, handPoints);
graphics.DrawLine(handPen, 6, 6, 8, 4);
graphics.DrawLine(handPen, 7, 7, 9.5f, 4.5f);
graphics.DrawLine(handPen, 8, 8, 11, 5);
graphics.FillRectangle(sleeveBrush, 13, 2, 2, 4);
graphics.DrawRectangle(sleevePen, 13, 2, 2, 4);
#endregion
}
示例9: DrawBackground
protected void DrawBackground( Graphics g, DrawState state )
{
Rectangle rc = ClientRectangle;
// Draw background
if( state == DrawState.Normal || state == DrawState.Disable )
{
g.FillRectangle( SystemBrushes.Control, rc );
Pen p = ( state == DrawState.Disable ) ? SystemPens.ControlDark : SystemPens.ControlDarkDark;
// Draw border rectangle
g.DrawRectangle( p, rc.Left, rc.Top, rc.Width-1, rc.Height-1);
}
else if( state == DrawState.Hot || state == DrawState.Pressed )
{
// Erase whaterver that was there before
if ( state == DrawState.Hot )
g.FillRectangle( ColorUtil.VSNetSelectionBrush, rc );
else
g.FillRectangle( ColorUtil.VSNetPressedBrush, rc );
// Draw border rectangle
g.DrawRectangle( SystemPens.Highlight, rc.Left, rc.Top, rc.Width-1, rc.Height-1 );
}
}
示例10: Draw
public override void Draw(Graphics graphics, RenderMode rm) {
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
if (lineVisible) {
graphics.SmoothingMode = SmoothingMode.HighSpeed;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.None;
//draw shadow first
if (shadow) {
int basealpha = 100;
int alpha = basealpha;
int steps = 5;
int currentStep = lineVisible ? 1 : 0;
while (currentStep <= steps) {
using (Pen shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness)) {
Rectangle shadowRect = GuiRectangle.GetGuiRectangle(Left + currentStep, Top + currentStep, Width, Height);
graphics.DrawRectangle(shadowPen, shadowRect);
currentStep++;
alpha = alpha - (basealpha / steps);
}
}
}
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
if (lineThickness > 0) {
using (Pen pen = new Pen(lineColor, lineThickness)) {
graphics.DrawRectangle(pen, rect);
}
}
}
}
示例11: DrawNode
public static void DrawNode( Graphics g, Node node )
{
if( node.Shape == NodeShape.Rectangle )
{
// Background
g.FillRectangle(node.BackBrush,
node.Position.X + node.Box.X, node.Position.Y + node.Box.Y,
node.Box.Width, node.Box.Height);
// Border
if( node.BorderType == NodeBorderType.Single )
{
g.DrawRectangle(node.BorderPen,
node.Position.X + node.Box.X, node.Position.Y + node.Box.Y,
node.Box.Width, node.Box.Height);
}
else if( node.BorderType == NodeBorderType.Double )
{
g.DrawRectangle(node.BorderPen,
node.Position.X + node.Box.X, node.Position.Y + node.Box.Y,
node.Box.Width, node.Box.Height);
float diff = node.BorderPen.Width * 2;
g.DrawRectangle(node.BorderPen,
node.Position.X + node.Box.X + diff, node.Position.Y + node.Box.Y + diff,
node.Box.Width - 2 * diff, node.Box.Height - 2 * diff);
}
}
else
{
// Background
g.FillEllipse(node.BackBrush,
node.Position.X + node.Box.X, node.Position.Y + node.Box.Y,
node.Box.Width, node.Box.Height);
// Border
if( node.BorderType == NodeBorderType.Single )
{
g.DrawEllipse(node.BorderPen,
node.Position.X + node.Box.X, node.Position.Y + node.Box.Y,
node.Box.Width, node.Box.Height);
}
else if( node.BorderType == NodeBorderType.Double )
{
g.DrawEllipse(node.BorderPen,
node.Position.X + node.Box.X, node.Position.Y + node.Box.Y,
node.Box.Width, node.Box.Height);
float diff = node.BorderPen.Width * 2;
g.DrawEllipse(node.BorderPen,
node.Position.X + node.Box.X + diff, node.Position.Y + node.Box.Y + diff,
node.Box.Width - 2 * diff, node.Box.Height - 2 * diff);
}
}
// Label
if( node.LabelText != null )
g.DrawString(node.LabelText, node.LabelFont, node.LabelBrush,
node.Position.X + node.LabelOffset.X, node.Position.Y + node.LabelOffset.Y);
}
示例12: Draw
public override void Draw(Graphics g, float zoom, PointF offset, PointF zoomPosition)
{
var rect = Helpers.NormalizedRect(currentRectangle.Location,
new PointF(currentRectangle.Right, currentRectangle.Bottom));
int x0 = (int) (rect.Left*zoom + offset.X);
int y0 = (int) (rect.Top*zoom + offset.Y);
int x1 = (int) (rect.Width*zoom);
int y1 = (int) (rect.Height*zoom);
if (x1 == 0 || y1 == 0)
return;
using (var pen = new Pen(borderColor))
{
if (ImageViewPort.CastShadow)
{
using (var pen2 = new Pen(Color.FromArgb(64, 0, 0, 0)))
{
pen2.Width = borderSize;
g.DrawRectangle(pen2, x0 + (int) (3*zoom), y0 + (int) (3*zoom), x1, y1);
}
}
pen.Width = borderSize;
g.DrawRectangle(pen, x0, y0, x1, y1);
}
}
示例13: drawSelf
protected override void drawSelf(Graphics g)
{
int yRect = 0;
g.DrawRectangle(new Pen(Color.Black, 1), 0, 0, this.Size.Width - 1, this.Size.Height - 1);
//Vẽ TableName
string nameTable = table.name;
g.DrawRectangle(new Pen(Color.Black, 1), 0, 0, this.Size.Width-1, ShapeSetting.heightPieceShape);
g.FillRectangle(ShapeSetting.brushTableName,new Rectangle(1, 1, this.Size.Width-2, ShapeSetting.heightPieceShape-1));
g.DrawString(nameTable, new Font("Arial", 10), ShapeSetting.brushText, new Rectangle(10, yRect, this.Size.Width-1, ShapeSetting.heightPieceShape));
//Vẽ Attribute
int maxLength = maxLengthText();
foreach (Column c in table.columns)
{
yRect += 20;
string strAttribute = "";
strAttribute += c.Name.PadRight(maxLength);
strAttribute += " " + c.DataType.PadRight(10);
if (c.PrimaryKey)
strAttribute += "(pk)";
if(c.ForeignKey)
strAttribute += "(fk)";
g.DrawString(strAttribute, this.Font, ShapeSetting.brushText, new Rectangle(10, yRect, this.Size.Width - 1, ShapeSetting.heightPieceShape));
}
}
示例14: Draw
public void Draw(Graphics g, Size mapSize)
{
bool drawSquares = false;
var galaxyMap = GalaxyMap.Instance;
var galaxy = galaxyMap.Galaxy;
var faction = galaxy.GetFaction(Planet);
var color = faction != null ? faction.Color : Color.White;
using (var brush = new SolidBrush(color)) {
var x1 = (int)(Position.X*mapSize.Width - PlanetSize/2);
var y1 = (int)(Position.Y*mapSize.Height - PlanetSize/2);
g.FillEllipse(Brushes.Black, x1 - OutlineSize, y1 - OutlineSize, PlanetSize + OutlineSize * 2, PlanetSize + OutlineSize * 2);
g.FillEllipse(brush, x1, y1, PlanetSize, PlanetSize);
if (drawSquares) {
g.SmoothingMode = SmoothingMode.None;
g.InterpolationMode = InterpolationMode.NearestNeighbor;
Faction attackFaction;
var found = galaxyMap.AttackablePlanetIDs.TryGetValue(Planet.ID, out attackFaction);
if (found) {
g.DrawRectangle(new Pen(attackFaction.Color, 3), x1, y1, PlanetSize, PlanetSize);
}
if (galaxyMap.ClaimablePlanetIDs.Contains(Planet.ID)) {
g.DrawRectangle(new Pen(Color.Purple, 3), x1, y1, PlanetSize, PlanetSize);
}
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
}
}
}
示例15: GraphicsIsVisibleRectangleF
public void GraphicsIsVisibleRectangleF(Graphics g)
{
Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));
// Create the first rectangle and draw it to the screen in blue.
g.DrawRectangle(myPen, regionRect1);
g.FillRectangle (myBrush, regionRect1);
// Create the second rectangle and draw it to the screen in red.
myPen.Color = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);
g.DrawRectangle(myPen, Rectangle.Round(regionRectF2));
g.FillRectangle (myBrush, Rectangle.Round (regionRectF2));
// Create a region using the first rectangle.
Region myRegion = new Region(regionRect1);
// Determine if myRect is contained in the region.
bool contained = myRegion.IsVisible(regionRect2);
// Display the result.
Font myFont = new Font("Arial", 8);
SolidBrush txtBrush = new SolidBrush(Color.Black);
g.DrawString("contained = " + contained.ToString(),
myFont,
txtBrush,
new PointF(regionRectF2.Right + 10, regionRectF2.Top));
regionRect1.Y += 120;
regionRectF2.Y += 120;
regionRectF2.X += 41;
myPen.Color = Color.FromArgb (196, 0xC3, 0xC9, 0xCF);
myBrush.Color = Color.FromArgb(127, 0xDD, 0xDD, 0xF0);
// Create the first rectangle and draw it to the screen in blue.
g.DrawRectangle(myPen, regionRect1);
g.FillRectangle (myBrush, regionRect1);
// Create the second rectangle and draw it to the screen in red.
myPen.Color = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);
g.DrawRectangle(myPen, Rectangle.Round(regionRectF2));
g.FillRectangle (myBrush, Rectangle.Round (regionRectF2));
// Create a region using the first rectangle.
myRegion = new Region(regionRect1);
// Determine if myRect is contained in the region.
contained = myRegion.IsVisible(regionRectF2);
// Display the result.
g.DrawString("contained = " + contained.ToString(),
myFont,
txtBrush,
new PointF(regionRectF2.Right + 10, regionRectF2.Top));
}