本文整理汇总了C#中System.Windows.Media.DrawingContext.DrawRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# DrawingContext.DrawRectangle方法的具体用法?C# DrawingContext.DrawRectangle怎么用?C# DrawingContext.DrawRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.DrawingContext
的用法示例。
在下文中一共展示了DrawingContext.DrawRectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBitmap
public void CreateBitmap()
{
int width = 100;
int height = 100;
int dpi = 96;
Tracing.Log(">> CreateBitmap");
var thread = new Thread(new ThreadStart(() =>
{
Tracing.Log(">> CreateBitmap - Thread start; creating drawing visual");
//Dispatcher.Invoke(new Action(() => {
_drawingVisual = new DrawingVisual();
_drawingContext = _drawingVisual.RenderOpen();
//}));
Tracing.Log(">> CreateBitmap - Drawing to context");
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.HotPink), new Pen(), new Rect(0, 0, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.Blue), new Pen(), new Rect(50, 0, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.Orange), new Pen(), new Rect(0, 50, 50, 50));
_drawingContext.DrawRectangle(new SolidColorBrush(Colors.DarkRed), new Pen(), new Rect(50, 50, 50, 50));
_drawingContext.Close();
Tracing.Log(">> CreateBitmap - Finished drawing; creating render target bitmap");
_bitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
_bitmap.Render(_drawingVisual);
Tracing.Log(">> CreateBitmap - Finished work");
_bitmap.Freeze();
}));
//thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
示例2: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
Size renderSize = this.RenderSize;
TextView textView = this.TextView;
if (textView != null && textView.VisualLinesValid) {
foreach (VisualLine line in textView.VisualLines) {
Rect rect = new Rect(0, line.VisualTop - textView.ScrollOffset.Y, 5, line.Height);
LineChangeInfo info = changeWatcher.GetChange(line.FirstDocumentLine.LineNumber);
switch (info.Change) {
case ChangeType.None:
break;
case ChangeType.Added:
drawingContext.DrawRectangle(Brushes.LightGreen, null, rect);
break;
case ChangeType.Deleted:
case ChangeType.Modified:
drawingContext.DrawRectangle(Brushes.LightBlue, null, rect);
break;
case ChangeType.Unsaved:
drawingContext.DrawRectangle(Brushes.Yellow, null, rect);
break;
default:
throw new Exception("Invalid value for ChangeType");
}
}
}
}
示例3: RenderClippedEdges
private static void RenderClippedEdges(Skeleton skeleton, DrawingContext drawingContext)
{
if (skeleton.ClippedEdges.HasFlag(FrameEdges.Bottom))
{
drawingContext.DrawRectangle(
Brushes.Red,
null,
new Rect(0, RenderHeight - ClipBoundsThickness, RenderWidth, ClipBoundsThickness));
}
if (skeleton.ClippedEdges.HasFlag(FrameEdges.Top))
{
drawingContext.DrawRectangle(
Brushes.Red,
null,
new Rect(0, 0, RenderWidth, ClipBoundsThickness));
}
if (skeleton.ClippedEdges.HasFlag(FrameEdges.Left))
{
drawingContext.DrawRectangle(
Brushes.Red,
null,
new Rect(0, 0, ClipBoundsThickness, RenderHeight));
}
if (skeleton.ClippedEdges.HasFlag(FrameEdges.Right))
{
drawingContext.DrawRectangle(
Brushes.Red,
null,
new Rect(RenderWidth - ClipBoundsThickness, 0, ClipBoundsThickness, RenderHeight));
}
}
示例4: DrawChanges
private void DrawChanges(DrawingContext drawingContext, NormalizedSnapshotSpanCollection changes, Brush brush)
{
if (changes.Count > 0)
{
double yTop = Math.Floor(_scrollBar.GetYCoordinateOfBufferPosition(changes[0].Start)) + markerStartOffset;
double yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(changes[0].End)) + markerEndOffset;
for (int i = 1; i < changes.Count; ++i)
{
double y = _scrollBar.GetYCoordinateOfBufferPosition(changes[i].Start) + markerStartOffset;
if (yBottom < y)
{
drawingContext.DrawRectangle(
brush,
null,
new Rect(0, yTop, markerWidth, yBottom - yTop));
yTop = y;
}
yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(changes[i].End)) + markerEndOffset;
}
drawingContext.DrawRectangle(
brush,
null,
new Rect(0, yTop, markerWidth, yBottom - yTop));
}
}
示例5: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
Rect rect = new Rect(startPoint, endPoint);
rect.Offset(-0.5d, -0.5d);
drawingContext.DrawRectangle(fill, stroke, rect);
}
示例6: DrawTile
protected override void DrawTile(DrawingContext dc, Rect TileRect)
{
if (!_tileImage.IsReady)
dc.DrawRectangle(Brushes.LemonChiffon, null, TileRect);
else
dc.DrawImage(_tileImage.Image, TileRect);
}
示例7: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
Rect rect = new Rect(-1, -1, this.ActualWidth + 2.0, this.ActualHeight + 2.0);
drawingContext.DrawRectangle(Background, null, rect);
rect = new Rect(1.0, 1.0, this.ActualWidth + 2.0, this.ActualHeight + 2.0);
drawingContext.DrawRectangle(Shadow, null, rect);
}
示例8: OnRender
protected override void OnRender(DrawingContext dc)
{
base.OnRender(dc);
dc.DrawRectangle(Brushes.Transparent, null, new Rect(RenderSize));
if (this.startPoint.HasValue && this.endPoint.HasValue)
dc.DrawRectangle(Brushes.Transparent, rubberbandPen, new Rect(this.startPoint.Value, this.endPoint.Value));
}
示例9: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
ScreenReplicator replicator = Visual as ScreenReplicator;
if (replicator != null)
{
if (replicator.IsRunning)
{
if (replicator.IsReplicating)
{
_screenBrush = CreateImageBrush(replicator);
}
else if (replicator.BlankOnStop)
{
_screenBrush = null;
}
if (_screenBrush != null)
{
drawingContext.DrawRectangle(_screenBrush, null, _displayRect);
}
}
else
{
drawingContext.DrawRectangle(null, _inactivePen, _displayRect);
_inactiveTextFormat.RenderText(drawingContext, _inactiveBrush, "Screen Replicator", _displayRect);
}
}
}
示例10: OnRender
protected override void OnRender(DrawingContext dc)
{
var inColumns = PointsInColumn();
var inRows = PointsInRow();
var noOfPoints = inColumns*inRows;
int finishedPoints = (int) (Progress*noOfPoints);
int currentPoint = 0;
for (int rowIndex = 0; rowIndex < inRows; rowIndex++)
{
for (int columnIndex = 0; columnIndex < inColumns; columnIndex++)
{
currentPoint++;
var point = new Point((columnIndex + 1)*Spacing + columnIndex*PointSize, Spacing * (rowIndex+1) + rowIndex*PointSize);
if (currentPoint > finishedPoints)
{
dc.DrawRectangle(PendingBrush, null, new Rect(point, new Size(PointSize, PointSize)));
}
else
{
dc.DrawRectangle(FinishedBrush, null, new Rect(point, new Size(PointSize, PointSize)));
}
}
}
}
示例11: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
var torrent = DataContext as PeriodicTorrent;
if (torrent == null)
{
drawingContext.DrawRectangle(null, new Pen(Brushes.DarkGray, 1), new Rect(0, 0, this.ActualWidth, this.ActualHeight));
return;
}
var pieces = torrent.RecievedPieces;
if (pieces == null)
{
drawingContext.DrawRectangle(null, new Pen(Brushes.DarkGray, 1), new Rect(0, 0, this.ActualWidth, this.ActualHeight));
return;
}
double width = ActualWidth / pieces.Length;
int increment = (int)(1 / width);
if (increment == 0) increment = 1;
for (int i = 0; i < pieces.Length; i += increment)
{
if (pieces[i])
{
drawingContext.DrawRectangle(Brushes.LightGreen, null,
new Rect(Math.Ceiling(i * width), 0, Math.Ceiling(width), ActualHeight));
}
else
drawingContext.DrawRectangle(Background, null,
new Rect(Math.Ceiling(i * width), 0, Math.Ceiling(width), ActualHeight));
}
drawingContext.DrawRectangle(null, new Pen(Brushes.DarkGray, 1), new Rect(0, 0, this.ActualWidth, this.ActualHeight));
base.OnRender(drawingContext);
}
示例12: DrawConnectionPoint
static void DrawConnectionPoint(ConnectionPoint connPoint, Point actualLocation, Brush renderBrush, Pen renderPen, DrawingContext drawingContext)
{
// actualLocation is the point on the Edge with respect to the coordinate system defined by the top left corner of the adorned element
// We will need this transparent rectangle to make sure OnMouseOver event can be triggered, for hit test.
drawingContext.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Transparent, 0),
new Rect(actualLocation + connPoint.HitTestOffset, connPoint.HitTestSize));
drawingContext.DrawRectangle(renderBrush, renderPen,
new Rect(actualLocation + connPoint.DrawingOffset, connPoint.DrawingSize));
}
示例13: RedrawDots
public static void RedrawDots(DrawingContext dc, ICollection<IP> dots, Rectangle rect, ShapeType t = ShapeType.Default)
{
if (!IsDrawEnabled) return;
foreach (var p in dots.Where(p => p != null))
{
dc.DrawRectangle(Pens.BackgroundColor, null, GetShape(p, rect, t));
dc.DrawRectangle(GetColor(p, ShapeType.Default), null, GetShape(p, rect, ShapeType.Default));
}
}
示例14: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.DrawRectangle(Brushes.Red, new Pen(), new Rect(5, _playerPaddlePos - 20, 10, 40));
drawingContext.DrawRectangle(Brushes.Red, new Pen(),
new Rect(RenderSize.Width - 7.5, _computerPaddlePos - 20, 10, 40));
drawingContext.DrawEllipse(Brushes.WhiteSmoke, new Pen(), _ballPos, 5, 5);
drawingContext.DrawText(
new FormattedText(String.Format("{0} - {1}", _playerScore, _computerScore), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Courier New"), 12, Brushes.White), new Point(RenderSize.Width / 2, 10));
base.OnRender(drawingContext);
}
示例15: PaintBackground
public static void PaintBackground(this Altaxo.Worksheet.ColumnStyle thiss, DrawingContext dc, RectangleD2D cellRectangle, bool bSelected)
{
var cellRect = cellRectangle.ToWpf();
if (bSelected)
dc.DrawRectangle(thiss.DefaultSelectedBackgroundBrush.ToWpf(), null, cellRect);
else
dc.DrawRectangle(thiss.BackgroundBrush.ToWpf(), null, cellRect);
dc.DrawLine(thiss.CellBorder.ToWpf(), cellRect.BottomLeft, cellRect.BottomRight);
dc.DrawLine(thiss.CellBorder.ToWpf(), cellRect.BottomRight, cellRect.TopRight);
}