FastReport

Форк
0
/
PageColumns.cs 
120 строк · 3.4 Кб
1
using FastReport.Utils;
2
using System;
3
using System.ComponentModel;
4

5
namespace FastReport
6
{
7
    /// <summary>
8
    /// This class contains the page columns settings. 
9
    /// It is used in the <see cref="ReportPage.Columns"/> property.
10
    /// </summary>
11
    [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
12
    public class PageColumns
13
    {
14
        private int count;
15
        private float width;
16
        private FloatCollection positions;
17
        private ReportPage page;
18

19
        /// <summary>
20
        /// Gets or sets the number of columns.
21
        /// </summary>
22
        /// <remarks>
23
        /// Set this property to 0 or 1 if you don't want to use columns.
24
        /// </remarks>
25
        [DefaultValue(1)]
26
        public int Count
27
        {
28
            get { return count; }
29
            set
30
            {
31
                if (value <= 0)
32
                    throw new ArgumentOutOfRangeException("Count", "Value must be greather than 0");
33

34
                count = value;
35
                width = (page.PaperWidth - page.LeftMargin - page.RightMargin) / count;
36
                positions.Clear();
37
                for (int i = 0; i < count; i++)
38
                {
39
                    positions.Add(i * Width);
40
                }
41
            }
42
        }
43

44
        /// <summary>
45
        /// Gets or sets the column width.
46
        /// </summary>
47
        [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
48
        public float Width
49
        {
50
            get { return width; }
51
            set { width = value; }
52
        }
53

54
        /// <summary>
55
        /// Gets or sets a list of column starting positions.
56
        /// </summary>
57
        /// <remarks>
58
        /// Each value represents a column starting position measured in the millimeters.
59
        /// </remarks>
60
        public FloatCollection Positions
61
        {
62
            get { return positions; }
63
            set
64
            {
65
                if (value.Count == count)
66
                {
67
                    positions = value;
68
                }
69
                else
70
                {
71
                    positions.Clear();
72
                    for (int i = 0; i < count; i++)
73
                    {
74
                        positions.Add(i * Width);
75
                    }
76
                }
77
            }
78
        }
79

80
        private bool ShouldSerializeWidth()
81
        {
82
            return Count > 1;
83
        }
84

85
        private bool ShouldSerializePositions()
86
        {
87
            return Count > 1;
88
        }
89

90
        /// <summary>
91
        /// Assigns values from another source.
92
        /// </summary>
93
        /// <param name="source">Source to assign from.</param>
94
        public void Assign(PageColumns source)
95
        {
96
            Count = source.Count;
97
            Width = source.Width;
98
            Positions.Assign(source.Positions);
99
        }
100

101
        internal void Serialize(FRWriter writer, PageColumns c)
102
        {
103
            if (Count != c.Count)
104
                writer.WriteInt("Columns.Count", Count);
105
            if (Count > 1)
106
            {
107
                writer.WriteFloat("Columns.Width", Width);
108
                Positions = Positions; // avoid bug when number of positions is not equal number of columns
109
                writer.WriteValue("Columns.Positions", Positions);
110
            }
111
        }
112

113
        internal PageColumns(ReportPage page)
114
        {
115
            this.page = page;
116
            positions = new FloatCollection();
117
            Count = 1;
118
        }
119
    }
120
}
121

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.