The width of a block is controlled from the PreferredWidth, MinWidth, and MaxWidth properties. Those properties can be specified either as fixed units (dips) or as percentages of the parent block content width. The following code example shows how to create a paragraph that spans 50% of the parent block width, but is always wider than 50 dips and narrower than 250dips:
Setting Block Width Preferences |
Copy Code
|
---|---|
NParagraph paragraph = new NParagraph("Paragraph with Preferred Width 50%, Min Width 50 dips, Max Width 250 dips"); paragraph.BackgroundFill = new NColorFill(NColor.LightGray); paragraph.PreferredWidth = new NMultiLength(ENMultiWidthUnit.Percentage, 50); paragraph.MinWidth = new NMultiLength(ENMultiWidthUnit.Dip, 50); paragraph.MaxWidth = new NMultiLength(ENMultiWidthUnit.Dip, 250); section.Blocks.Add(paragraph); |
If you do not specify a preferred width each block will automatically compute a width, depending on the block type. Paragraphs and Group Blocks use 100% of the container block content width. Tables will be sized so that the used width is enough to accommodate the cell content in the table.
In certain cases, you may want the automatically computed width of a block to be the width of the block without any hard line breaks (a hard line break is a break that is introduced to a paragraph in order to fit the parent width without having lines that extend outside the parent block). This is useful when you want to emulate the behavior of <pre> tags in html. To do this you can set the WrapDesiredWidth and WrapMinWidth properties to false:
Setting Block Width Preferences |
Copy Code
|
---|---|
NParagraph paragraph = new NParagraph("Paragraph with disabled line folding."); paragraph.WrapDesiredWidth = false; paragraph.WrapMinWidth = false; section.Blocks.Add(paragraph); |
The WrapDesiredWidrth/WrapMinWidth properties can be applied on any block. When applied on the root block in Web layout mode the control will not introduce hard breaks - this feature can be very useful if you want to create a code editor or a Notepad alternative for example.