Exemple #1
0
 public static void SplitRowsByPercentages(
     TableLayoutRowStyleCollection rowStyles, float[] percentages)
 {
     for (var i = 0; i < rowStyles.Count; i++)
     {
         rowStyles[i] = new RowStyle(SizeType.Percent, percentages[i]);
     }
 }
        public void TableLayoutRowStyleCollection_Item_GetNotRowStyle_ThrowsInvalidCastException()
        {
            using var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table };
            TableLayoutSettings           settings   = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);
            TableLayoutRowStyleCollection collection = settings.RowStyles;

            collection.Add(new ColumnStyle());
            Assert.Throws <InvalidCastException>(() => collection[0]);
        }
Exemple #3
0
 private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         rowStyles    = tableLayoutPanel1.RowStyles;
         columnStyles = tableLayoutPanel1.ColumnStyles;
         resizing     = true;
     }
 }
Exemple #4
0
        public static void setStyleLevelTable(ref TableLayoutPanel localLevelTable)
        {
            TableLayoutRowStyleCollection styles = localLevelTable.RowStyles;

            foreach (RowStyle style in styles)
            {
                style.SizeType = SizeType.Absolute;
                style.Height   = 30;
            }
        }
Exemple #5
0
 public ContainerInfo(ContainerInfo containerInfo)
 {
     _cellBorderWidth = containerInfo.CellBorderWidth;
     _maxRows         = containerInfo.MaxRows;
     _maxColumns      = containerInfo.MaxColumns;
     _growStyle       = containerInfo.GrowStyle;
     _container       = containerInfo.Container;
     _rowStyles       = containerInfo.RowStyles;
     _colStyles       = containerInfo.ColumnStyles;
 }
        private void ChangeRowSize(TableLayoutPanel tlp, int size)
        {
            TableLayoutRowStyleCollection styles = tlp.RowStyles;

            foreach (RowStyle style in styles)
            {
                style.SizeType = SizeType.Absolute;
                style.Height   = size;
            }
        }
        public void TableLayoutRowStyleCollection_Insert_RowStyle_Success()
        {
            using var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table };
            TableLayoutSettings           settings   = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);
            TableLayoutRowStyleCollection collection = settings.RowStyles;

            var style = new RowStyle();

            collection.Insert(0, style);
            Assert.Equal(style, Assert.Single(collection));
        }
Exemple #8
0
        public static List <RowStyle> AsList(this TableLayoutRowStyleCollection colection)
        {
            List <RowStyle> styles = new List <RowStyle>();

            foreach (RowStyle style in colection)
            {
                styles.Add(style);
            }

            return(styles);
        }
Exemple #9
0
        private void Config_Load(object sender, EventArgs e)
        {
            rowStyles   = tbPrincipal.RowStyles;
            rowGraficos = tbGraficos.RowStyles;
            rowAtalhos  = tbAtalhos.RowStyles;
            rowInicial  = tbInicial.RowStyles;
            DefaultState();


            RecolheSubs("");
        }
Exemple #10
0
        public void addTableRow(TableLayoutPanel table)
        {
            table.RowCount = table.RowCount + 1;
            table.RowStyles.Add(new RowStyle(SizeType.Absolute));
            TableLayoutRowStyleCollection styles =
                table.RowStyles;
            RowStyle styleRow = styles[table.RowCount - 1];

            // Set the row height to 20 pixels.
            styleRow.SizeType = SizeType.Absolute;
            styleRow.Height   = 40;
        }
Exemple #11
0
 static void Assert_AreEqual(TableLayoutRowStyleCollection expected, TableLayoutRowStyleCollection actual, String message)
 {
     for (int i = 0; i < Math.Min(expected.Count, actual.Count); ++i)
     {
         RowStyle expectedCur = expected[i];
         RowStyle actualCur   = actual[i];
         Assert_AreEqual(expectedCur, actualCur, "TableLayoutRowStyleCollection[" + i + "] -- " + message);
     }
     // Check this *after*, so that if the initial values in the lists don't match
     // that's reported instead -- it makes it more obvious what is being mis-parsed.
     Assert.AreEqual(expected.Count, actual.Count, "TableLayoutRowStyleCollection.Count -- " + message);
 }
        public Form1()
        {
            InitializeComponent();
            TableLayoutRowStyleCollection styles = tableLayoutPanel1.RowStyles;

            styles[1].SizeType = SizeType.Absolute;
            styles[1].Height   = 80;
            openFileDialog1.InitialDirectory = @"C:\Temp";
            openFileDialog1.Filter           = "Text Files (*.txt)|*.txt|" + "Comma-Delimited Files (*.csv)|*.csv|All Files (*.*)|*.*";
            saveFileDialog1.InitialDirectory = @"C:\Temp";
            saveFileDialog1.Filter           = "Text Files (*.txt)|*.txt|" + "Comma-Delimited Files (*.csv)|*.csv|All Files (*.*)|*.*";
        }
        public void TableLayoutRowStyleCollection_Contains_RowStyle_ReturnsExpected()
        {
            using var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table };
            TableLayoutSettings           settings   = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);
            TableLayoutRowStyleCollection collection = settings.RowStyles;
            var style = new RowStyle();

            collection.Add(style);
            Assert.True(collection.Contains(style));
            Assert.False(collection.Contains(new RowStyle()));
            Assert.False(collection.Contains(null));
        }
        public void TableLayoutRowStyleCollection_IndexOf_Invoke_ReturnsExpected()
        {
            using var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table };
            TableLayoutSettings           settings   = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);
            TableLayoutRowStyleCollection collection = settings.RowStyles;
            var style = new RowStyle();

            collection.Add(style);
            Assert.Equal(0, collection.IndexOf(style));
            Assert.Equal(-1, collection.IndexOf(new RowStyle()));
            Assert.Equal(-1, collection.IndexOf(null));
        }
Exemple #15
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            Text = $"{Options.AppName} - v{Options.AppVersion.ToString(3)}";

            IBible[] bibles = Options.BibleRepository.OpenAll();

            foreach (IBible b in bibles)
            {
                tsBibles.DropDownItems.Insert(0, new ToolStripMenuItem(b.Name)
                {
                    Tag = b
                });
            }

            openedBibles = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            if (bibles.Length > 0)
            {
                OpenBible(bibles[0]);
            }

            //Dispays
            tsDisplay.DropDownItems.Clear();
            Screen[] screens      = Screen.AllScreens;
            string[] screensNames = new string[screens.Length];
            int      secondary    = 0;

            for (int i = 0; i < screens.Length; i++)
            {
                Screen screen = screens[i];
                var    dd     = new DISPLAY_DEVICE();
                dd.cb = Marshal.SizeOf(dd);

                screensNames[i] = EnumDisplayDevices(screen.DeviceName, 0, ref dd, 0)
                    ? dd.DeviceString
                    : screen.DeviceName;

                tsDisplay.DropDownItems.Add(screensNames[i]).Tag = screen;

                if (!screen.Primary)
                {
                    secondary = i;
                }
            }

            displayView.SetDevice(screens[secondary], screensNames[secondary]);

            rowStyles    = tblBibles.RowStyles;
            columnStyles = tblBibles.ColumnStyles;
        }
        public void TableLayoutRowStyleCollection_Item_SetRowStyle_GetReturnsExpected()
        {
            using var toolStrip = new ToolStrip { LayoutStyle = ToolStripLayoutStyle.Table };
            TableLayoutSettings           settings   = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);
            TableLayoutRowStyleCollection collection = settings.RowStyles;

            collection.Add(new RowStyle());

            var style = new RowStyle();

            collection[0] = style;
            Assert.Single(collection);
            Assert.Equal(style, collection[0]);
        }
Exemple #17
0
        public VerifyFiles()
        {
            this.FileList     = new List <ModFile>();
            this.FormClosing += VerifyFiles_FormClosing;

            InitializeComponent();

            TableLayoutRowStyleCollection styles = tableLayoutPanel1.RowStyles;

            foreach (RowStyle style in styles)
            {
                style.SizeType = SizeType.Absolute;
                style.Height   = 20;
            }
        }
        public void TableLayoutRowStyleCollection_Remove_RowStyle_Success()
        {
            var toolStrip = new ToolStrip {
                LayoutStyle = ToolStripLayoutStyle.Table
            };
            TableLayoutSettings           settings   = Assert.IsType <TableLayoutSettings>(toolStrip.LayoutSettings);
            TableLayoutRowStyleCollection collection = settings.RowStyles;
            var style = new RowStyle();

            collection.Add(style);
            collection.Remove(style);
            Assert.Empty(collection);

            collection.Add(style);
            Assert.Equal(style, Assert.Single(collection));
        }
Exemple #19
0
        private static int RedistributePercents(int overlap, TableLayoutRowStyleCollection styles, int[] row_heights)
        {
            int saved = 0;

            if (overlap > 0)
            {
                // Find the total percent (not always 100%)
                float total_percent = 0;
                int   index         = 0;
                foreach (RowStyle rs in styles)
                {
                    if (index >= row_heights.Length)
                    {
                        break;
                    }
                    if (rs.SizeType == SizeType.Percent)
                    {
                        total_percent += rs.Height;
                    }
                    index++;
                }

                // Divvy up the space..
                index = 0;
                foreach (RowStyle rs in styles)
                {
                    if (index >= row_heights.Length)
                    {
                        break;
                    }
                    if (rs.SizeType == SizeType.Percent)
                    {
                        int height_change = (int)((rs.Height / total_percent) * overlap);
                        if (height_change > 0)
                        {
                            row_heights[index] += height_change;
                            saved += height_change;
                        }
                    }
                    index++;
                }
            }

            return(saved);
        }
        private void clear_button_Click(object sender, EventArgs e)
        {
            InitializeTableView(seqContext, "", parameterValuesArray, parameterTypesArray, true);  //Clear the grid
            this.tableLayoutPanel1.RowCount = 1;
            TableLayoutRowStyleCollection rowStyles = this.tableLayoutPanel1.RowStyles;

            foreach (RowStyle style in rowStyles)
            {
                if (style.SizeType == SizeType.AutoSize)
                {
                    style.SizeType = SizeType.Percent;
                }
            }
            this.FilePath.Text = "";
            Array.Resize(ref parameterValuesArray, 0);
            Array.Resize(ref parameterNamesArray, 0);
            Array.Resize(ref parameterTypesArray, 0);
        }
Exemple #21
0
        public ControllingForm()
        {
            InitializeComponent();

            TableLayoutRowStyleCollection rows = table.RowStyles;

            fullNameRow = rows[1];
            normalHeightOfFullNameRow         = fullNameRow.Height;
            repeatedPasswordRow               = rows[4];
            normalHeightOfRepeatedPasswordRow = repeatedPasswordRow.Height;

            minHeight = MinimumSize.Height;
            minHeightWhenAuthorize = minHeight - (int)(minHeight * (normalHeightOfFullNameRow + normalHeightOfRepeatedPasswordRow) / 100);

            selectedColor      = buttonRegister.BackColor;
            selectedColorHover = buttonRegister.FlatAppearance.MouseOverBackColor;

            ButtonAuthorize_Click(this, EventArgs.Empty);
        }
        /* if Client change the size of Form */
        private void Calculator_ClientSizeChanged(object sender, EventArgs e)//Completed Check of Syntax Code ***
        {
            // it measure on the standard or normal size of form (width 568, height 525)
            if (this.Height > 525 || this.Width > 568)
            {
                tlpRight.Visible   = true;
                btnHistory.Visible = false;

                TableLayoutRowStyleCollection RowStyle = this.tlpMain.RowStyles;
                GetDefaultStyle(tlpBottom, tlpMain, RowStyle, tlpRight);
            }
            else if (this.Height < 525 || this.Width < 568)
            {
                tlpRight.Visible   = false;
                btnHistory.Visible = true;
            }
            if (tlpRight.Dock == DockStyle.Bottom)
            {
                tlpBottom.Visible = true;
            }
        }
Exemple #23
0
        private void AddButtons(List <Model.MenuItem> items)
        {
            tableLayoutPanel1.ColumnCount = 2;
            if (items.Count % 2 == 1)
            {
                tableLayoutPanel1.RowCount = ((items.Count / 2) + 1);
            }
            else
            {
                tableLayoutPanel1.RowCount = items.Count / 2;
            }

            TableLayoutRowStyleCollection Rowstyles = tableLayoutPanel1.RowStyles;

            foreach (RowStyle style in Rowstyles)
            {
                style.SizeType = SizeType.Absolute;
                style.Height   = button_Item.Height;
            }

            button_Item.Name   = items[0].Name;
            button_Item.Tag    = items[0];
            button_Item.Text   = items[0].Name;
            button_Item.Click += (s, e) => {
                ChoosenItem = (Model.MenuItem)button_Item.Tag;
            };

            for (int i = 1; i < items.Count; i++)
            {
                Button b = new Button();
                b.Name   = "btn_" + items[i].Name;
                b.Tag    = items[i];
                b.Text   = items[i].Name;
                b.Size   = button_Item.Size;
                b.Click += (s, e) => {
                    ChoosenItem = (Model.MenuItem)b.Tag;
                };
                tableLayoutPanel1.Controls.Add(b);
            }
        }
        //Interface
        public void UpdateUsersTable(List <User> usersToAdd)
        {
            Table_Users.SuspendLayout();
            emptyTable(Table_Users);
            Table_Users.ResumeLayout();

            Table_Users.Hide();
            Table_Users.RowCount = usersToAdd.Count;
            for (int i = 0; i < usersToAdd.Count - 1; i++)
            {
                Table_Users.RowStyles.Add(new RowStyle(SizeType.Absolute));
                if (i % 10000 == 0)
                {
                    Console.WriteLine("Rows added: " + i);
                }
            }
            TableLayoutRowStyleCollection styles =
                Table_Users.RowStyles;

            for (int i = 0; i < styles.Count; i++)
            {
                if (i % 10000 == 0)
                {
                    Console.WriteLine("Styled: " + i);
                }
                // Set the row height to 20 pixels.
                styles[i].SizeType = SizeType.Absolute;
                styles[i].Height   = 40;
            }

            for (int i = 0; i < usersToAdd.Count; i++)
            {
                if (i % 10000 == 0)
                {
                    Console.WriteLine("Written: " + i);
                }
                addEventToEventTableRow(usersToAdd[i], i);
            }
            Table_Users.Show();
        }
Exemple #25
0
        public FormShop(FormMainMenu form)
        {
            InitializeComponent();

            tableLayoutShopPanel.AutoScroll = false;
            tableLayoutShopPanel.HorizontalScroll.Enabled = false;
            tableLayoutShopPanel.HorizontalScroll.Visible = false;
            tableLayoutShopPanel.HorizontalScroll.Maximum = 0;
            tableLayoutShopPanel.AutoScroll = true;
            TableLayoutRowStyleCollection styles = tableLayoutShopPanel.RowStyles;

            foreach (RowStyle style in styles)
            {
                // Set the row height to 20 pixels.
                style.SizeType = SizeType.Absolute;
                style.Height   = 200;
            }
            _form    = form;
            products = produktyWKoszyku;
            comboBoxFiltruj.SelectedIndex = 0;
            UstawProdukty();
        }
        private void SetWorldSize()
        {
            while (tblWorldLevel.RowCount != ThisFloor.CurrentFloor.GetLength(0))
            {
                if (tblWorldLevel.RowCount > ThisFloor.CurrentFloor.GetLength(0)) RemoveRow();
                else AddRow();
                
            }

            while (tblWorldLevel.ColumnCount != ThisFloor.CurrentFloor.GetLength(1))
            {
                if (tblWorldLevel.ColumnCount > ThisFloor.CurrentFloor.GetLength(1)) RemoveCol();
                else AddCol();
            }

            tblWorldLevel.Refresh();

            TableLayoutRowStyleCollection RowStyles = this.tblWorldLevel.RowStyles;
            foreach (RowStyle style in RowStyles)
            {
                style.SizeType = SizeType.Percent;

                // Set the row height to be a percentage  
                // of the TableLayoutPanel control's height.  
                style.Height = (float)(100.00 / tblWorldLevel.RowCount);

            }

            TableLayoutColumnStyleCollection ColStyles = this.tblWorldLevel.ColumnStyles;
            foreach (ColumnStyle style in ColStyles)
            {
                style.SizeType = SizeType.Percent;

                // Set the row height to be a percentage  
                // of the TableLayoutPanel control's height.  
                style.Width = (float)(100.00 / tblWorldLevel.ColumnCount);

            }            
        }
        /// <summary>
        /// <see cref="TableLayoutRowStyleCollection"/> の要素を配列に変換する
        /// </summary>
        /// <param name="collection">
        /// 拡張機能を追加する <see cref="TableLayoutRowStyleCollection"/> オブジェクト
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// 引数の <see cref="TableLayoutRowStyleCollection"/> オブジェクトがNULLの場合に発生
        /// </exception>
        /// <returns>
        /// <see cref="TableLayoutRowStyleCollection"/> の要素のシャドウコピーを格納した配列
        /// </returns>
        public static RowStyle[] ToArray(this TableLayoutRowStyleCollection collection)
        {
            // NULLチェック
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            // スタイルのリストの配列を生成する
            RowStyle[] rowStyles = new RowStyle[collection.Count];

            // 生成した配列にコレクションの要素をコピーしながら格納する
            int styleIndex = 0;

            foreach (RowStyle style in collection)
            {
                rowStyles[styleIndex] = new RowStyle(style.SizeType, style.Height);
                styleIndex++;
            }

            // 取得した配列を返却する
            return(rowStyles);
        }
Exemple #28
0
        //IOsignals
        private void DrawIOsignals(List <string> names)
        {
            int rowCount = _checkedIOIndexes.Count;

            if (rowCount == 0)
            {
                rowCount = 1;
            }
            //IOsignals names
            var tlpIOnames = new TableLayoutPanel();

            tlpIOnames.Dock            = DockStyle.Fill;
            tlpIOnames.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;
            tlpIOnames.ColumnCount     = 1;
            tlpIOnames.RowCount        = rowCount;
            for (int i = 0; i < rowCount; i++)
            {
                tlpIOnames.RowStyles.Add(new RowStyle());
            }
            float rowHight2 = 100 / rowCount;
            TableLayoutRowStyleCollection styles2 = tlpIOnames.RowStyles;

            foreach (RowStyle style in styles2)
            {
                style.SizeType = SizeType.Percent;
                style.Height   = rowHight2;
            }
            panelIOnames.Controls.Clear();
            panelIOnames.Controls.Add(tlpIOnames);
            for (int i = 0; i < _checkedIOIndexes.Count; i++)
            {
                var nameLabel = new Label {
                    Text = names[_checkedIOIndexes[i]], ForeColor = _colors[i], TextAlign = ContentAlignment.MiddleCenter, Dock = DockStyle.Fill
                };
                tlpIOnames.Controls.Add(nameLabel, 0, i);
            }
        }
        private void ShowLunchSorts()
        {
            TableLayoutRowStyleCollection Rowstyles = tableLayoutPanel1.RowStyles;

            foreach (RowStyle style in Rowstyles)
            {
                style.SizeType = SizeType.Absolute;
                style.Height   = button_LunchKind.Height;
            }

            button_LunchKind.Text = "Starters";
            button_LunchKind.Name = "btn_LunchStarters";
            tableLayoutPanel1.Controls.Add(button_LunchKind, 0, 0);

            btn_LunchMain.Size   = button_LunchKind.Size;
            btn_LunchMain.Text   = "Main";
            btn_LunchMain.Click += new EventHandler(Btn_LunchMain_Click);
            tableLayoutPanel1.Controls.Add(btn_LunchMain, 0, 1);

            btn_LunchDessert.Size   = button_LunchKind.Size;
            btn_LunchDessert.Text   = "Dessert";
            btn_LunchDessert.Click += new EventHandler(Btn_LunchDessert_Click);
            tableLayoutPanel1.Controls.Add(btn_LunchDessert, 0, 2);
        }
		private void CalculateColumnRowSizes (TableLayoutPanel panel, int columns, int rows)
		{
			TableLayoutSettings settings = panel.LayoutSettings;

			panel.column_widths = new int[panel.actual_positions.GetLength (0)];
			panel.row_heights = new int[panel.actual_positions.GetLength (1)];

			int border_width = TableLayoutPanel.GetCellBorderWidth (panel.CellBorderStyle);
				
			Rectangle parentDisplayRectangle = panel.DisplayRectangle;

			TableLayoutColumnStyleCollection col_styles = new TableLayoutColumnStyleCollection (panel);
			
			foreach (ColumnStyle cs in settings.ColumnStyles)
				col_styles.Add( new ColumnStyle(cs.SizeType, cs.Width));

			TableLayoutRowStyleCollection row_styles = new TableLayoutRowStyleCollection (panel);

			foreach (RowStyle rs in settings.RowStyles)
				row_styles.Add (new RowStyle (rs.SizeType, rs.Height));
		
			// If we have more columns than columnstyles, temporarily add enough columnstyles
			if (columns > col_styles.Count)
			{
				for (int i = col_styles.Count; i < columns; i++)
					col_styles.Add(new ColumnStyle());			
			}

			// Same for rows..
			if (rows > row_styles.Count) 
			{
				for (int i = row_styles.Count; i < rows; i++)
					row_styles.Add (new RowStyle ());
			}

			while (row_styles.Count > rows)
				row_styles.RemoveAt (row_styles.Count - 1);
			while (col_styles.Count > columns)
				col_styles.RemoveAt (col_styles.Count - 1);
				
			// Figure up all the column widths
			int total_width = parentDisplayRectangle.Width - (border_width * (columns + 1));
			int index = 0;

			// First assign all the Absolute sized columns..
			foreach (ColumnStyle cs in col_styles) {
				if (cs.SizeType == SizeType.Absolute) {
					panel.column_widths[index] = (int)cs.Width;
					total_width -= (int)cs.Width;
				}

				index++;
			}

			index = 0;

			// Next, assign all the AutoSize columns..
			foreach (ColumnStyle cs in col_styles)
			{
				if (cs.SizeType == SizeType.AutoSize)
				{
					int max_width = 0; 
					
					// Find the widest control in the column
					for (int i = 0; i < rows; i ++)
					{
						Control c = panel.actual_positions[index, i];

						if (c != null && c != dummy_control && c.VisibleInternal)
						{
							if (settings.GetColumnSpan (c) > 1)
								continue;
								
							if (c.AutoSize)
								max_width = Math.Max (max_width, c.PreferredSize.Width + c.Margin.Horizontal);
							else
								max_width = Math.Max (max_width, c.ExplicitBounds.Width + c.Margin.Horizontal);
							
							if (c.Width + c.Margin.Left + c.Margin.Right > max_width)
								max_width = c.Width + c.Margin.Left + c.Margin.Right;						
						}
					}

					panel.column_widths[index] = max_width;
					total_width -= max_width;				
				}
				
				index++;
			}
			
			index = 0;
			float total_percent = 0;
			
			// Finally, assign the remaining space to Percent columns..
			if (total_width > 0)
			{
				int percent_width = total_width; 
				
				// Find the total percent (not always 100%)
				foreach (ColumnStyle cs in col_styles) 
				{
					if (cs.SizeType == SizeType.Percent)
						total_percent += cs.Width;
				}

				// Divy up the space..
				foreach (ColumnStyle cs in col_styles) 
				{
					if (cs.SizeType == SizeType.Percent) 
					{
						panel.column_widths[index] = (int)((cs.Width / total_percent) * percent_width);
						total_width -= panel.column_widths[index];
					}

					index++;
				}
			}

			if (total_width > 0)
				panel.column_widths[col_styles.Count - 1] += total_width;

			// Figure up all the row heights
			int total_height = parentDisplayRectangle.Height - (border_width * (rows + 1));
			index = 0;

			// First assign all the Absolute sized rows..
			foreach (RowStyle rs in row_styles) {
				if (rs.SizeType == SizeType.Absolute) {
					panel.row_heights[index] = (int)rs.Height;
					total_height -= (int)rs.Height;
				}

				index++;
			}

			index = 0;

			// Next, assign all the AutoSize rows..
			foreach (RowStyle rs in row_styles) {
				if (rs.SizeType == SizeType.AutoSize) {
					int max_height = 0;

					// Find the tallest control in the row
					for (int i = 0; i < columns; i++) {
						Control c = panel.actual_positions[i, index];

						if (c != null && c != dummy_control && c.VisibleInternal) {
							if (settings.GetRowSpan (c) > 1)
								continue; 
								
							if (c.AutoSize)
								max_height = Math.Max (max_height, c.PreferredSize.Height + c.Margin.Vertical);
							else
								max_height = Math.Max (max_height, c.ExplicitBounds.Height + c.Margin.Vertical);

							if (c.Height + c.Margin.Top + c.Margin.Bottom > max_height)
								max_height = c.Height + c.Margin.Top + c.Margin.Bottom;
						}
					}

					panel.row_heights[index] = max_height;
					total_height -= max_height;
				}

				index++;
			}

			index = 0;
			total_percent = 0;

			// Finally, assign the remaining space to Percent columns..
			if (total_height > 0) {
				int percent_height = total_height;
				
				// Find the total percent (not always 100%)
				foreach (RowStyle rs in row_styles) {
					if (rs.SizeType == SizeType.Percent)
						total_percent += rs.Height;
				}

				// Divy up the space..
				foreach (RowStyle rs in row_styles) {
					if (rs.SizeType == SizeType.Percent) {
						panel.row_heights[index] = (int)((rs.Height / total_percent) * percent_height);
						total_height -= panel.row_heights[index];
					}

					index++;
				}
			}

			if (total_height > 0)
				panel.row_heights[row_styles.Count - 1] += total_height;
		}
        private void bGWGunParts_DoWork(object sender, DoWorkEventArgs e)
        {
            TableLayoutPanel tLP       = new TableLayoutPanel();
            Label            lblTitle  = new Label();
            Label            labelPN   = new Label();
            Label            labelDesc = new Label();
            Label            labelPic  = new Label();
            Label            lblCount  = new Label();

            String gun = (String)e.Argument;

            lblTitle.Text = gun + " Parts";
            RequestsDB requestDB    = new RequestsDB();
            DataTable  gunPartTable = requestDB.GetGunParts(gun);

            tLP.SuspendLayout();
            tLP.Padding      = new Padding(0, 0, 1, 0);
            tLP.AutoScroll   = true;
            tLP.AutoSize     = true;
            tLP.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            tLP.ColumnCount  = 3;
            tLP.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 300f));
            tLP.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 400f));
            tLP.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 90f));
            tLP.Controls.Add(lblTitle, 0, 0);
            tLP.Controls.Add(labelPN, 0, 1);
            tLP.Controls.Add(labelDesc, 1, 1);
            tLP.Controls.Add(labelPic, 2, 1);
            tLP.Location = new System.Drawing.Point(0, 0);
            tLP.Name     = "tLPGun";
            tLP.RowCount = 2;
            tLP.RowStyles.Add(new System.Windows.Forms.RowStyle());
            tLP.RowStyles.Add(new System.Windows.Forms.RowStyle());
            tLP.TabIndex    = 0;
            tLP.MouseEnter += new System.EventHandler(tLP_MouseEnter);
            //
            TableLayoutRowStyleCollection styles = tLP.RowStyles;

            foreach (RowStyle style in styles)
            {
                style.SizeType = SizeType.Absolute;
                style.Height   = 50;
            }
            //
            // lblCount
            //
            //lblCount.AutoSize = true;
            //lblCount.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            //lblCount.Dock = System.Windows.Forms.DockStyle.Fill;
            //lblCount.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            //lblCount.Location = new System.Drawing.Point(3, 0);
            //lblCount.Name = "lblCount";
            //lblCount.TabIndex = 0;
            //lblCount.Text = "#";
            //lblCount.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            // lblTitle
            //
            lblTitle.AutoSize    = true;
            lblTitle.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            tLP.SetColumnSpan(lblTitle, 3);
            lblTitle.Dock      = System.Windows.Forms.DockStyle.Fill;
            lblTitle.Font      = new System.Drawing.Font("Arial Black", 15.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            lblTitle.Location  = new System.Drawing.Point(3, 0);
            lblTitle.Name      = "lblTitle";
            lblTitle.TabIndex  = 0;
            lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            // labelPN
            //
            labelPN.AutoSize    = true;
            labelPN.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            labelPN.Dock        = System.Windows.Forms.DockStyle.Fill;
            labelPN.Font        = new System.Drawing.Font("Arial Narrow", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            labelPN.Location    = new System.Drawing.Point(3, 29);
            labelPN.Name        = "label2";
            //labelPN.Size = new System.Drawing.Size(248, 552);
            labelPN.TabIndex  = 1;
            labelPN.Text      = "Part Number";
            labelPN.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            // labelDesc
            //
            labelDesc.AutoSize    = true;
            labelDesc.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            labelDesc.Dock        = System.Windows.Forms.DockStyle.Fill;
            labelDesc.Font        = new System.Drawing.Font("Arial Narrow", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            labelDesc.Location    = new System.Drawing.Point(257, 29);
            labelDesc.Name        = "label3";
            labelDesc.Size        = new System.Drawing.Size(375, 552);
            labelDesc.TabIndex    = 2;
            labelDesc.Text        = "Description";
            labelDesc.TextAlign   = System.Drawing.ContentAlignment.MiddleCenter;
            //
            // labelPic
            //
            labelPic.AutoSize    = true;
            labelPic.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            labelPic.Dock        = System.Windows.Forms.DockStyle.Fill;
            labelPic.Font        = new System.Drawing.Font("Arial Narrow", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            labelPic.Location    = new System.Drawing.Point(638, 29);
            labelPic.Name        = "label1";
            labelPic.Size        = new System.Drawing.Size(272, 552);
            labelPic.TabIndex    = 3;
            labelPic.Text        = "3D Image";
            labelPic.TextAlign   = System.Drawing.ContentAlignment.MiddleCenter;

            foreach (DataRow row in gunPartTable.Rows)
            {
                int    index;
                Label  lblPartNumber  = new Label();
                Label  lblDescription = new Label();
                Panel  pnlPN          = new Panel();
                Panel  pnlDesc        = new Panel();
                Panel  pnlBtn         = new Panel();
                Button btnPic         = new Button();
                index = gunPartTable.Rows.IndexOf(row) + 3;
                lblDescription.Font            = lblPartNumber.Font = btnPic.Font = new System.Drawing.Font("Arial Narrow", 14.25F, System.Drawing.FontStyle.Bold);
                lblPartNumber.Dock             = btnPic.Dock = pnlBtn.Dock = pnlPN.Dock = pnlDesc.Dock = lblDescription.Dock = DockStyle.Fill;
                lblPartNumber.TextAlign        = lblDescription.TextAlign = ContentAlignment.MiddleCenter;
                btnPic.UseVisualStyleBackColor = true;
                btnPic.Name  = row["PartNumber"].ToString();
                btnPic.Image = imageIcon;
                toolTipPartsList.SetToolTip(btnPic, "3D Image of Part");
                lblPartNumber.Text = row["PartNumber"].ToString();
                imagePath          = @"\\hlsql01\Beamtech\Summit\FE_Cleaning\JT\" + lblPartNumber.Text + ".jt";
                if (File.Exists(imagePath))
                {
                    btnPic.Enabled = true;
                }
                else
                {
                    btnPic.Enabled = false;
                }
                lblDescription.Text = row["Description"].ToString();
                btnPic.Click       += new System.EventHandler(btnPic_Click);
                pnlBtn.Height       = pnlDesc.Height = pnlPN.Height = 50;
                pnlBtn.BorderStyle  = pnlDesc.BorderStyle = pnlPN.BorderStyle = BorderStyle.Fixed3D;
                pnlPN.Controls.Add(lblPartNumber);
                pnlDesc.Controls.Add(lblDescription);
                pnlBtn.Controls.Add(btnPic);
                tLP.Controls.Add(pnlPN, 0, index);
                tLP.Controls.Add(pnlDesc, 1, index);
                tLP.Controls.Add(pnlBtn, 2, index);
            }
            tLP.ResumeLayout();
            e.Result = tLP;
        }
Exemple #32
0
		private void CalculateColumnRowSizes (TableLayoutPanel panel, int columns, int rows)
		{
			TableLayoutSettings settings = panel.LayoutSettings;

			panel.column_widths = new int[panel.actual_positions.GetLength (0)];
			panel.row_heights = new int[panel.actual_positions.GetLength (1)];

			int border_width = TableLayoutPanel.GetCellBorderWidth (panel.CellBorderStyle);
				
			Rectangle parentDisplayRectangle = panel.DisplayRectangle;

			TableLayoutColumnStyleCollection col_styles = new TableLayoutColumnStyleCollection (panel);
			
			foreach (ColumnStyle cs in settings.ColumnStyles)
				col_styles.Add( new ColumnStyle(cs.SizeType, cs.Width));

			TableLayoutRowStyleCollection row_styles = new TableLayoutRowStyleCollection (panel);

			foreach (RowStyle rs in settings.RowStyles)
				row_styles.Add (new RowStyle (rs.SizeType, rs.Height));
		
			// If we have more columns than columnstyles, temporarily add enough columnstyles
			if (columns > col_styles.Count)
			{
				for (int i = col_styles.Count; i < columns; i++)
					col_styles.Add(new ColumnStyle());			
			}

			// Same for rows..
			if (rows > row_styles.Count) 
			{
				for (int i = row_styles.Count; i < rows; i++)
					row_styles.Add (new RowStyle ());
			}

			while (row_styles.Count > rows)
				row_styles.RemoveAt (row_styles.Count - 1);
			while (col_styles.Count > columns)
				col_styles.RemoveAt (col_styles.Count - 1);
				
			// Find the largest column-span/row-span values.
			int max_colspan = 0, max_rowspan = 0;
			foreach (Control c in panel.Controls) {
				max_colspan = Math.Max (max_colspan, settings.GetColumnSpan (c));
				max_rowspan = Math.Max (max_rowspan, settings.GetRowSpan (c));
			}

			// Figure up all the column widths
			int total_width = parentDisplayRectangle.Width - (border_width * (columns + 1));
			int index = 0;

			// First assign all the Absolute sized columns..
			foreach (ColumnStyle cs in col_styles) {
				if (cs.SizeType == SizeType.Absolute) {
					panel.column_widths[index] = (int)cs.Width;
					total_width -= (int)cs.Width;
				}

				index++;
			}

			// Next, assign all the AutoSize columns to the width of their widest
			// control.  If the table-layout is auto-sized, then make sure that
			// no column with Percent styling clips its contents.
			// (per http://msdn.microsoft.com/en-us/library/ms171690.aspx)
			for (int colspan = 0; colspan < max_colspan; ++colspan)
			{
				for (index = colspan; index < col_styles.Count - colspan; ++index)
				{
					ColumnStyle cs = col_styles[index];
					if (cs.SizeType == SizeType.AutoSize
					|| (panel.AutoSize && cs.SizeType == SizeType.Percent))
					{
						int max_width = panel.column_widths[index];

						// Find the widest control in the column
						for (int i = 0; i < rows; i ++)
						{
							Control c = panel.actual_positions[index - colspan, i];

							if (c != null && c != dummy_control && c.VisibleInternal)
							{
								// Skip any controls not being sized in this pass.
								if (settings.GetColumnSpan (c) != colspan + 1)
									continue;

								// Calculate the maximum control width.
								if (c.AutoSize)
									max_width = Math.Max (max_width, c.PreferredSize.Width + c.Margin.Horizontal);
								else
									max_width = Math.Max (max_width, c.ExplicitBounds.Width + c.Margin.Horizontal);
								max_width = Math.Max (max_width, c.Width + c.Margin.Left + c.Margin.Right);
							}
						}

						// Subtract the width of prior columns, if any.
						for (int i = Math.Max (index - colspan, 0); i < index; ++i)
							max_width -= panel.column_widths[i];

						// If necessary, increase this column's width.
						if (max_width > panel.column_widths[index])
						{
							max_width -= panel.column_widths[index];
							panel.column_widths[index] += max_width;
							total_width -= max_width;
						}
					}
				}
			}
			
			index = 0;
			float total_percent = 0;
			
			// Finally, assign the remaining space to Percent columns, if any.
			if (total_width > 0)
			{
				int percent_width = total_width; 
				
				// Find the total percent (not always 100%)
				foreach (ColumnStyle cs in col_styles) 
				{
					if (cs.SizeType == SizeType.Percent)
						total_percent += cs.Width;
				}

				// Divvy up the space..
				foreach (ColumnStyle cs in col_styles) 
				{
					if (cs.SizeType == SizeType.Percent) 
					{
						int width_change = (int)(((cs.Width / total_percent) * percent_width)
							- panel.column_widths[index]);
						if (width_change > 0)
						{
							panel.column_widths[index] += width_change;
							total_width -= width_change;
						}
					}

					index++;
				}
			}

			if (total_width > 0)
			{
				// Find the last column that isn't an Absolute SizeType, and give it
				// all this free space.  (Absolute sized columns need to retain their
				// absolute width if at all possible!)
				int col = col_styles.Count - 1;
				for (; col >= 0; --col)
				{
					if (col_styles[col].SizeType != SizeType.Absolute)
						break;
				}
				if (col < 0)
					col = col_styles.Count - 1;
				panel.column_widths[col] += total_width;
			}

			// Figure up all the row heights
			int total_height = parentDisplayRectangle.Height - (border_width * (rows + 1));
			index = 0;

			// First assign all the Absolute sized rows..
			foreach (RowStyle rs in row_styles) {
				if (rs.SizeType == SizeType.Absolute) {
					panel.row_heights[index] = (int)rs.Height;
					total_height -= (int)rs.Height;
				}

				index++;
			}

			index = 0;

			// Next, assign all the AutoSize rows to the height of their tallest
			// control.  If the table-layout is auto-sized, then make sure that
			// no row with Percent styling clips its contents.
			// (per http://msdn.microsoft.com/en-us/library/ms171690.aspx)
			for (int rowspan = 0; rowspan < max_rowspan; ++rowspan)
			{
				for (index = rowspan; index < row_styles.Count - rowspan; ++index)
				{
					RowStyle rs = row_styles[index];
					if (rs.SizeType == SizeType.AutoSize
					|| (panel.AutoSize && rs.SizeType == SizeType.Percent))
					{
						int max_height = panel.row_heights[index];

						// Find the tallest control in the row
						for (int i = 0; i < columns; i++) {
							Control c = panel.actual_positions[i, index - rowspan];

							if (c != null && c != dummy_control && c.VisibleInternal)
							{
								// Skip any controls not being sized in this pass.
								if (settings.GetRowSpan (c) != rowspan + 1)
									continue;

								// Calculate the maximum control height.
								if (c.AutoSize)
									max_height = Math.Max (max_height, c.PreferredSize.Height + c.Margin.Vertical);
								else
									max_height = Math.Max (max_height, c.ExplicitBounds.Height + c.Margin.Vertical);
								max_height = Math.Max (max_height, c.Height + c.Margin.Top + c.Margin.Bottom);
							}
						}

						// Subtract the height of prior rows, if any.
						for (int i = Math.Max (index - rowspan, 0); i < index; ++i)
							max_height -= panel.row_heights[i];

						// If necessary, increase this row's height.
						if (max_height > panel.row_heights[index])
						{
							max_height -= panel.row_heights[index];
							panel.row_heights[index] += max_height;
							total_height -= max_height;
						}
					}
				}
			}

			index = 0;
			total_percent = 0;

			// Finally, assign the remaining space to Percent rows, if any.
			if (total_height > 0) {
				int percent_height = total_height;
				
				// Find the total percent (not always 100%)
				foreach (RowStyle rs in row_styles) {
					if (rs.SizeType == SizeType.Percent)
						total_percent += rs.Height;
				}

				// Divvy up the space..
				foreach (RowStyle rs in row_styles) {
					if (rs.SizeType == SizeType.Percent) {
						int height_change = (int)(((rs.Height / total_percent) * percent_height)
							- panel.row_heights[index]);
						if (height_change > 0)
						{
							panel.row_heights[index] += height_change;
							total_height -= height_change;
						}
					}

					index++;
				}
			}

			if (total_height > 0)
			{
				// Find the last row that isn't an Absolute SizeType, and give it
				// all this free space.  (Absolute sized rows need to retain their
				// absolute height if at all possible!)
				int row = row_styles.Count - 1;
				for (; row >= 0; --row)
				{
					if (row_styles[row].SizeType != SizeType.Absolute)
						break;
				}
				if (row < 0)
					row = row_styles.Count - 1;
				panel.row_heights[row] += total_height;
			}
		}