Hi,
Sorry to be a pain but I still have not been able to solve this problem. so thought I would post my code here. If you don't mind having a look.
Thanks
Loftty
Code:namespace WindowsApplication1 { public partial class Form1 : Form { Bitmap _backbuf; Graphics _grfx; GraphicsPath temp; GraphicsPath _myShape; bool MouseClicked = false; float StartX = 0; float StartY = 0; float currentX = 0; float currentY = 0; float currentX = 0; float currentY = 0; public Form1() { InitializeComponent(); } private void Redraw() { float scaleWidth = (float)(((float)trkWidth.Value / (float)trkWidth.Maximum) * 10); float scaleHeight = (float)(((float)trkHeight.Value / (float)trkHeight.Maximum) * 10); float rotation = (float)trkRotation.Value; DrawShape( scaleWidth, scaleHeight, rotation ); pictureBox1.Invalidate(); } private void DrawShape( float scaleWidth, float scaleHeight, float rotation ) { temp = (GraphicsPath)_myShape.Clone(); Matrix m1 = new Matrix(); int TX = (int)temp.GetBounds().X + ((int)temp.GetBounds().Width / 2); int TY = (int)temp.GetBounds().Y + ((int)temp.GetBounds().Height / 2); m1.Translate(-TX, -TY); temp.Transform(m1); Matrix m = new Matrix(); m.Translate(((int)_myShape.GetBounds().X + ((int)_myShape.GetBounds().Width)) / 2, ((int)_myShape.GetBounds().Y + ((int)_myShape.GetBounds().Height) / 2)); m.Rotate(rotation); m.Scale(scaleWidth, scaleHeight); temp.Transform(m); drawPaths(); } private void drawPaths() { _grfx.Clear(pictureBox1.BackColor); _grfx.DrawPath(new Pen(Color.Gainsboro, 1), temp); } private void pictureBox1_Resize( object sender, EventArgs e ) { InitBuffer(); } private void InitBuffer() { int w = pictureBox1.Width; int h = pictureBox1.Height; _backbuf = new Bitmap( w > 0 ? w : 1, h > 0 ? h : 1 ); _grfx = Graphics.FromImage( _backbuf ); _grfx.SmoothingMode = SmoothingMode.AntiAlias; } private void pictureBox1_Paint( object sender, PaintEventArgs e ) { if ( _backbuf != null ) e.Graphics.DrawImageUnscaled( _backbuf, 0, 0 ); } private void Form1_Load( object sender, EventArgs e ) { InitBuffer(); } private GraphicsPath CreateShape() { GraphicsPath temp = new GraphicsPath(); FontFamily f = new FontFamily("Arial"); StringFormat st = new StringFormat(); temp.AddString("Hello", f, 1,40, new PointF(0,0), st); temp.CloseFigure(); return temp; } private void ChangeString() { GraphicsPath temp = new GraphicsPath(); FontFamily f = new FontFamily("Arial"); StringFormat st = new StringFormat(); temp.AddString(textBox1.Text, f, 1, 40, new PointF(currentX, currentY), st); temp.CloseFigure(); _myShape = temp; Redraw(); } private void trackBar1_Scroll( object sender, EventArgs e ) { Redraw(); } private void trackBar2_Scroll( object sender, EventArgs e ) { Redraw(); } private void button1_Click( object sender, EventArgs e ) { _myShape = CreateShape(); Redraw(); } private void trackBar3_Scroll( object sender, EventArgs e ) { drawPaths(); } private void pictureBox1_MouseDown( object sender, MouseEventArgs e ) { if ( temp.IsVisible( e.X, e.Y ) ) { MouseClicked = true; StartX = e.X - (int)temp.GetBounds().X; StartY = e.Y - (int)temp.GetBounds().Y; } } private void pictureBox1_MouseMove( object sender, MouseEventArgs e ) { if ( MouseClicked == true ) { float GX = e.X - temp.GetBounds().X; float GY = e.Y - temp.GetBounds().Y; float distanceX = GX - StartX; float distanceY = GY - StartY; Matrix m = new Matrix(); m.Translate(distanceX, distanceY); _myShape.Transform(m); Redraw(); } } private void pictureBox1_MouseUp( object sender, MouseEventArgs e ) { MouseClicked = false; float GX = temp.GetBounds().X; float GY = temp.GetBounds().Y; currentX = (GX - MinusX) * 2; currentY = GY - MinusY; } private void textBox1_TextChanged(object sender, EventArgs e) { ChangeString(); } } }




Reply With Quote