Reports for WinForms | ComponentOne
Working with C1PrintDocument / Render Objects / Render Objects Containment, Positioning, and Stacking Rules / Examples of relative positioning of render objects
In This Topic
    Examples of relative positioning of render objects
    In This Topic

    Below are some examples showing the use of relative positioning of objects to arrange an image and a text ("myImage" in those samples is an object of type System.Drawing.Image declared elsewhere in code):

    This code places the text below the image simply adding one object after another into the regular block flow:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc as New C1PrintDocument
    Dim rt as New RenderText("test")
    Dim ri as New RenderImage(myImage)
    Dim ra As New RenderArea()
    ra.Children.Add(ri)
    ra.Children.Add(rt)
    doc.Body.Children.Add(ra)
    

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText("test");
    RenderImage ri = new RenderImage(myImage);
    RenderArea ra = new RenderArea();
    ra.Children.Add(ri);
    ra.Children.Add(rt);
    doc.Body.Children.Add(ra);
    

    This code produces equivalent result (text below image) while the children are added to the area in inverse order (because both objects have non-auto coordinates specified explicitly, neither is inserted into the block flow):

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc as New C1PrintDocument
    Dim rt as New RenderText("test")
    Dim ri as New RenderImage(myImage)
    Dim ra As New RenderArea()
    ' place image at the top of the parent:
    ri.Y = 0
    ' place text below next sibling:
    rt.Y = "next.bottom"
    ' auto-size text width:
    rt.Width = Unit.Auto
    ra.Children.Add(ri)
    ra.Children.Add(rt)
    doc.Body.Children.Add(ra)
    

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText("test");
    RenderImage ri = new RenderImage(myImage);
    RenderArea ra = new RenderArea();
    // place image at the top of the parent:
    ri.Y = 0;
    // place text below next sibling:
    rt.Y = "next.bottom";
    // auto-size text width:
    rt.Width = Unit.Auto;
    ra.Children.Add(rt);
    ra.Children.Add(ri);
    doc.Body.Children.Add(ra);
    

    The following code inserts the image into the regular block flow, while putting the text to the right of the image, centering it vertically relative to the image:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc as New C1PrintDocument
    Dim rt as New RenderText("test")
    Dim ri as New RenderImage(myImage)
    Dim ra As New RenderArea()
    ra.Children.Add(ri)
    rt.Width = Unit.Auto
    ' add text after the image:
    ra.Children.Add(rt)
    rt.X = "prev.right"
    rt.Y = "prev.height/2-self.height/2"
    doc.Body.Children.Add(ra)
    

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText("test");
    RenderImage ri = new RenderImage(myImage);
    RenderArea ra = new RenderArea();
    ra.Children.Add(ri);
    rt.Width = Unit.Auto;
    // add text after the image:
    ra.Children.Add(rt);
    rt.X = "prev.right";
    rt.Y = "prev.height/2-self.height/2";
    doc.Body.Children.Add(ra);
    

    This code also places the text to the right of the image, centered vertically - but uses the RenderObject.Name in the positioning expressions rather than relative id "prev", Also, the text is shifted 2mm to the right, demonstrating the use of absolute lengths in expressions:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc as New C1PrintDocument
    Dim rt as New RenderText("test")
    Dim ri as New RenderImage(myImage)
    Dim ra As New RenderArea()
    ri.Name = "myImage"
    rt.Width = "auto"
    rt.X = "myImage.right+2mm"
    rt.Y = "myImage.height/2-self.height/2"
    ra.Children.Add(ri)
    ra.Children.Add(rt)
    doc.Body.Children.Add(ra)
    

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText("test");
    RenderImage ri = new RenderImage(myImage);
    RenderArea ra = new RenderArea();
    ri.Name = "myImage";
    rt.Width = "auto";
    rt.X = "myImage.right+2mm";
    rt.Y = "myImage.height/2-self.height/2";
    ra.Children.Add(ri);
    ra.Children.Add(rt);
    doc.Body.Children.Add(ra);
    

    The code below modifies the same example so that the text is shifted to the right at least 6cm, using the built-in Max functions:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc as New C1PrintDocument
    Dim rt as New RenderText("test")
    Dim ri as New RenderImage(myImage)
    Dim ra As New RenderArea()
    ri.Name = "myImage"
    rt.Width = "auto"
    rt.X = "Max(myImage.right+2mm,6cm)"
    rt.Y = "myImage.height/2-self.height/2"
    ra.Children.Add(ri)
    ra.Children.Add(rt)
    doc.Body.Children.Add(ra)
    

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText("test");
    RenderImage ri = new RenderImage(myImage);
    RenderArea ra = new RenderArea();
    ri.Name = "myImage";
    rt.Width = "auto";
    rt.X = "Max(myImage.right+2mm,6cm)";
    rt.Y = "myImage.height/2-self.height/2";
    ra.Children.Add(ri);
    ra.Children.Add(rt);
    doc.Body.Children.Add(ra);
    

    The following code snippet aligns image to the right side of the page (utilizing the default value for the width of a render area - parent width), while the text is left-aligned, and centered vertically relative to the image:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc as New C1PrintDocument
    Dim rt as New RenderText("test")
    Dim ri as New RenderImage(myImage)
    Dim ra As New RenderArea()
    ri.Name = "myImage"
    ' right-align image:
    ri.X = "parent.right-width"
    ' left-align text:
    rt.X = "0"
    rt.Y = "myImage.height/2-height/2"
    ra.Children.Add(ri)
    ra.Children.Add(rt)
    doc.Body.Children.Add(ra)
    

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    RenderText rt = new RenderText("test");
    RenderImage ri = new RenderImage(myImage);
    RenderArea ra = new RenderArea();
    ri.Name = "myImage";
    // right-align image:
    ri.X = "parent.right-width";
    // left-align text:
    rt.X = "0";
    rt.Y = "myImage.height/2-height/2";
    ra.Children.Add(ri);
    ra.Children.Add(rt);
    doc.Body.Children.Add(ra);