/// <summary> /// Performs the layout for the given container, that has to be a TableLayoutPanel. /// </summary> /// <param name="parent">The control whose layout has to be done.</param> /// <param name="layoutEventArgs">The LayoutEventArgs.</param> /// <returns>Always false.</returns> public override bool Layout(Control parent, LayoutEventArgs layoutEventArgs) { TableLayoutPanel tableLayoutPanel = parent as TableLayoutPanel; if (tableLayoutPanel == null) { throw new ArgumentException("The given container is not a TableLayoutPanel", "parent"); } if (tableLayoutPanel.Controls.Count == 0) { return(false); } TableLayoutSettings settings = tableLayoutPanel.LayoutSettings; // STEP 1: // - Figure out which row/column each control goes into Control[,] grid = this.CalculateControlLocations(tableLayoutPanel, settings, settings.ColumnCount, settings.RowCount); // STEP 2: // - Figure out the sizes of each row/column int[] columnWidths; int[] rowHeights; CalculateCellSizes(tableLayoutPanel, settings, grid, out columnWidths, out rowHeights); // STEP 3: // - Size and position each control LayoutControls(tableLayoutPanel, grid, columnWidths, rowHeights); return(false); }
public void CreateControl(int cols, int rows) { controls = new Control[cols, rows]; columnScale = new bool[cols]; rowScale = new bool[rows]; lastColumnScale = cols - 1; lastRowScale = rows - 1; for (int i = 0; i < cols; i++) { Control.ColumnDefinitions.Add(new swc.ColumnDefinition { Width = GetColumnWidth(i) }); } for (int i = 0; i < rows; i++) { Control.RowDefinitions.Add(new swc.RowDefinition { Height = GetRowHeight(i) }); } for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { Control.Children.Add(EmptyCell(x, y)); } } border.Child = Control; Control.LayoutUpdated += (sender, args) => SetChildrenSizes(); }
/// <summary> /// Replaces the EformControl in the section cell with that passed as an /// argument to the method. /// </summary> /// <param name="column">The zero-based index of the column in which to insert the control.</param> /// <param name="row">The zero-based index of the row in which to insert the control.</param> /// <param name="control">An Eform control.</param> public void InsertControl(Control control, int row, int column) { if (cells == null) { cells = new Control[Rows, Columns]; } // TODO: narrow the third arg to EformControl or whatever is appropriate if (row >= Rows) { throw new ArgumentException(string.Format("{0} exceeds the number of rows ({1}) in the section.", row, Rows), "row"); } if (column >= Columns) { throw new ArgumentException(string.Format("{0} exceeds the number of columns ({1}) in the section.", column, Columns), "column"); } if (initialized) { throw new InvalidOperationException("Controls cannot be added to the section after initialization. Insert controls before adding section to a page."); } cells[row, column] = control; if (!containsGrid) { containsGrid = ContainsGrid(control); } }
private bool ParseKey(Game game, Control[,] labels, Keys key) { var moved = false; switch (key) { case Keys.W: moved = game.MakeMove(Direction.Up); break; case Keys.A: moved = game.MakeMove(Direction.Left); break; case Keys.S: moved = game.MakeMove(Direction.Down); break; case Keys.D: moved = game.MakeMove(Direction.Right); break; case Keys.Q: game.Undo(); UpdateColors(game, labels); break; default: return(false); } return(moved); }
private static void Animate(Game game, Control field, Control[,] staticLabels) { var animations = new List <Animation>(); var movingLabels = new Label[game.Width, game.Height]; foreach (var transition in game.Transitions.Peek().Where(t => t.Condition != Condition.Appeared)) { var j = transition.Start.X; var i = transition.Start.Y; staticLabels[j, i].BackColor = Tile.GetColor(0); staticLabels[j, i].Text = ""; var location = new Point(RectSize.Width * j + (j + 1) * Distance, RectSize.Height * i + (i + 1) * Distance); movingLabels[transition.Start.X, transition.Start.Y] = CreateLabel( Tile.GetColor(transition.StartValue), transition.StartValue == 0 ? "" : transition.StartValue.ToString(), location); field.Controls.Add(movingLabels[j, i]); animations.Add(new Animation(transition)); } MoveLabels(field, animations, movingLabels); foreach (var label in movingLabels) { field.Controls.Remove(label); } }
public void SetMap(TableCellMap map) { map.SingleCellChangeEvent = _ => { SetBtn(_.X, _.Y, _.NewCell); }; map.Reset = _ => { if (this.buttons != null) { foreach (var btn in this.buttons) { btn.Dispose(); } this.buttons = null; } this.buttons = new Control[_.TableCellMap.Width, _.TableCellMap.Height]; for (var x = 0; x < _.TableCellMap.Width; x++) { for (var y = 0; y < _.TableCellMap.Height; y++) { SetBtn(x, y, _.TableCellMap[x, y]); } } }; this.map = map; }
//начальное создание игрового поля private void InitializeGameBoard(int width, int height, int countMine) { //Стартовый отступ по ширине и высоте int startX = 15, startY = 75; cells = new Button[width, height]; board = new Control[width, height]; //Заполнение и расстановка кнопок на форме for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { cells[x, y] = createButton(startX + 24 * x, startY + 24 * y, x, y); } } //Изменение размеров формы в зависимости от количства ячеек Width = startX * 2 + (width + 1) * 24 - 8; Height = startY + (height + 2) * 24; //Автоматическое выставление расположения gbTime gbTime.Location = new Point(startX, startY - 50); //Автоматическое выставление расположения btnFace btnFace.Location = new Point(startX + Width / 2 - btnFace.Width - 8, startY - 45); btnFace.BackgroundImage = Properties.Resources.smileybase; //Автоматическое выставление расположения gbMines gbMines.Location = new Point(Width - 2 * startX - gbMines.Width, startY - 50); //задание количества мин lbCountMine.Text = countMine.ToString(); }
private void initializeUIBoard(int i_BoardSize) { int clientSize = (i_BoardSize * k_ButtonSize) + k_SpacingBetweenButtonAndClientWindow; this.ClientSize = new System.Drawing.Size(clientSize, clientSize); m_BoardControls = new Control[i_BoardSize, i_BoardSize]; createBoardMatrix(i_BoardSize); }
/// <summary> /// This enables or disables all controls in the array that is passed in. /// </summary> /// <param name="controlArray">An array of controls to enable or disable</param> /// <param name="enabledStatus">Boolean: set controls to enabled?</param> private void SetControlsEnabled(Control[,] controlArray, bool enabledStatus) { // For every control in the list that is passed in, empty its text property. foreach (Control controlToClear in controlArray) { controlToClear.Enabled = enabledStatus; } }
/// <summary> /// This clears the text property of all controls in the array of controls that is passed in /// </summary> /// <param name="controlArray">An array of controls with a text property to clear</param> private void ClearControls(Control[,] controlArray) { // For every control in the list that is passed in, empty its text property. foreach (Control controlToClear in controlArray) { controlToClear.Text = String.Empty; } }
public void CreateControl(int cols, int rows) { views = new Control[rows, cols]; xscaling = new bool[cols]; lastxscale = cols - 1; yscaling = new bool[rows]; lastyscale = rows - 1; }
/// <summary> /// This clears the text property of all controls in the array of controls that is passed in /// </summary> /// <param name="controlArray">An array of controls with a text property to clear</param> private void ClearControls(Control[,] controlArray) { // For every control in the list that is passed in, empty its text property and change colour to default. foreach (Control controlToClear in controlArray) { controlToClear.Text = String.Empty; controlToClear.BackColor = Button.DefaultBackColor; } }
/// <summary> /// This clears the text property of all controls in the array of controls that is passed in /// </summary> /// <param name="controlArray">An array of controls with a text property to clear</param> private void ClearControls(Control[,] controlArray) { // For every control in the list that is passed in, empty its text property. foreach (Control controlToClear in controlArray) { controlToClear.Text = String.Empty; // Thanks Kyle and Kamrin controlToClear.BackColor = Color.Gainsboro; } }
// Default Constructor public Battlefield() { InitializeComponent(); OnPlayerStart(); gameStarted = false; battleMatrix = new Control[3, 3]; }
private void PopulateCpuUsageTable() { CommandResultTuple cmdresult = null; MiscTools.SpawnBackgroundWorker(() => cmdresult = ManagerHandler.SshHandler.RunCommand("mpstat -o JSON"), () => { if (cmdresult.ExitCode == 0) { var result = JsonConvert.DeserializeObject <MPStatResult>(cmdresult.StdOut); var numthreads = result.SysStat.Hosts[0].NumberOfCpus; _CpuUsageTableControls = new Control[3, numthreads]; _CpuUsageTableControls = new Control[3, numthreads + 1]; _CpuUsageTableControls[0, 0] = averageCpuUsage_Label; _CpuUsageTableControls[1, 0] = averageCpuUsage_ProgressBar; _CpuUsageTableControls[2, 0] = averageCpuFreq_Label; for (int i = 0; i < numthreads; i++) { var rowstyle = new RowStyle(SizeType.Absolute, 20); this.Invoke((MethodInvoker)(() => { cpuLoad_TableLayoutPanel.RowCount += 1; cpuLoad_TableLayoutPanel.RowStyles.Add(rowstyle); var threadNumLbl = new Label { Text = "" + i, AutoSize = true }; var usageProgBar = new ProgressBar { Dock = DockStyle.Fill }; var freqLbl = new Label { Text = "? MHz", AutoSize = true }; _CpuUsageTableControls[0, i + 1] = threadNumLbl; _CpuUsageTableControls[1, i + 1] = usageProgBar; _CpuUsageTableControls[2, i + 1] = freqLbl; cpuLoad_TableLayoutPanel.Controls.Add(threadNumLbl); cpuLoad_TableLayoutPanel.Controls.Add(usageProgBar); cpuLoad_TableLayoutPanel.Controls.Add(freqLbl); })); } this.Invoke((MethodInvoker)(() => { cpuLoad_TableLayoutPanel.RowCount += 1; cpuLoad_TableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent)); })); } }); }
public FormGame(int i_Rows, int i_Columns, string i_MainPlayer, string i_OpponentPlayer) { m_CellsRows = i_Rows; m_CellsColumns = i_Columns; m_GameManagement = new GameManagement(i_Columns, i_Rows, i_MainPlayer, i_OpponentPlayer); m_Controls = new Control[m_CellsRows, m_CellsColumns]; InitializeComponent(); dataCellPlacement(); refreshLabelsState(); ShowDialog(); }
private void UpdateColors(Game game, Control[,] labels) { for (var i = 0; i < game.Height; i++) { for (var j = 0; j < game.Width; j++) { labels[j, i].Text = game[j, i].Value == 0 ? "" : game[j, i].Value.ToString(); labels[j, i].BackColor = game[j, i].Color; } } Invalidate(); }
private void RedrawPanel() { gridMainPanel.Children.Clear(); gridMainPanel.ColumnDefinitions.Clear(); gridMainPanel.RowDefinitions.Clear(); listOfControls = new Control[size + 2, size + 2]; for (int i = 0; i <= size + 1; i++) { gridMainPanel.RowDefinitions.Add(new RowDefinition()); gridMainPanel.ColumnDefinitions.Add(new ColumnDefinition()); if (i == 0 || i == size + 1) { for (int j = 1; j <= size; j++) { Button b = new Button(); b.Click += ChooseNumberWindow; Grid.SetColumn(b, j); Grid.SetRow(b, i); gridMainPanel.Children.Add(b); listOfControls[i, j] = b; } } else { for (int j = 0; j <= size + 1; j++) { if (j == 0 || j == size + 1) { Button b = new Button(); b.Click += ChooseNumberWindow; Grid.SetColumn(b, j); Grid.SetRow(b, i); gridMainPanel.Children.Add(b); listOfControls[i, j] = b; } else { Label l = new Label(); Grid.SetColumn(l, j); Grid.SetRow(l, i); l.BorderBrush = Brushes.Black; l.BorderThickness = new Thickness(0, 0, 1, 1); l.HorizontalContentAlignment = HorizontalAlignment.Center; l.VerticalContentAlignment = VerticalAlignment.Center; l.Content = " "; gridMainPanel.Children.Add(l); listOfControls[i, j] = l; } } } } }
protected override void OnInit(EventArgs e) { base.OnInit(e); if (cells == null) { cells = new Control[Rows, Columns]; } CellContainer.Controls.Add(BuildLayout()); initialized = true; }
public ControlHandler(State stateref, bool useMouse = true) : base(stateref, "ControlHandler") { _controls = new Control[1, 1]; UseMouse = useMouse; //Check to see if the mouse service is present, if not, log and disable mouse if (!stateref.CheckService<MouseService>()) { UseMouse = false; EntityGame.Log.Write("Mouse was disabled on this state, switching UseMouse to false. Next time, please specify UseMouse in constructor", this, Alert.Warning); } }
public GameWindow(GameManager i_GameEngine, Dictionary <string, int> io_PlayerPoints) { InitializeComponent(); r_Timer = new System.Windows.Forms.Timer(); r_Timer.Tick += new EventHandler(timer_Ticked); r_Timer.Interval = 1000; r_PlayerPoints = io_PlayerPoints; r_GameEngine = i_GameEngine; m_PlayersWithoutMoves = 0; r_ControlsArray = new System.Windows.Forms.Control[r_GameEngine.GetSizeOfBoard(), r_GameEngine.GetSizeOfBoard()]; this.ClientSize = new Size((k_SizeOfButton * r_GameEngine.GetSizeOfBoard()) + 20, (k_SizeOfButton * r_GameEngine.GetSizeOfBoard()) + 20); initializeButtonArray(); managePlayerWindow(); }
public ControlHandler(State stateref, bool useMouse = true) : base(stateref, "ControlHandler") { _controls = new Control[1, 1]; UseMouse = useMouse; //Check to see if the mouse service is present, if not, log and disable mouse if (!stateref.CheckService <MouseService>()) { UseMouse = false; EntityGame.Log.Write("Mouse was disabled on this state, switching UseMouse to false. Next time, please specify UseMouse in constructor", this, Alert.Warning); } }
public void CreateControl(int cols, int rows) { columnScale = new bool[cols]; lastColumnScale = true; rowScale = new bool[rows]; lastRowScale = true; align = new Gtk.Alignment(0, 0, 1.0F, 1.0F); Control = new Gtk.Table((uint)rows, (uint)cols, false); controls = new Control[rows, cols]; blank = new Gtk.Widget[rows, cols]; align.Add(Control); this.Spacing = TableLayout.DefaultSpacing; this.Padding = TableLayout.DefaultPadding; }
private void ResizeControlCollection(int x, int y) { var controlcopy = (Control[, ])_controls.Clone(); _controls = new Control[x, y]; foreach (var c in controlcopy) { if (c == null) { continue; } _controls[c.TabPosition.X, c.TabPosition.Y] = c; } }
public FontItem() { InitializeComponent(); m_arrctrlPixels = new Control[16, 16]; for (int nY = 0; nY < 16; ++nY) { for (int nX = 0; nX < 16; ++nX) { m_arrctrlPixels[nY, nX] = new Panel(); m_arrctrlPixels[nY, nX].Size = new Size(15, 15); m_arrctrlPixels[nY, nX].Location = new Point(15 * nX, 15 * nY); Controls.Add(m_arrctrlPixels[nY, nX]); } } }
private void arrowPointer(int[] boxCoords, KeyEventArgs e) { _setup.UpdateSetupCoordiateTable(); //list of places I can go to from here List <int[]> options = availableTxtBoxes(boxCoords); //find the coresponding coords of the control Control[,] controlCoords = getEnabledTextBoxes(getTextBoxes()); // right, left, above, below if (e.KeyCode == Keys.Right) { // need the coords of the first available below it int[] goHere = shiftFocus(options, Direction.right); // then shift focus to it controlCoords[goHere[0], goHere[1]].Focus(); } else if (e.KeyCode == Keys.Left) { // need the coords of the first available below it int[] goHere = shiftFocus(options, Direction.left); // then shift focus to it controlCoords[goHere[0], goHere[1]].Focus(); } else if (e.KeyCode == Keys.Up) { // need the coords of the first available below it int[] goHere = shiftFocus(options, Direction.above); // then shift focus to it controlCoords[goHere[0], goHere[1]].Focus(); } else if (e.KeyCode == Keys.Down) { // need the coords of the first available below it int[] goHere = shiftFocus(options, Direction.below); // then shift focus to it controlCoords[goHere[0], goHere[1]].Focus(); } }
public MemoryGame(int i_Rows, int i_Columns, string i_FirstPlayer, string i_SecondPlayer, bool i_VersusComputer) { m_RowsOFCells = i_Rows; m_ColumnsOfCells = i_Columns; m_UserChoice = eCellChoice.FirstChoice; this.Size = new Size(110 * i_Columns, 110 * i_Rows + 150); this.FormBorderStyle = FormBorderStyle.FixedToolWindow; this.StartPosition = FormStartPosition.CenterScreen; this.AutoSize = true; InitializeComponent(); m_Game = new Controll(i_FirstPlayer, i_SecondPlayer, i_Rows, i_Columns, i_VersusComputer); CreateArrayOfCoordinates(); m_FormArrayOfControls = new Control[m_RowsOFCells, m_ColumnsOfCells]; m_VersusComputer = i_VersusComputer; ShowDialog(); }
public void CreateControl(int cols, int rows) { columnScale = new bool[cols]; lastColumnScale = cols - 1; rowScale = new bool[rows]; lastRowScale = rows - 1; Control = new Gtk.Table((uint)rows, (uint)cols, false); controls = new Control[rows, cols]; blank = new Gtk.Widget[rows, cols]; align.Add(Control); if (spacing != null) { Control.ColumnSpacing = (uint)spacing.Value.Width; Control.RowSpacing = (uint)spacing.Value.Height; spacing = null; } }
private void InitializeMap(PictureBox mob, PictureBox player) { Point startLocation = new Point(0, 0); Point endLocation = new Point(); int width = GameMain.ActiveForm.Width / 20; int height = GameMain.ActiveForm.Height / 10; int z = 0; int k = 0; this.map = new bool[25, 25]; this.panelmap = new Control[25, 25]; for (int y = 0; y < 25; y++) { z = 0; k += height; for (int x = 0; x < 25; x++) { map[x, y] = true; panelmap[x, y] = spawnnode(z, k); z += width; } } for (int y = 0; y < 25; y++) { for (int x = 0; x < 25; x++) { if (startLocation == new Point(0, 0)) { if (mob.Bounds.IntersectsWith(panelmap[x, y].Bounds)) { startLocation = new Point(x, y); } } if (endLocation == new Point(0, 0)) { if (player.Bounds.IntersectsWith(panelmap[x, y].Bounds)) { endLocation = new Point(x, y); } } } } this.searchParameters = new SearchParameters(startLocation, endLocation, map); }
// Verifica se houve vitória public static bool CheckVictory(Control[,] bf, String symbol) { if ((bf[0, 0].Text.Equals(symbol) && bf[0, 1].Text.Equals(symbol) && bf[0, 2].Text.Equals(symbol)) || (bf[1, 0].Text.Equals(symbol) && bf[1, 1].Text.Equals(symbol) && bf[1, 2].Text.Equals(symbol)) || (bf[2, 0].Text.Equals(symbol) && bf[2, 1].Text.Equals(symbol) && bf[2, 2].Text.Equals(symbol)) || (bf[0, 0].Text.Equals(symbol) && bf[1, 0].Text.Equals(symbol) && bf[2, 0].Text.Equals(symbol)) || (bf[0, 1].Text.Equals(symbol) && bf[1, 1].Text.Equals(symbol) && bf[2, 1].Text.Equals(symbol)) || (bf[0, 2].Text.Equals(symbol) && bf[1, 2].Text.Equals(symbol) && bf[2, 2].Text.Equals(symbol)) || (bf[0, 0].Text.Equals(symbol) && bf[1, 1].Text.Equals(symbol) && bf[2, 2].Text.Equals(symbol)) || (bf[0, 2].Text.Equals(symbol) && bf[1, 1].Text.Equals(symbol) && bf[2, 0].Text.Equals(symbol))) { return(true); } else { return(false); } }
public void CreateControl(int cols, int rows) { columnScale = new bool[cols]; lastColumnScale = cols - 1; rowScale = new bool[rows]; lastRowScale = rows - 1; align = new Gtk.Alignment(0, 0, 1.0F, 1.0F); Control = new Gtk.Table((uint)rows, (uint)cols, false); controls = new Control[rows, cols]; blank = new Gtk.Widget[rows, cols]; align.Add(Control); box = new Gtk.EventBox { Child = align }; Spacing = TableLayout.DefaultSpacing; Padding = TableLayout.DefaultPadding; }
private void ResizeControlCollection(int x, int y) { var controlcopy = (Control[,])_controls.Clone(); _controls = new Control[x, y]; foreach (var c in controlcopy) { if (c == null) continue; _controls[c.TabPosition.X, c.TabPosition.Y] = c; } }
internal override Size GetPreferredSizeCore (Size proposedSize) { // If the tablelayoutowner is autosize, we have to make sure it is big enough // to hold every non-autosize control actual_positions = (LayoutEngine as TableLayout).CalculateControlPositions (this, Math.Max (ColumnCount, 1), Math.Max (RowCount, 1)); // Use actual row/column counts, not user set ones int actual_cols = actual_positions.GetLength (0); int actual_rows = actual_positions.GetLength (1); // Figure out how wide the owner needs to be int[] column_widths = new int[actual_cols]; float total_column_percentage = 0f; // Figure out how tall each column wants to be for (int i = 0; i < actual_cols; i++) { if (i < ColumnStyles.Count && ColumnStyles[i].SizeType == SizeType.Percent) total_column_percentage += ColumnStyles[i].Width; int biggest = 0; for (int j = 0; j < actual_rows; j++) { Control c = actual_positions[i, j]; if (c != null) { if (!c.AutoSize) biggest = Math.Max (biggest, c.ExplicitBounds.Width + c.Margin.Horizontal + Padding.Horizontal); else biggest = Math.Max (biggest, c.PreferredSize.Width + c.Margin.Horizontal + Padding.Horizontal); } } column_widths[i] = biggest; } // Because percentage based rows divy up the remaining space, // we have to make the owner big enough so that all the rows // get bigger, even if we only need one to be bigger. int non_percent_total_width = 0; int percent_total_width = 0; for (int i = 0; i < actual_cols; i++) { if (i < ColumnStyles.Count && ColumnStyles[i].SizeType == SizeType.Percent) percent_total_width = Math.Max (percent_total_width, (int)(column_widths[i] / ((ColumnStyles[i].Width) / total_column_percentage))); else non_percent_total_width += column_widths[i]; } // Figure out how tall the owner needs to be int[] row_heights = new int[actual_rows]; float total_row_percentage = 0f; // Figure out how tall each row wants to be for (int j = 0; j < actual_rows; j++) { if (j < RowStyles.Count && RowStyles[j].SizeType == SizeType.Percent) total_row_percentage += RowStyles[j].Height; int biggest = 0; for (int i = 0; i < actual_cols; i++) { Control c = actual_positions[i, j]; if (c != null) { if (!c.AutoSize) biggest = Math.Max (biggest, c.ExplicitBounds.Height + c.Margin.Vertical + Padding.Vertical); else biggest = Math.Max (biggest, c.PreferredSize.Height + c.Margin.Vertical + Padding.Vertical); } } row_heights[j] = biggest; } // Because percentage based rows divy up the remaining space, // we have to make the owner big enough so that all the rows // get bigger, even if we only need one to be bigger. int non_percent_total_height = 0; int percent_total_height = 0; for (int j = 0; j < actual_rows; j++) { if (j < RowStyles.Count && RowStyles[j].SizeType == SizeType.Percent) percent_total_height = Math.Max (percent_total_height, (int)(row_heights[j] / ((RowStyles[j].Height) / total_row_percentage))); else non_percent_total_height += row_heights[j]; } int border_width = GetCellBorderWidth (CellBorderStyle); return new Size (non_percent_total_width + percent_total_width + (border_width * (actual_cols + 1)), non_percent_total_height + percent_total_height + (border_width * (actual_rows + 1))); }
internal override Size GetPreferredSizeCore (Size proposedSize) { // If the tablelayoutowner is autosize, we have to make sure it is big enough // to hold every non-autosize control actual_positions = (LayoutEngine as TableLayout).CalculateControlPositions (this, Math.Max (ColumnCount, 1), Math.Max (RowCount, 1)); // Use actual row/column counts, not user set ones int actual_cols = actual_positions.GetLength (0); int actual_rows = actual_positions.GetLength (1); // Find the largest column-span/row-span values. A table entry that spans more than one // column (row) should not be treated as though it's width (height) all belongs to the // first column (row), but should be spread out across all the columns (rows) that are // spanned. So we need to keep track of the widths (heights) of spans as well as // individual columns (rows). int max_colspan = 1, max_rowspan = 1; foreach (Control c in Controls) { max_colspan = Math.Max(max_colspan, GetColumnSpan(c)); max_rowspan = Math.Max(max_rowspan, GetRowSpan(c)); } // Figure out how wide the owner needs to be int[] column_widths = new int[actual_cols]; // Keep track of widths for spans as well as columns. column_span_widths[i,j] stores // the maximum width for items column i than have a span of j+1 (ie, covers columns // i through i+j). int[,] column_span_widths = new int[actual_cols, max_colspan]; int[] biggest = new int[max_colspan]; float total_column_percentage = 0f; // Figure out how wide each column wants to be for (int i = 0; i < actual_cols; i++) { if (i < ColumnStyles.Count && ColumnStyles[i].SizeType == SizeType.Percent) total_column_percentage += ColumnStyles[i].Width; int absolute_width = -1; if (i < ColumnStyles.Count && ColumnStyles[i].SizeType == SizeType.Absolute) absolute_width = (int)ColumnStyles[i].Width; // use the absolute width if it's absolute! for (int s = 0; s < max_colspan; ++s) biggest[s] = 0; for (int j = 0; j < actual_rows; j++) { Control c = actual_positions[i, j]; if (c != null) { int colspan = GetColumnSpan (c); if (colspan == 0) continue; if (colspan == 1 && absolute_width > -1) biggest[0] = absolute_width; // use the absolute width if the column has absolute width assigned! else if (!c.AutoSize) biggest[colspan-1] = Math.Max (biggest[colspan-1], c.ExplicitBounds.Width + c.Margin.Horizontal + Padding.Horizontal); else biggest[colspan-1] = Math.Max (biggest[colspan-1], c.PreferredSize.Width + c.Margin.Horizontal + Padding.Horizontal); } else if (absolute_width > -1) { biggest[0] = absolute_width; } } for (int s = 0; s < max_colspan; ++s) column_span_widths[i,s] = biggest[s]; } for (int i = 0; i < actual_cols; ++i) { for (int s = 1; s < max_colspan; ++s) { if (column_span_widths[i,s] > 0) AdjustWidthsForSpans (column_span_widths, i, s); } column_widths[i] = column_span_widths[i,0]; } // Because percentage based rows divy up the remaining space, // we have to make the owner big enough so that all the rows // get bigger, even if we only need one to be bigger. int non_percent_total_width = 0; int percent_total_width = 0; for (int i = 0; i < actual_cols; i++) { if (i < ColumnStyles.Count && ColumnStyles[i].SizeType == SizeType.Percent) percent_total_width = Math.Max (percent_total_width, (int)(column_widths[i] / ((ColumnStyles[i].Width) / total_column_percentage))); else non_percent_total_width += column_widths[i]; } int border_width = GetCellBorderWidth (CellBorderStyle); int needed_width = non_percent_total_width + percent_total_width + (border_width * (actual_cols + 1)); // Figure out how tall the owner needs to be int[] row_heights = new int[actual_rows]; int[,] row_span_heights = new int[actual_rows, max_rowspan]; biggest = new int[max_rowspan]; float total_row_percentage = 0f; // Figure out how tall each row wants to be for (int j = 0; j < actual_rows; j++) { if (j < RowStyles.Count && RowStyles[j].SizeType == SizeType.Percent) total_row_percentage += RowStyles[j].Height; int absolute_height = -1; if (j < RowStyles.Count && RowStyles[j].SizeType == SizeType.Absolute) absolute_height = (int)RowStyles[j].Height; // use the absolute height if it's absolute! for (int s = 0; s < max_rowspan; ++s) biggest[s] = 0; for (int i = 0; i < actual_cols; i++) { Control c = actual_positions[i, j]; if (c != null) { int rowspan = GetRowSpan (c); if (rowspan == 0) continue; if (rowspan == 1 && absolute_height > -1) biggest[0] = absolute_height; // use the absolute height if the row has absolute height assigned! else if (!c.AutoSize) biggest[rowspan-1] = Math.Max (biggest[rowspan-1], c.ExplicitBounds.Height + c.Margin.Vertical + Padding.Vertical); else biggest[rowspan-1] = Math.Max (biggest[rowspan-1], c.PreferredSize.Height + c.Margin.Vertical + Padding.Vertical); } else if (absolute_height > -1) { biggest[0] = absolute_height; } } for (int s = 0; s < max_rowspan; ++s) row_span_heights[j,s] = biggest[s]; } for (int j = 0; j < actual_rows; ++j) { for (int s = 1; s < max_rowspan; ++s) { if (row_span_heights[j,s] > 0) AdjustHeightsForSpans (row_span_heights, j, s); } row_heights[j] = row_span_heights[j,0]; } // Because percentage based rows divy up the remaining space, // we have to make the owner big enough so that all the rows // get bigger, even if we only need one to be bigger. int non_percent_total_height = 0; int percent_total_height = 0; for (int j = 0; j < actual_rows; j++) { if (j < RowStyles.Count && RowStyles[j].SizeType == SizeType.Percent) percent_total_height = Math.Max (percent_total_height, (int)(row_heights[j] / ((RowStyles[j].Height) / total_row_percentage))); else non_percent_total_height += row_heights[j]; } int needed_height = non_percent_total_height + percent_total_height + (border_width * (actual_rows + 1)); return new Size (needed_width, needed_height); }
private void InitPaneWindows() { this.Controls.Clear(); ViewerAnnotPanes = null; ViewerAnnotPanes = new Control[rows, cols]; // Add Panels for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { SelectablePanel p = new SelectablePanel(); p.Padding = new Padding(5); //p.BackColor = ngMediImage.GetColorConfig().MultiPaneBackColor; this.Controls.Add(p); p.SelectedChanged += new EventHandler(p_SelectedChanged); ViewerAnnotPanes[i, j] = p; } } // Add ViewerAnnots for (int i = 0; i < this.Rows; i++) { for (int j = 0; j < this.Cols; j++) { ViewerAnnot v = new ViewerAnnot(); //v.Size = new Size(50, 50); v.Dock = DockStyle.Fill; //v.Viewer.ZoomFitForMultiPane(); this.SetViewerAnnot(i, j, v); } } }
void InitValues() { Permissions = GetAvailablePermissions(); Roles = GetAvailableRoles(); map = new Control[Permissions.Length, Roles.Length]; }
private void GenerateControlTiles() { this.panelTiledContainer.Controls.Clear(); this.panelDummyEvents.Width = this.panelTiledContainer.Width = this.tiledBitmap.Width; this.panelDummyEvents.Height = this.panelTiledContainer.Height = this.tiledBitmap.Height; //Array.Clear(this.tilePanels, 0, this.tilePanels.Length); this.tilePanels = null; this.tilePanels = new Control[this.tiledBitmap.TilesX, this.tiledBitmap.TilesY]; int tileWidth = this.tiledBitmap.Width / this.tiledBitmap.TilesX; int tileHeight = this.tiledBitmap.Height / this.tiledBitmap.TilesY; this.CopyEvents<Control>(this.panelTiledContainer); this.CopyEvents<Control>(this.panelDummyEvents); for (int x = 0, relativeX = 0; x < this.tiledBitmap.TilesX; x++, relativeX += tileWidth) { for (int y = 0, relativeY = 0; y < this.tiledBitmap.TilesY; y++, relativeY += tileHeight) { Control tilePanel = new Control { Anchor = AnchorStyles.None, BackColor = Color.Black, BackgroundImageLayout = ImageLayout.None, //ErrorImage = null, //InitialImage = null, Location = new Point(relativeX, relativeY), Margin = new Padding(0), Size = new Size(tileWidth, tileHeight), BackgroundImage = new Bitmap(tileWidth, tileHeight) }; this.tilePanels[x, y] = tilePanel; //this.tiledBitmap[x, y].Image = tilePanel.BackgroundImage as Bitmap; this.tiledBitmap[x, y].RenderCycleCompleted += (tile, type) => { if (type == TiledBitmap.RenderCycleType.Partial || type == TiledBitmap.RenderCycleType.Finish) { //tile.Graphics.Flush(FlushIntention.Sync); //this.panelTiledContainer.Invalidate(true); if (this.tilePanels[tile.XGridPosition, tile.YGridPosition].InvokeRequired) { this.tilePanels[tile.XGridPosition, tile.YGridPosition].Invoke( new Action(() => { this.tilePanels[tile.XGridPosition, tile.YGridPosition] .BackgroundImage = tile.Image.Clone() as Bitmap; })); } else { //this.tilePanels[tile.XGridPosition, tile.XGridPosition].Refresh(); this.tilePanels[tile.XGridPosition, tile.YGridPosition] .BackgroundImage = tile.Image.Clone() as Bitmap; } } }; this.panelTiledContainer.Controls.Add(tilePanel); } } CenterControlInParent(this.panelDummyEvents); CenterControlInParent(this.panelTiledContainer); }