本文整理汇总了C#中Graphics.FillRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.FillRectangle方法的具体用法?C# Graphics.FillRectangle怎么用?C# Graphics.FillRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graphics
的用法示例。
在下文中一共展示了Graphics.FillRectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillRoundedRectangle
public static void FillRoundedRectangle(Graphics g, Rectangle r, int d, Brush b)
{
// anti alias distorts fill so remove it.
System.Drawing.Drawing2D.SmoothingMode mode = g.SmoothingMode;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
g.FillPie(b, r.X, r.Y, d, d, 180, 90);
g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90);
g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90);
g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
g.FillRectangle(b, r.X + d / 2, r.Y, r.Width - d, d / 2);
g.FillRectangle(b, r.X, r.Y + d / 2, r.Width, r.Height - d);
g.FillRectangle(b, r.X + d / 2, r.Y + r.Height - d / 2, r.Width - d, d / 2);
g.SmoothingMode = mode;
}
示例2: ApplyTextWatermark
protected override void ApplyTextWatermark(ImageProcessingActionExecuteArgs args, Graphics g)
{
// Draw a filled rectangle
int rectangleWidth = 14;
using (Brush brush = new SolidBrush(Color.FromArgb(220, Color.Red)))
{
g.FillRectangle(brush, new Rectangle(args.Image.Size.Width - rectangleWidth, 0, rectangleWidth, args.Image.Size.Height));
}
using (System.Drawing.Drawing2D.Matrix transform = g.Transform)
{
using (StringFormat stringFormat = new StringFormat())
{
// Vertical text (bottom -> top)
stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
transform.RotateAt(180F, new PointF(args.Image.Size.Width / 2, args.Image.Size.Height / 2));
g.Transform = transform;
// Align: top left, +2px displacement
// (because of the matrix transformation we have to use inverted values)
base.ContentAlignment = ContentAlignment.MiddleLeft;
base.ContentDisplacement = new Point(-2, -2);
base.ForeColor = Color.White;
base.Font.Size = 10;
// Draw the string by invoking the base Apply method
base.StringFormat = stringFormat;
base.ApplyTextWatermark(args, g);
base.StringFormat = null;
}
}
}
示例3: PaintDocumentGradientBackground
public static void PaintDocumentGradientBackground(Graphics graphics, Rectangle rectangle)
{
LinearGradientBrush BackgroundBrush = new LinearGradientBrush(rectangle, DefaultGradientUpper, DefaultGradientLower, LinearGradientMode.Vertical);
graphics.Clear(DefaultGradientUpper);
graphics.FillRectangle(BackgroundBrush, rectangle);
BackgroundBrush.Dispose();
}
示例4: OnDrawItem
protected override void OnDrawItem(DrawItemEventArgs e)
{
G = e.Graphics;
Rect = e.Bounds;
using (SolidBrush Back = new SolidBrush(Color.FromArgb(34, 34, 33)))
{
G.FillRectangle(Back, new Rectangle(e.Bounds.X - 4, e.Bounds.Y - 1, e.Bounds.Width + 4, e.Bounds.Height + 1));
}
if (!(e.Index == -1))
{
using (Font ItemsFont = new Font("Segoe UI", 9))
{
using (Pen Border = new Pen(Color.FromArgb(38, 38, 37)))
{
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
using (SolidBrush HoverItemBrush = new SolidBrush(Color.FromArgb(220, 220, 220)))
{
using (SolidBrush HoverItemFill = new SolidBrush(Color.FromArgb(38, 38, 37)))
{
G.FillRectangle(HoverItemFill, new Rectangle(Rect.X - 1, Rect.Y + 2, Rect.Width + 1, Rect.Height - 4));
G.DrawString(GetItemText(Items[e.Index]), new Font("Segoe UI", 9), HoverItemBrush, new Point(Rect.X + 5, Rect.Y + 1));
}
}
}
else
{
using (SolidBrush DefaultItemBrush = new SolidBrush(Color.FromArgb(220, 220, 220)))
{
G.DrawString(GetItemText(Items[e.Index]), new Font("Segoe UI", 9), DefaultItemBrush, new Point(Rect.X + 5, Rect.Y + 1));
}
}
}
}
}
base.OnDrawItem(e);
}
示例5: Gradient
public static void Gradient(Graphics g, Color c1, Color c2, int x, int y, int width, int height)
{
Rectangle R = new Rectangle(x, y, width, height);
using (LinearGradientBrush T = new LinearGradientBrush(R, c1, c2, LinearGradientMode.Vertical))
{
g.FillRectangle(T, R);
}
}
示例6: Blend
public static void Blend(Graphics g, Color c1, Color c2, Color c3, float c, int d, int x, int y, int width, int height)
{
ColorBlend V = new ColorBlend(3);
V.Colors = new Color[] { c1, c2, c3 };
V.Positions = new float[] { 0F, c, 1F };
Rectangle R = new Rectangle(x, y, width, height);
using (LinearGradientBrush T = new LinearGradientBrush(R, c1, c1, (LinearGradientMode)d))
{
T.InterpolationColors = V;
g.FillRectangle(T, R);
}
}
示例7: PaintBackground
public static void PaintBackground(Graphics graphics, Rectangle rectangle, Color colorLight, Color colorDark, Blend blend)
{
LinearGradientBrush BackgroundBrush = new LinearGradientBrush(rectangle, colorLight, colorDark, LinearGradientMode.Vertical);
if (blend != null)
{
BackgroundBrush.Blend = blend;
}
graphics.FillRectangle(BackgroundBrush, rectangle);
BackgroundBrush.Dispose();
}
示例8: drawObject
public static void drawObject(Graphics g, ObjectRec curObject, bool isSelected, float curScale, ImageList objectSprites)
{
//don't render commands
if (curObject.type >= 0xFF00)
return;
var dict = curObject.additionalData;
var myFont = new Font(FontFamily.GenericSansSerif, 6.0f);
int x = curObject.x, y = curObject.y;
int addX = dict["addX"];
int addY = dict["addY"];
int fromFloor = dict["fromFloor"];
/*if (curObject.type < objectSprites.Images.Count)
{
var p1 = new Point((int)(x * curScale) - 8, (int)(y * curScale) - 8);
var p2 = new Point(p1.X + (int)(addX/2 * curScale) - 8, p1.Y + (int)(addY/2 * curScale) - 8);
g.DrawImage(objectSprites.Images[curObject.type], p1);
if (fromFloor == 0)
{
g.DrawImage(objectSprites.Images[curObject.type],p2);
g.DrawLine(new Pen(Brushes.Red), p1, p2);
}
}
else*/
{
var p1 = new Point((int)(x * curScale) - 8, (int)(y * curScale) - 8);
g.FillRectangle(Brushes.Black, new Rectangle(p1, new Size(16, 16)));
g.DrawString(curObject.type.ToString("X3"), myFont, Brushes.White, p1);
if (fromFloor == 0)
{
var p2 = new Point(p1.X + (int)(addX/2 * curScale) - 8, p1.Y + (int)(addY/2 * curScale) - 8);
g.FillRectangle(Brushes.Green, new Rectangle(p2, new Size(16, 16)));
g.DrawString(curObject.type.ToString("X3"), myFont, Brushes.White, p2);
g.DrawLine(new Pen(Brushes.Red), p1, p2);
}
}
if (isSelected)
g.DrawRectangle(new Pen(Brushes.Red, 2.0f), new Rectangle((int)(x * curScale) - 8, (int)(y * curScale) - 8, 16, 16));
}
示例9: paint
public void paint(Graphics g)
{
int Xpos = (int)(xpos*TuioDemo.width);
int Ypos = (int)(ypos*TuioDemo.height);
int size = TuioDemo.height/10;
g.TranslateTransform(Xpos,Ypos);
g.RotateTransform((float)(angle/Math.PI*180.0f));
g.TranslateTransform(-1*Xpos,-1*Ypos);
g.FillRectangle(black, new Rectangle(Xpos-size/2,Ypos-size/2,size,size));
g.TranslateTransform(Xpos,Ypos);
g.RotateTransform(-1*(float)(angle/Math.PI*180.0f));
g.TranslateTransform(-1*Xpos,-1*Ypos);
Font font = new Font("Arial", 10.0f);
g.DrawString(symbol_id+"",font, white, new PointF(Xpos-10,Ypos-10));
}
示例10: DrawBar
private void DrawBar(Graphics objGraphics,
int Value, int BarNumber, string Label)
{
int intLeft = (BarNumber*75)+60;
int intBottom = 275;
int intHeight = (25*Value);
//绘制柱面
objGraphics.FillRectangle(Brushes.Red,intLeft,
intBottom-intHeight,35,intHeight);
//使用GraphicsPath方法绘制柱面顶层
GraphicsPath pthTop = new GraphicsPath();
pthTop.AddLine(intLeft-1, intBottom-intHeight,
intLeft+20, intBottom-intHeight-10);
pthTop.AddLine(intLeft+55,intBottom-
intHeight-10,intLeft+35,
intBottom-intHeight);
objGraphics.FillPath(Brushes.LightSalmon,
pthTop);
// 绘制柱面左侧
GraphicsPath pthRight = new GraphicsPath();
pthRight.AddLine(intLeft+35,intBottom-
intHeight,intLeft+55,intBottom-
intHeight-10);
pthRight.AddLine(intLeft+55,
intBottom-15,intLeft+35,intBottom);
objGraphics.FillPath(Brushes.Firebrick,
pthRight);
//绘制标签
objGraphics.TranslateTransform(intLeft+15,
intBottom-intHeight - 30);
objGraphics.RotateTransform(300);
objGraphics.DrawString(Label,new
Font("Arial",10,FontStyle.Bold),
Brushes.Black,0,0);
objGraphics.ResetTransform();
}
示例11: Paint
protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates cellState, object value, object formattedValue,
string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
int progressVal = 0;
if (value != null)
progressVal = (int)value;
float percentage = (progressVal / 100.0f);
// Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%.
Brush backColorBrush = new SolidBrush(cellStyle.BackColor);
Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);
// Draws the cell grid
base.Paint(g, clipBounds, cellBounds,
rowIndex, cellState, value, formattedValue, errorText,
cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));
if (percentage > 0.0)
{
// Draw the progress bar and the text
g.FillRectangle(new SolidBrush(Color.FromArgb(163, 189, 242)), cellBounds.X + 2, cellBounds.Y + 2,
Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4);
g.DrawString(progressVal + "%", cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2);
}
else
{
// draw the text
if (DataGridView.CurrentRow.Index == rowIndex)
g.DrawString(progressVal + "%", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), cellBounds.X + 6,
cellBounds.Y + 2);
else
g.DrawString(progressVal + "%", cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2);
}
}
示例12: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
G = e.Graphics;
G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
G.Clear(Color.FromArgb(50, 50, 50));
G.SmoothingMode = SmoothingMode.AntiAlias;
ItemHeight = ItemSize.Height + 2;
GP1 = ThemeModule.CreateRound(0, 0, ItemHeight + 3, Height - 1, 7);
GP2 = ThemeModule.CreateRound(1, 1, ItemHeight + 3, Height - 3, 7);
PB1 = new PathGradientBrush(GP1);
PB1.CenterColor = Color.FromArgb(50, 50, 50);
PB1.SurroundColors = new Color[] { Color.FromArgb(45, 45, 45) };
PB1.FocusScales = new PointF(0.8f, 0.95f);
G.FillPath(PB1, GP1);
G.DrawPath(P1, GP1);
G.DrawPath(P2, GP2);
for (int I = 0; I <= TabCount - 1; I++)
{
R1 = GetTabRect(I);
R1.Y += 2;
R1.Height -= 3;
R1.Width += 1;
R1.X -= 1;
TP1 = TabPages[I];
Offset = 0;
if (SelectedIndex == I)
{
G.FillRectangle(B1, R1);
for (int J = 0; J <= 1; J++)
{
G.FillRectangle(B2, R1.X + 5 + (J * 5), R1.Y + 6, 2, R1.Height - 9);
G.SmoothingMode = SmoothingMode.None;
G.FillRectangle(B3, R1.X + 5 + (J * 5), R1.Y + 5, 2, R1.Height - 9);
G.SmoothingMode = SmoothingMode.AntiAlias;
Offset += 5;
}
G.DrawRectangle(P3, R1.X + 1, R1.Y - 1, R1.Width, R1.Height + 2);
G.DrawRectangle(P1, R1.X + 1, R1.Y + 1, R1.Width - 2, R1.Height - 2);
G.DrawRectangle(P2, R1);
}
else {
for (int J = 0; J <= 1; J++)
{
G.FillRectangle(B2, R1.X + 5 + (J * 5), R1.Y + 6, 2, R1.Height - 9);
G.SmoothingMode = SmoothingMode.None;
G.FillRectangle(B4, R1.X + 5 + (J * 5), R1.Y + 5, 2, R1.Height - 9);
G.SmoothingMode = SmoothingMode.AntiAlias;
Offset += 5;
}
}
R1.X += 5 + Offset;
R2 = R1;
R2.Y += 1;
R2.X += 1;
G.DrawString(TP1.Text, Font, Brushes.Black, R2, SF1);
G.DrawString(TP1.Text, Font, Brushes.White, R1, SF1);
}
GP3 = ThemeModule.CreateRound(ItemHeight, 0, Width - ItemHeight - 1, Height - 1, 7);
GP4 = ThemeModule.CreateRound(ItemHeight + 1, 1, Width - ItemHeight - 3, Height - 3, 7);
G.DrawPath(P2, GP3);
G.DrawPath(P1, GP4);
}
示例13: PaintBackground
/// <summary>
/// Paints the background of the box
/// </summary>
/// <param name="g"></param>
private void PaintBackground(Graphics g, RectangleF rectangle)
{
//HACK: Background rectangles are being deactivated when justifying text.
if (ContainingBlock.TextAlign == CssConstants.Justify) return;
GraphicsPath roundrect = null;
Brush b = null;
SmoothingMode smooth = g.SmoothingMode;
if (IsRounded)
{
roundrect = CssDrawingHelper.GetRoundRect(rectangle, ActualCornerNW, ActualCornerNE, ActualCornerSE, ActualCornerSW);
}
if (BackgroundGradient != CssConstants.None && rectangle.Width > 0 && rectangle.Height > 0)
{
b = new LinearGradientBrush(rectangle, ActualBackgroundColor, ActualBackgroundGradient, ActualBackgroundGradientAngle);
}
else
{
b = new SolidBrush(ActualBackgroundColor);
}
if (InitialContainer != null && !InitialContainer.AvoidGeometryAntialias && IsRounded)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
}
if (roundrect != null)
{
g.FillPath(b, roundrect);
}
else
{
g.FillRectangle(b, rectangle);
}
g.SmoothingMode = smooth;
if (roundrect != null) roundrect.Dispose();
if (b != null) b.Dispose();
}
示例14: DrawHeader
// The funtion that print the title, page number, and the header row
private void DrawHeader(Graphics g) {
CurrentY = (float)TopMargin;
// Printing the page number (if isWithPaging is set to true)
if(IsWithPaging) {
PageNumber++;
string PageString = "Page " + PageNumber.ToString();
StringFormat PageStringFormat = new StringFormat();
PageStringFormat.Trimming = StringTrimming.Word;
PageStringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
PageStringFormat.Alignment = StringAlignment.Far;
Font PageStringFont = new Font("Tahoma",8,FontStyle.Regular,GraphicsUnit.Point);
RectangleF PageStringRectangle = new RectangleF((float)LeftMargin,CurrentY,(float)PageWidth - (float)RightMargin - (float)LeftMargin,g.MeasureString(PageString,PageStringFont).Height);
g.DrawString(PageString,PageStringFont,new SolidBrush(Color.Black),PageStringRectangle,PageStringFormat);
CurrentY += g.MeasureString(PageString,PageStringFont).Height;
}
// Printing the title (if IsWithTitle is set to true)
if(IsWithTitle) {
StringFormat TitleFormat = new StringFormat();
TitleFormat.Trimming = StringTrimming.Word;
TitleFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
if(IsCenterOnPage){
TitleFormat.Alignment = StringAlignment.Center;
}
else{
TitleFormat.Alignment = StringAlignment.Near;
}
RectangleF TitleRectangle = new RectangleF((float)LeftMargin,CurrentY,(float)PageWidth - (float)RightMargin - (float)LeftMargin,g.MeasureString(TheTitleText,TheTitleFont).Height);
g.DrawString(TheTitleText,TheTitleFont,new SolidBrush(TheTitleColor),TitleRectangle,TitleFormat);
CurrentY += g.MeasureString(TheTitleText,TheTitleFont).Height;
}
// Calculating the starting x coordinate that the printing process will start from
float CurrentX = (float)LeftMargin;
if(IsCenterOnPage){
CurrentX += (((float)PageWidth - (float)RightMargin - (float)LeftMargin) - mColumnPointsWidth[mColumnPoint]) / 2.0F;
}
// Setting the HeaderFore style
Color HeaderForeColor = TheDataGridView.ColumnHeadersDefaultCellStyle.ForeColor;
if(HeaderForeColor.IsEmpty){ // If there is no special HeaderFore style, then use the default DataGridView style
HeaderForeColor = TheDataGridView.DefaultCellStyle.ForeColor;
}
SolidBrush HeaderForeBrush = new SolidBrush(HeaderForeColor);
// Setting the HeaderBack style
Color HeaderBackColor = TheDataGridView.ColumnHeadersDefaultCellStyle.BackColor;
if(HeaderBackColor.IsEmpty){ // If there is no special HeaderBack style, then use the default DataGridView style
HeaderBackColor = TheDataGridView.DefaultCellStyle.BackColor;
}
SolidBrush HeaderBackBrush = new SolidBrush(HeaderBackColor);
// Setting the LinePen that will be used to draw lines and rectangles (derived from the GridColor property of the DataGridView control)
Pen TheLinePen = new Pen(TheDataGridView.GridColor,1);
// Setting the HeaderFont style
Font HeaderFont = TheDataGridView.ColumnHeadersDefaultCellStyle.Font;
if(HeaderFont == null){ // If there is no special HeaderFont style, then use the default DataGridView font style
HeaderFont = TheDataGridView.DefaultCellStyle.Font;
}
// Calculating and drawing the HeaderBounds
RectangleF HeaderBounds = new RectangleF(CurrentX,CurrentY,mColumnPointsWidth[mColumnPoint],RowHeaderHeight);
g.FillRectangle(HeaderBackBrush,HeaderBounds);
// Setting the format that will be used to print each cell of the header row
StringFormat CellFormat = new StringFormat();
CellFormat.Trimming = StringTrimming.Word;
CellFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
// Printing each visible cell of the header row
RectangleF CellBounds;
float ColumnWidth;
for(int i = (int)mColumnPoints[mColumnPoint].GetValue(0);i < (int)mColumnPoints[mColumnPoint].GetValue(1);i++) {
if(!TheDataGridView.Columns[i].Visible) continue; // If the column is not visible then ignore this iteration
ColumnWidth = ColumnsWidth[i];
// Check the CurrentCell alignment and apply it to the CellFormat
if(TheDataGridView.ColumnHeadersDefaultCellStyle.Alignment.ToString().Contains("Right"))
CellFormat.Alignment = StringAlignment.Far;
else if(TheDataGridView.ColumnHeadersDefaultCellStyle.Alignment.ToString().Contains("Center"))
CellFormat.Alignment = StringAlignment.Center;
else
CellFormat.Alignment = StringAlignment.Near;
CellBounds = new RectangleF(CurrentX,CurrentY,ColumnWidth,RowHeaderHeight);
// Printing the cell text
g.DrawString(TheDataGridView.Columns[i].HeaderText,HeaderFont,HeaderForeBrush,CellBounds,CellFormat);
// Drawing the cell bounds
if(TheDataGridView.RowHeadersBorderStyle != DataGridViewHeaderBorderStyle.None) // Draw the cell border only if the HeaderBorderStyle is not None
g.DrawRectangle(TheLinePen,CurrentX,CurrentY,ColumnWidth,RowHeaderHeight);
CurrentX += ColumnWidth;
}
CurrentY += RowHeaderHeight;
}
示例15: DrawBar
// ===================================================================
private void DrawBar(Rectangle rect, Line line, ref Graphics g)
{
SolidBrush barBrush = new SolidBrush(line.m_Color);
g.FillRectangle(barBrush, rect);
barBrush.Dispose();
}