本文整理汇总了C#中System.Drawing.Brush.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Brush.Dispose方法的具体用法?C# Brush.Dispose怎么用?C# Brush.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Brush
的用法示例。
在下文中一共展示了Brush.Dispose方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReCreateBrush
private static void ReCreateBrush(ref Brush brush, Color color)
{
if (brush != null)
brush.Dispose();
brush = new SolidBrush(color);
}
示例2: OnPaint
protected override void OnPaint(PaintEventArgs pe)
{
this.brBack = new SolidBrush(BackColor);
this.brCode = new SolidBrush(Color.Pink);
this.brData = new SolidBrush(Color.LightBlue);
try
{
Rectangle rcBody = CalculateLayout();
RenderSelectionBar(pe.Graphics);
RenderScrollControls(pe.Graphics, rcBody);
RenderBody(pe.Graphics, rcBody);
}
finally
{
brData.Dispose();
brCode.Dispose();
brBack.Dispose();
}
}
示例3: CacheBrush
private Brush CacheBrush(ref Brush brInstance, Brush brNew)
{
if (brInstance != null)
brInstance.Dispose();
brInstance = brNew;
return brNew;
}
示例4: DisposeBrush
// Dispose of a brush
public static void DisposeBrush(Brush brush)
{
#if true
brush.Dispose();
#endif
}
示例5: DrawString
void DrawString(Graphics g, Font font, Brush brush, string s, int x, int y)
{
foreach (char ch in s)
{
g.DrawString(ch.ToString(), font, brush, x, y);
x += _charWidth;
}
brush.Dispose();
}
示例6: FillPoint
/// <summary>
/// Render the filled <see cref="Symbol"/> to the specified <see cref="Graphics"/>
/// device at the specified location.
/// </summary>
/// <param name="g">
/// A graphic device object to be drawn into. This is normally e.Graphics from the
/// PaintEventArgs argument to the Paint() method.
/// </param>
/// <param name="x">The x position of the center of the symbol in
/// pixel units</param>
/// <param name="y">The y position of the center of the symbol in
/// pixel units</param>
/// <param name="scaleFactor">
/// The scaling factor for the features of the graph based on the <see cref="GraphPane.BaseDimension"/>. This
/// scaling factor is calculated by the <see cref="GraphPane.CalcScaleFactor"/> method. The scale factor
/// represents a linear multiple to be applied to font sizes, symbol sizes, etc.
/// </param>
/// <param name="pen">A pen with attributes of <see cref="Color"/> and
/// <see cref="ZedGraph.Border.PenWidth"/> for this symbol</param>
/// <param name="brush">A brush with the <see cref="Color"/> attribute
/// for this symbol</param>
public void FillPoint( Graphics g, float x, float y, double scaleFactor,
Pen pen, Brush brush )
{
float scaledSize = (float) ( this.size * scaleFactor ),
hsize = scaledSize / 2,
hsize4 = scaledSize / 3,
hsize41 = hsize4 + 1,
hsize1 = hsize + 1;
PointF[] polyPt = new PointF[5];
RectangleF rect = new RectangleF( x-hsize, y-hsize, scaledSize, scaledSize );
if ( this.fill.Type == FillType.Brush )
brush = this.fill.MakeBrush( rect );
switch( this.type == SymbolType.Default ? Default.Type : this.type )
{
case SymbolType.Square:
g.FillRectangle( brush, rect );
break;
case SymbolType.Diamond:
polyPt[0].X = x;
polyPt[0].Y = y-hsize;
polyPt[1].X = x+hsize;
polyPt[1].Y = y;
polyPt[2].X = x;
polyPt[2].Y = y+hsize;
polyPt[3].X = x-hsize;
polyPt[3].Y = y;
polyPt[4] = polyPt[0];
g.FillPolygon( brush, polyPt );
break;
case SymbolType.Triangle:
polyPt[0].X = x;
polyPt[0].Y = y-hsize;
polyPt[1].X = x+hsize;
polyPt[1].Y = y+hsize;
polyPt[2].X = x-hsize;
polyPt[2].Y = y+hsize;
polyPt[3] = polyPt[0];
g.FillPolygon( brush, polyPt );
break;
case SymbolType.Circle:
g.FillEllipse( brush, rect );
break;
case SymbolType.XCross:
g.FillRectangle( brush, x-hsize4, y-hsize4,
hsize4+hsize41, hsize4+hsize41 );
g.DrawLine( pen, x-hsize, y-hsize, x+hsize1, y+hsize1 );
g.DrawLine( pen, x+hsize, y-hsize, x-hsize1, y+hsize1 );
break;
case SymbolType.Plus:
g.FillRectangle( brush, x-hsize4, y-hsize4,
hsize4+hsize41, hsize4+hsize41 );
g.DrawLine( pen, x, y-hsize, x, y+hsize1 );
g.DrawLine( pen, x-hsize, y, x+hsize1, y );
break;
case SymbolType.Star:
g.FillRectangle( brush, x-hsize4, y-hsize4,
hsize4+hsize41, hsize4+hsize41 );
g.DrawLine( pen, x, y-hsize, x, y+hsize1 );
g.DrawLine( pen, x-hsize, y, x+hsize1, y );
g.DrawLine( pen, x-hsize, y-hsize, x+hsize1, y+hsize1 );
g.DrawLine( pen, x+hsize, y-hsize, x-hsize1, y+hsize1 );
break;
case SymbolType.TriangleDown:
polyPt[0].X = x;
polyPt[0].Y = y+hsize;
polyPt[1].X = x+hsize;
polyPt[1].Y = y-hsize;
polyPt[2].X = x-hsize;
polyPt[2].Y = y-hsize;
polyPt[3] = polyPt[0];
g.FillPolygon( brush, polyPt );
break;
}
if ( this.fill.Type == FillType.Brush )
brush.Dispose();
}
示例7: OnPaint
/// <summary>
/// 重绘控件
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (BackImg == null)
{
base.OnPaint(e);
return;
}
int i = (int)state;
if (this.Focused && state != State.MouseDown && _IsTabFocus==true) i = 5;
if (!this.Enabled) i = 4;
Rectangle rc = this.ClientRectangle;
Graphics g = e.Graphics;
base.InvokePaintBackground(this, new PaintEventArgs(e.Graphics, base.ClientRectangle));
try
{
if (BackImg != null)
{
if (_BacklightLTRB !=Rectangle.Empty)
{
ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(_BacklightLTRB.X, _BacklightLTRB.Y, _BacklightLTRB.Width, _BacklightLTRB.Height),i,5);
}
else
{
ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(10, 10, 10, 10), i, 5);
}
}
}
catch
{ }
Image img = null;
Size txts, imgs;
txts = Size.Empty;
imgs = Size.Empty;
if (this.Image != null)
{
img = this.Image;
}
else if (this.ImageList != null && this.ImageIndex != -1)
{
img = this.ImageList.Images[this.ImageIndex];
}
if (img != null)
{
imgs.Width = img.Width;
imgs.Height = img.Height;
}
StringFormat format1;
using (format1 = new StringFormat())
{
format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
SizeF ef1 = g.MeasureString(this.Text, this.Font, new SizeF((float)rc.Width, (float)rc.Height), format1);
txts = Size.Ceiling(ef1);
}
rc.Inflate(-4, -4);
if (imgs.Width * imgs.Height != 0)
{
Rectangle imgr = rc;
imgr = AlClass.ImageDrawRect.HAlignWithin(imgs, imgr, this.ImageAlign);
imgr = AlClass.ImageDrawRect.VAlignWithin(imgs, imgr, this.ImageAlign);
if (!this.Enabled)
{
ControlPaint.DrawImageDisabled(g, img, imgr.Left, imgr.Top, this.BackColor);
}
else
{
g.DrawImage(img, imgr.Left, imgr.Top, img.Width, img.Height);
}
}
Rectangle txtr = rc;
txtr = AlClass.ImageDrawRect.HAlignWithin(txts, txtr, this.TextAlign);
txtr = AlClass.ImageDrawRect.VAlignWithin(txts, txtr, this.TextAlign);
format1 = new StringFormat();
format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
if (this.RightToLeft == RightToLeft.Yes)
{
format1.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
}
brush = new SolidBrush(this.ForeColor);
g.DrawString(this.Text, this.Font, brush, (RectangleF)txtr, format1);
brush.Dispose();
}
示例8:
DisposeBrush
(
ref Brush oBrush
)
{
if (oBrush != null)
{
oBrush.Dispose();
oBrush = null;
}
}
示例9: OnPaint
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
Graphics g = pevent.Graphics;
_paintBrush = new LinearGradientBrush(this.ClientRectangle, this.StartColor, this.EndColor, lgm);
g.FillRectangle(_paintBrush, this.ClientRectangle);
_paintBrush = new SolidBrush(this.ForeColor);
SizeF size = pevent.Graphics.MeasureString(Text, Font);
PointF pt = new PointF((Width - size.Width) / 2, (Height - size.Height) / 2);
if (clicked)
{
pt.X += 2;
pt.Y += 2;
}
pevent.Graphics.DrawString(Text, Font, _paintBrush, pt);
_paintBrush.Dispose();
// this._centerPoint = new PointF(this.Width / 2, this.Height / 2);
//g.DrawString(this.Text, this.Font, _paintBrush, _centerPoint.X, _centerPoint.Y - 5, _sf);
//paint_Border(pevent);
}
示例10: CleanBrush
private static void CleanBrush(ref Brush brush, Color color)
{
if (brush != null)
{
if (!color.IsSystemColor)
{
brush.Dispose();
brush = null;
}
}
}
示例11: DisposeBrush
//*************************************************************************
// Method: DisposeBrush()
//
/// <summary>
/// Disposes of a brush.
/// </summary>
///
/// <param name="oBrush">
/// Brush to dispose. Can be null. Gets set to null.
/// </param>
///
/// <remarks>
/// If <paramref name="oBrush" /> isn't null, this method calls the Dispose
/// method on <paramref name="oBrush" />, then sets it to null.
/// </remarks>
//*************************************************************************
public static void DisposeBrush(
ref Brush oBrush
)
{
if (oBrush != null)
{
oBrush.Dispose();
oBrush = null;
}
}
示例12: DrawBackground
internal static void DrawBackground(Graphics g, RectangleF rect, Brush fillBrush, CornerShape bShape,
int cornerRadius, Region excRegion)
{
if (excRegion != null)
{
g.ExcludeClip(excRegion);
}
var path = GetDrawingPath(rect, bShape, cornerRadius);
g.FillPath(fillBrush, path);
fillBrush.Dispose();
path.Dispose();
}
示例13: panelDrawArea_Paint
private void panelDrawArea_Paint(object sender, PaintEventArgs e)
{
if(drawingProcess)
{
tempDrawingArea = (Bitmap)snapshotDrawArea.Clone();
g = Graphics.FromImage(tempDrawingArea);
drawingPen = new Pen(brushColor, lineWidth);
drawigBrush = new SolidBrush(fillColor);
switch (selectedTool)
{
case GraphicTool.Dot:
drawigBrush = new SolidBrush(brushColor);
g.FillRectangle(drawigBrush, xStartPoint, yStartPoint, lineWidth, lineWidth);
e.Graphics.DrawImageUnscaled(tempDrawingArea, 0, 0);
xStartPoint = xEndPoint;
yStartPoint = yEndPoint;
snapshotDrawArea = (Bitmap)tempDrawingArea.Clone();
break;
case GraphicTool.Pencil:
g.DrawLine(drawingPen, xStartPoint, yStartPoint, xEndPoint, yEndPoint);
e.Graphics.DrawImageUnscaled(tempDrawingArea, 0, 0);
xStartPoint = xEndPoint;
yStartPoint = yEndPoint;
snapshotDrawArea = (Bitmap)tempDrawingArea.Clone();
break;
case GraphicTool.Line:
g.DrawLine(drawingPen, xStartPoint, yStartPoint, xEndPoint, yEndPoint);
e.Graphics.DrawImageUnscaled(tempDrawingArea, 0, 0);
break;
case GraphicTool.Rectangle:
//Realization of universal drawing of a rectangle. FillRectangle and DrawRectangle are doesn't understand negative values of the size.
if (xStartPoint < xEndPoint && yStartPoint < yEndPoint)
{
g.FillRectangle(drawigBrush, new Rectangle(xStartPoint, yStartPoint, xEndPoint - xStartPoint, yEndPoint - yStartPoint));
g.DrawRectangle(drawingPen, new Rectangle(xStartPoint, yStartPoint, xEndPoint - xStartPoint, yEndPoint - yStartPoint));
}
else if (xStartPoint > xEndPoint && yStartPoint < yEndPoint)
{
g.FillRectangle(drawigBrush, new Rectangle(xStartPoint + (xEndPoint - xStartPoint), yStartPoint, Math.Abs(xEndPoint - xStartPoint), Math.Abs(yEndPoint - yStartPoint)));
g.DrawRectangle(drawingPen, new Rectangle(xStartPoint + (xEndPoint - xStartPoint), yStartPoint, Math.Abs(xEndPoint - xStartPoint), Math.Abs(yEndPoint - yStartPoint)));
}
else if (xStartPoint < xEndPoint && yStartPoint > yEndPoint)
{
g.FillRectangle(drawigBrush, new Rectangle(xStartPoint, yStartPoint + (yEndPoint - yStartPoint), Math.Abs(xEndPoint - xStartPoint), Math.Abs(yEndPoint - yStartPoint)));
g.DrawRectangle(drawingPen, new Rectangle(xStartPoint, yStartPoint + (yEndPoint - yStartPoint), Math.Abs(xEndPoint - xStartPoint), Math.Abs(yEndPoint - yStartPoint)));
}
else
{
g.FillRectangle(drawigBrush, new Rectangle(xEndPoint, yEndPoint, Math.Abs(xEndPoint - xStartPoint), Math.Abs(yEndPoint - yStartPoint)));
g.DrawRectangle(drawingPen, new Rectangle(xEndPoint, yEndPoint, Math.Abs(xEndPoint - xStartPoint), Math.Abs(yEndPoint - yStartPoint)));
}
e.Graphics.DrawImageUnscaled(tempDrawingArea, 0, 0);
break;
case GraphicTool.Ellipse:
g.DrawEllipse(drawingPen, new Rectangle(xStartPoint, yStartPoint, xEndPoint - xStartPoint, yEndPoint - yStartPoint));
g.FillEllipse(drawigBrush, new Rectangle(xStartPoint, yStartPoint, xEndPoint - xStartPoint, yEndPoint - yStartPoint));
e.Graphics.DrawImageUnscaled(tempDrawingArea, 0, 0);
break;
default:
break;
}
drawingPen.Dispose();
drawigBrush.Dispose();
g.Dispose();
}
}