C1.C1Preview Namespace > RenderObject Class : CalcSize Method |
C1PrintDocument doc = new C1PrintDocument(); doc.StartDoc(); RenderText rt = new RenderText("The text to measure.); // add the object temporarily to calculate its size: doc.Body.Children.Add(rt); // measure the object, specifying page width and auto heigh // (i.e. effectively, measure the text height): C1PageSettings ps = doc.PageLayout.PageSettings; double pageWidth = ps.Width.Value - ps.LeftMargin.Value - ps.RightMargin.Value; SizeD sz = rt.CalcSize(new Unit(pageWidth, ps.Width.Units), Unit.Auto); // remove the object added temporarily: doc.Body.Children.Remove(rt); // test whether the object would fit on the page: if (doc.AvailableBlockFlowHeight >= sz.Height) { // object would fit, do something: doc.RenderBlockText("YES"); } doc.EndDoc();
C1PrintDocument doc = new C1PrintDocument(); doc.StartDoc(); RenderText rt = new RenderText("The text to measure.); // add the object temporarily to calculate its size: doc.Body.Children.Add(rt); // measure the object, specifying page width and auto heigh // (i.e. effectively, measure the text height): C1PageSettings ps = doc.PageLayout.PageSettings; double pageWidth = ps.Width.Value - ps.LeftMargin.Value - ps.RightMargin.Value; SizeD sz = rt.CalcSize(new Unit(pageWidth, ps.Width.Units), Unit.Auto); // remove the object added temporarily: doc.Body.Children.Remove(rt); // test whether the object would fit on the page: if (doc.AvailableBlockFlowHeight >= sz.Height) { // object would fit, do something: doc.RenderBlockText("YES"); } doc.EndDoc();
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2