Aspose.Words.Examples.CSharp.Programming_Documents.Working_with_Tables.SpecifyHeightAndWidth.SetPreferredWidthSettings C# (CSharp) Method

SetPreferredWidthSettings() private static method

Shows how to set the different preferred width settings.
private static SetPreferredWidthSettings ( string dataDir ) : void
dataDir string
return void
        private static void SetPreferredWidthSettings(string dataDir)
        {
            // ExStart:SetPreferredWidthSettings
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a table row made up of three cells which have different preferred widths.
            Table table = builder.StartTable();

            // Insert an absolute sized cell.
            builder.InsertCell();
            builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(40);
            builder.CellFormat.Shading.BackgroundPatternColor = Color.LightYellow;
            builder.Writeln("Cell at 40 points width");

            // Insert a relative (percent) sized cell.
            builder.InsertCell();
            builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);
            builder.CellFormat.Shading.BackgroundPatternColor = Color.LightBlue;
            builder.Writeln("Cell at 20% width");

            // Insert a auto sized cell.
            builder.InsertCell();
            builder.CellFormat.PreferredWidth = PreferredWidth.Auto;
            builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGreen;
            builder.Writeln("Cell automatically sized. The size of this cell is calculated from the table preferred width.");
            builder.Writeln("In this case the cell will fill up the rest of the available space.");

            dataDir = dataDir + "Table.CellPreferredWidths_out.doc";
            // Save the document to disk.
            doc.Save(dataDir);
            // ExEnd:SetPreferredWidthSettings
            Console.WriteLine("\nDifferent preferred width settings set successfully.\nFile saved at " + dataDir);
        }
        /// <summary>