本文整理汇总了C#中System.Drawing.Drawing2D.GraphicsPath.GetBounds方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Drawing2D.GraphicsPath.GetBounds方法的具体用法?C# System.Drawing.Drawing2D.GraphicsPath.GetBounds怎么用?C# System.Drawing.Drawing2D.GraphicsPath.GetBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.GraphicsPath
的用法示例。
在下文中一共展示了System.Drawing.Drawing2D.GraphicsPath.GetBounds方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasureText
private Size MeasureText(Graphics graphics, string text, Font font)
{
var sz = TextRenderer.MeasureText(graphics, text, this.Font, new Size(0, 0), tf);
return sz;
var bounds = new RectangleF();
using (var textPath = new System.Drawing.Drawing2D.GraphicsPath())
{
textPath.AddString(
text,
font.FontFamily,
(int)font.Style,
font.Size,
new PointF(0, 0),
StringFormat.GenericTypographic);
bounds = textPath.GetBounds();
}
return new Size((int)bounds.Width, (int)bounds.Height);
}
示例2: AnalyzeVertexGroup
/// <summary>
/// Analyzuje pole vertexů jako polygon a zjistí jeho geometrický střed (centroid), šířku a výšku
/// </summary>
/// <param name="Vertices">Pole vertexů</param>
/// <returns>Výsledek analýzy polygonu</returns>
public static GeometryDescriptor AnalyzeVertexGroup(PointF[] Vertices)
{
if (Vertices.Length <= 1)
throw new ArgumentException();
GeometryDescriptor Description = new GeometryDescriptor(Vertices);
Description.FrontalArea = PolygonArea(Vertices);
for (int i = 0,j = 0; i < Vertices.Length; i++)
{
j = (i + 1) % Vertices.Length;
Description.Centroid.X += (Vertices[i].X + Vertices[j].X) * (Vertices[i].X * Vertices[j].Y - Vertices[i].Y * Vertices[j].X);
Description.Centroid.Y += (Vertices[i].Y + Vertices[j].Y) * (Vertices[i].X * Vertices[j].Y - Vertices[i].Y * Vertices[j].X);
}
Description.ConvexHull = ConvexHull.GetConvexHull(Vertices);
Description.Centroid.X /= (float)(Description.FrontalArea * 6);
Description.Centroid.Y /= (float)(Description.FrontalArea * 6);
using (System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath())
{
p.AddPolygon(Vertices);
RectangleF r = p.GetBounds();
Description.Width = r.Width;
Description.Height = r.Height;
}
return Description;
}
示例3: Carte_Paint
private void Carte_Paint(object sender, PaintEventArgs e)
{
int i;
double w, h;
//projet = ((Musliw.MusliW)(this.MdiParent)).projet;
Graphics page = e.Graphics;
//page.Clear(this.BackColor);
w = this.Width;
h = this.Height;
Pen stylo = new Pen(fen.stylo_couleur, (int)fen.epaisseur);
Font fonte = new Font(FontFamily.GenericSansSerif, 7,FontStyle.Bold);
this.ForeColor = Color.Black;
Brush brosse =new SolidBrush(fen.brosse_couleur);
Brush brosse_texte = new SolidBrush(fen.couleur_texte);
double dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl);
double dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl);
double deltax,deltay,voldeltax,voldeltay;
double cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl);
double cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl);
//MessageBox.Show(xl.ToString() + " " + yu.ToString());
PointF p1=new PointF();
PointF p2 = new PointF();
PointF p3 = new PointF();
PointF p4 = new PointF();
PointF p5 = new PointF();
PointF[] points = new PointF[4] ;
double angle=0,norme=0;
double sinx = 0, cosx = 1;
if (fen.volume_echelle < 1e-6f)
{
fen.volume_echelle = 1e-6f;
}
for (i = 0; i < projet.reseaux[nproj].links.Count; i++)
{
norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true))
{
//page.DrawRectangle(stylo, 0f, 0f, 200, 200);
//MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
cosx = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
sinx = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
page.DrawLine(stylo, (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay), (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax),(float) (((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay),(float) (((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax));
p1.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay);
p1.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax);
p2.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay);
p2.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax);
p3.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay);
p3.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax);
p4.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay);
p4.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax);
System.Drawing.Drawing2D.GraphicsPath epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
epaisseur.StartFigure();
points[0] = p1;
points[1] = p2;
points[2] = p3;
points[3] = p4;
epaisseur.AddPolygon(points);
epaisseur.CloseFigure();
//page.FillPath(brosse, epaisseur);
//page.FillPolygon(brosse, points);
//page.DrawPolygon(stylo,points);
epaisseur.Reset();
texte_epaisseur.StartFigure();
p5.X = 0.5f * (p3.X + p2.X);
p5.Y = 0.5f * (p3.Y + p2.Y);
texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, (float)fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault);
RectangleF encombrement = texte_epaisseur.GetBounds();
// texte_epaisseur.AddRectangle(encombrement);
//texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360);
page.FillPolygon(brosse, points);
page.DrawPolygon(stylo, points);
if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0)
{
System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix();
if (cosx >= 0 && sinx <= 0)
{
angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
rotation.RotateAt((float)angle, p5);
rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
texte_epaisseur.Transform(rotation);
trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
//.........这里部分代码省略.........
示例4: Render
public Caption Render(string message, Position position, string fontName, float fontSize, bool isBold, bool isItalic, Color fontColor, Color bgColor, float bgBorder)
{
using (Graphics g = Graphics.FromImage(bitmap))
{
float padding = bgBorder * g.DpiX / 72;
float x = padding;
float y = padding;
int fontStyle = (int)System.Drawing.FontStyle.Regular;
if (isBold) fontStyle |= (int)System.Drawing.FontStyle.Bold;
if (isItalic) fontStyle |= (int)System.Drawing.FontStyle.Italic;
Font font = new Font(fontName, fontSize);
Brush brush = new SolidBrush(fontColor);
Brush bbrush = new SolidBrush(bgColor);
Pen pen = new Pen(bbrush, padding);
pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
// Get Render Bounds
RectangleF rect;
using (var gp = new System.Drawing.Drawing2D.GraphicsPath())
{
gp.AddString(message, new FontFamily(fontName), fontStyle, fontSize, new RectangleF(new PointF(padding, padding), new SizeF(bitmap.Width - padding, bitmap.Height - padding)), StringFormat.GenericTypographic);
rect = gp.GetBounds();
}
// Render
if (position == K4WDisclaimer.Position.Bottom)
{
y = bitmap.Height - rect.Height - rect.Y - padding;
}
using (var gp = new System.Drawing.Drawing2D.GraphicsPath())
{
gp.AddString(message, new FontFamily(fontName), fontStyle, fontSize, new RectangleF(new PointF(x, y), new SizeF(bitmap.Width - padding, bitmap.Height - padding)), StringFormat.GenericTypographic);
g.FillPath(bbrush, gp);
g.DrawPath(pen, gp);
g.FillPath(brush, gp);
}
brush.Dispose();
bbrush.Dispose();
pen.Dispose();
font.Dispose();
}
return this;
}
示例5: RefreshAndStopDrawing
/// <summary>
/// Erase the trail of the gesture and stop drawing
/// </summary>
public void RefreshAndStopDrawing()
{
// the drawing of gestures was finished
m_gestureDrawing = false;
// drawing in thread timer tick should not continue
m_drawingEnded = true;
// stop the thread timer
m_threadTimerDraw.Change(-1, -1);
if (!m_threadDrawing)
{
int lastIndex = m_curvePoints.Count;
PointF[] points = m_curvePoints.GetRange(m_lastIndex, lastIndex - m_lastIndex).ToArray();
m_lastIndex = lastIndex - 1;
if (points.Length > 1)
m_gp.DrawLines(m_pen, points);
}
List<PointF> allPoints = new List<PointF>(m_curvePoints.ToArray());
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines(allPoints.ToArray());
RectangleF rect = path.GetBounds();
int rectShift = m_penWidth * 6;
rect.X -= rectShift;
rect.Y -= rectShift;
rect.Width += rectShift * 2;
rect.Height += rectShift * 2;
//Win32.RECT r = new Win32.RECT(rect);
m_drawnRegion = new Win32.RECT(rect);
//Rectangle r = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
if (!m_threadDrawing)
{
Debug.WriteLine(String.Format("##### InvalidateRect in MOUSE UP left: {0}, top: {1}, right: {2}, bottom: {3} ######",
m_drawnRegion.left, m_drawnRegion.top, m_drawnRegion.right, m_drawnRegion.bottom));
//Win32.InvalidateRect(m_hwndForm, ref m_drawnRegion, true);
Win32.RedrawWindow(m_hwndForm, ref m_drawnRegion, IntPtr.Zero, Win32.RDW_ERASE | Win32.RDW_INVALIDATE | Win32.RDW_UPDATENOW);
MakeNonTopMost();
}
else
m_redrawInTick = true;
//this.Invalidate(r);
//Win32.RedrawWindow(m_hwndForm, ref r, IntPtr.Zero, 0x2);
}
示例6: GeneratePath
protected override void GeneratePath()
{
_Path = new System.Drawing.Drawing2D.GraphicsPath();
_Path.AddRectangle(new Rectangle(Location, Size));
InvalidationArea = Rectangle.Round(_Path.GetBounds());
}