I want to create my own kind of rich text box in winforms, where lines are curved, in circle for example and will have many other effects and animations, like the angled text: http://ift.tt/1F5mLq0
I've been using something similar to this But it is way too slow, I mean it's visibly slow, and I'll need much more functionality. On the other hand, it is not really graphically intensive, you can play games in software mod that require much more intensive graphic processing without problem, so I't sure this is from .NET being extremely slow with such tasks. What can I do, probably create it in C++ and then just import the control?
Here's my code so far:
void WriteCircle(Control c, string s, Point P, float r)
{
try
{
Graphics g = c.CreateGraphics(); g.SmoothingMode = SmoothingMode.AntiAlias;
Font f = new Font(c.Font.FontFamily, 12F);
SolidBrush b = new SolidBrush(c.ForeColor);
List<float> widths = new List<float>();
float space = g.MeasureString(" ", f, Point.Empty, StringFormat.GenericDefault).Width;
foreach (char ch in s)
{
if (ch == ' ')widths.Add(space);
else widths.Add(g.MeasureString(ch.ToString(), f, Point.Empty, StringFormat.GenericTypographic).Width);
}
float sH = g.MeasureString(s, f).Height; //s.Height
float sW = widths.Sum(); //s.Width
//DrawCircle(c, (int)r, P);
//DrawCircle(c, (int)(r0 + sH), P);
double alpha0 = DegtoRad(180F); double alphastart = alpha0;
int x0 = (int)Math.Ceiling(Math.Cos(alpha0) * r); int y0 = (int)Math.Ceiling(Math.Sin(alpha0) * r);
//DrawFilledCircle(c, 2, new Point(P.X + x0, P.Y + y0), Color.Red);
for (int i = 0; i < widths.Count(); i++)
{
int x = (int)Math.Ceiling(Math.Cos(alpha0) * r); int y = (int)Math.Ceiling(Math.Sin(alpha0) * r);
GraphicsPath path = new GraphicsPath();
path.AddString(s[i].ToString(), f.FontFamily, (int)f.Style, f.Size, Point.Empty, StringFormat.GenericTypographic);
RectangleF bounds = path.GetBounds();
Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.Translate(P.X + x, P.Y + y);
matrix.Rotate(RadtoDeg((float)alpha0) - 110);
matrix.Translate(-bounds.Width / 2F, -sH * 0.75F);
path.Transform(matrix);
g.FillPath(b, path);
double angle = Math.Acos((r * r + r * r - widths[i] * widths[i]) / (2 * r * r)); alpha0 -= angle;
if (RadtoDeg((float)alpha0) <= RadtoDeg((float)alphastart) - 360 + RadtoDeg((float)angle)) break;
}
}
catch { return; }
}
Aucun commentaire:
Enregistrer un commentaire