PrintDocument for WinForms
CalcSize メソッド (RenderObject)
使用例 


C1.PrintDocument.6 アセンブリ > C1.C1Preview 名前空間 > RenderObject クラス : CalcSize メソッド
The width of the current object. This parameter may be specified as Unit.Auto or as an absolute value (but it must not reference other objects).
The height of the current object. This parameter may be specified as Unit.Auto or as an absolute value (but it must not reference other objects).
Calculates the size of the current object. When this method is called, the object must already have been added to the document (e.g. to C1PrintDocument.Body or to RenderObject.Children of another object in the document). See remarks for more details.
シンタックス
'宣言
 
Public Function CalcSize( _
   ByVal width As Unit, _
   ByVal height As Unit _
) As SizeD
'使用法
 
Dim instance As RenderObject
Dim width As Unit
Dim height As Unit
Dim value As SizeD
 
value = instance.CalcSize(width, height)
public SizeD CalcSize( 
   Unit width,
   Unit height
)

パラメータ

width
The width of the current object. This parameter may be specified as Unit.Auto or as an absolute value (but it must not reference other objects).
height
The height of the current object. This parameter may be specified as Unit.Auto or as an absolute value (but it must not reference other objects).

戻り値の型

The size of the current object, in C1PrintDocument.ResolvedUnit units.
解説
If the current object has not been added to the document, an exception is thrown. (This is because to calculate the size of an object, its style is needed, and due to style inheritance, the effective style of an object depends on the placement of that object within the document.) The object may be removed from the document after calling this method if desired. The following C# code may be used to test whether a RenderText will fit on the current page if inserted at the current block flow position (see C1PrintDocument.AvailableBlockFlowHeight): 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();
使用例
The following C# code may be used to test whether a RenderText will fit on the current page if inserted at the current block flow position (see C1PrintDocument.AvailableBlockFlowHeight):
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();
参照

RenderObject クラス
RenderObject メンバ