Reports for WinForms | ComponentOne
Working with C1PrintDocument / Styles / Inline and Non-Inline Styles
In This Topic
    Inline and Non-Inline Styles
    In This Topic

    In C1PrintDocument, there are two kinds of styles - inline and non-inline. If an object has the Style property, that property refers to the inline style of the object, which is an integral part of the object itself. An inline style cannot be removed or set - it's a read-only property that refers to the style instance which always lives together with the object. Thus, style properties can be considered to be the properties of the object itself. But, due to inheritance, styles are much more flexible and memory-efficient (for example, if none of an object's style properties have been modified from their default values, they consume almost no memory, referencing base style properties instead).

    Additionally, each Style contains a collection of styles (called Children, and empty by default) which are not directly attached to any objects. Instead, those (non-inline) styles can be used as parent styles (see style properties Parent and AmbientParent) to provide values for inherited properties of other styles (including, of course, inline styles).

    A style object cannot be created by itself - it is always either an inline style attached directly to a render object or other element of the document, or a member of the Children collection of another style.

    So, for instance, this code will not compile:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc As New C1PrintDocument()
    Style s = new Style() ' will not compile
    s.Borders.All = New LineDef("1mm", Color.Red)
    Dim rt As New RenderText("My text.")
    rt.Style = s
    

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    Style s = new Style(); // will not compile
    s.Borders.All = new LineDef("1mm", Color.Red);
    RenderText rt = new RenderText("My text.");
    rt.Style = s;
    

    While this code will compile and achieve the desired result:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc As New C1PrintDocument()
    Dim s = doc.Style.Children.Add()
    s.Borders.All = New LineDef("1mm", Color.Red)
    Dim rt As RenderText = New RenderText("My text.")
    rt.Style.Parent = s

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    Style s = doc.Style.Children.Add();
    s.Borders.All = new LineDef("1mm", Color.Red);
    RenderText rt = new RenderText("My text.");
    rt.Style.Parent = s;
    

    For more about ambient and non-ambient style attributes and parents, see Ambient and Non-Ambient Style Properties.