Welcome Guest! You need to login or register to make posts.



Go to last post Go to first unread
#1 Posted : Friday, December 14, 2007 5:49:54 PM(UTC)

Rank: Member

Groups: Member
Joined: 12/14/2007(UTC)
Posts: 2

I'm working on a medical application where I need to measure distances. For this purpose, I wanted to create (inherits) from a LineVObject, and add a text in the middle of the line which would be the distance (in pixels at first).
I though I would just inherit from LineVObjet and override the Draw method like this :


 public override void Draw(Rectangle renderingRect, Graphics g, ICoordinateMapper coordinateMapper)
           m_text.Text = ((renderingRect.Width + renderingRect.Height)/2).ToString();
           RectangleF rec = m_text.TextArea;
           rec.X = renderingRect.Width/2 + renderingRect.X;
           m_text.TextArea = rec;
           m_text.Draw(renderingRect, g, coordinateMapper);
           base.Draw(renderingRect, g, coordinateMapper);

But the text is not printed in the middle (X) of the line and the value displayed doesn't seem to be ok (I can't get less than 50 even if the line is at its minimum). So can someone give me a hint about doing this ? I know this is maybe not the right way of doing it...
Thank you


Edited by user Saturday, December 15, 2007 6:11:44 AM(UTC)  | Reason: Not specified

Alex Kon  
#2 Posted : Tuesday, December 18, 2007 5:33:36 PM(UTC)
Alex Kon

Rank: Advanced Member

Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello Loïc,

It is possible to implement drawing of the measured distance as a part of the VObject rendering. But the problem is that in such case the distance text sign will change its size while zooming... I think that is not the behaviour you want.

VObject itself is binded to the workspace coordinate system and if you change zoom from 100% to 200% - it should be drawn in a doubled size. Maybe it will be acceptable for you to render this sign via VObject designer? But note that in this case the sign will be visible only when line object is selected.

Here is the code sample which demostrates how to extend standart edit designer of the LineVObject to display line width:

class MeasuringLineDesigner : Aurigma.GraphicsMill.WinControls.GenericVObjectEditDesigner
	public MeasuringLineDesigner(MeasuringLine line)
		: base(line)
		if (line == null)
			throw new ArgumentNullException("line");

		_line = line;
		_font = new System.Drawing.Font("Verdana", 12);
		_brush = System.Drawing.Brushes.Red;

	public override void Draw(System.Drawing.Graphics g)

		System.Drawing.Rectangle textBounds = GetDistanceTextRectangle();
		g.DrawString(_line.GetDistanceText(), _font, _brush, textBounds.Location);

	protected override void ObjectChangedHandler(object sender, System.EventArgs e)
		base.ObjectChangedHandler(sender, e);
		if (this.Connected)

	private void InvalidateDesignerArea()

		System.Drawing.Rectangle invalidationRect = GetDistanceTextRectangle();
			new Aurigma.GraphicsMill.WinControls.MultiLayerViewerInvalidationTarget(invalidationRect));

	private System.Drawing.Rectangle GetDistanceTextRectangle()
		System.Drawing.Rectangle lineBounds = base.VObjectHost.HostViewer.WorkspaceToControl(

		System.Drawing.SizeF textSize = _g.MeasureString(_line.GetDistanceText(), _font);

		System.Drawing.RectangleF result = new System.Drawing.RectangleF();
		result.X = lineBounds.Left + lineBounds.Width / 2 - textSize.Width / 2;
		result.Y = lineBounds.Top + lineBounds.Height / 2 - textSize.Height / 2;
		result.Width = textSize.Width;
		result.Height = textSize.Height;

		return System.Drawing.Rectangle.Ceiling(result);

	private MeasuringLine _line;
	private System.Drawing.Font _font;
	private System.Drawing.Brush _brush;
	private System.Drawing.Graphics _g = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);

class MeasuringLine : Aurigma.GraphicsMill.WinControls.LineVObject
	public MeasuringLine(float x0, float y0, float x1, float y1)
		: base(x0, y0, x1, y1)
		_designer = new MeasuringLineDesigner(this);

	public override Aurigma.GraphicsMill.WinControls.IDesigner Designer
			return _designer;

	public string GetDistanceText()
		System.Drawing.PointF[] pnts = new System.Drawing.PointF[2];
		pnts[0] = base.Path.PathPoints[0];
		pnts[1] = base.Path.PathPoints[1];

		int distance = (int)Math.Sqrt(Math.Pow(pnts[0].X - pnts[1].X, 2) +
					     Math.Pow(pnts[0].Y - pnts[1].Y, 2));

		return string.Format("D={0}", distance);

	private MeasuringLineDesigner _designer;
Users browsing this topic
Similar Topics
Removing vObjects (Discussions – Graphics Mill)
by Andy79 10/7/2012 8:05:27 PM(UTC)
IE9 / VObjectsRubberband / gifteditor (Discussions – Graphics Mill)
by NormanL 4/26/2012 3:15:33 AM(UTC)
How to resize selected VObjects (Discussions – Graphics Mill)
by ChingYen 5/2/2011 4:36:20 PM(UTC)
VObjects coordinate space (Discussions – Graphics Mill)
by mike_w_mason 4/27/2009 10:01:24 PM(UTC)
HOWTO: Reset Rotation of VObjects (Archive - Graphics Mill)
by Tamila 3/15/2009 8:03:58 PM(UTC)
Grip size for vObjectsRubberband (Discussions – Graphics Mill)
by mikro 9/25/2008 1:46:01 AM(UTC)
HOWTO: Rotate VObjects (Archive - Graphics Mill)
by Tamila 9/22/2008 5:59:29 PM(UTC)
PRB: Cannot Deserialize VObjects after Update Assemblies (Archive - Graphics Mill)
by Tamila 7/14/2008 4:20:10 PM(UTC)
Transforms and Filters on ImageVObjects (Discussions – Graphics Mill)
by tcrosbie 7/3/2008 5:41:43 PM(UTC)
Printing Vobjects and image together (Discussions – Graphics Mill)
by cpav 6/8/2008 4:47:54 PM(UTC)
Issue about adding Vobjects and selecting area (Discussions – Graphics Mill)
by cpav 5/15/2008 6:47:43 AM(UTC)
How can I get the rectangle information from Vobjects in Multilayerviewer (Discussions – Graphics Mill)
by Ichiro 2/27/2007 4:46:09 PM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.