public void BindData()
        {
            OptionsTableLayout.RowCount = DataSource.Count;
            OptionsTableLayout.Controls.Clear();

            for (int i = 0; i < DataSource.Count; i++)
            {
                var button = new RadioButton();
                button.Text = DataSource[i];

                var position = new TableLayoutPanelCellPosition(0, i);
                OptionsTableLayout.SetCellPosition(button, position);

                OptionsTableLayout.Controls.Add(button);
            }
        }
Example #2
0
        public void DisplayEditor(JobsEditor _js, string xmlText, bool _isEditMode)
        {
            js = _js;
            isEditMode = _isEditMode;

            try
            {
                this.SuspendLayout();

                Clear();
                ResizeEditor();

                if (!xmlText.Equals(String.Empty))
                {
                    xdoc = new XmlDocument();
                    xdoc.LoadXml(xmlText);

                    int row = 0;
                    foreach (XmlNode node in xdoc.FirstChild.Attributes)
                    {
                        tableLayoutPanel1.RowCount = row + 1;

                        TableLayoutPanelCellPosition posLeft = new TableLayoutPanelCellPosition(0, row);
                        Label l = new Label();
                        l.Text = node.Name;
                        l.TextAlign = ContentAlignment.MiddleLeft;
                        l.Width = Convert.ToInt32(tableLayoutPanel1.ColumnStyles[0].Width);
                        tableLayoutPanel1.SetCellPosition(l, posLeft);
                        tableLayoutPanel1.Controls.Add(l);

                        TableLayoutPanelCellPosition posRight = new TableLayoutPanelCellPosition(1, row);
                        TextBox t = new TextBox();
                        t.Multiline = true;
                        t.WordWrap = true;
                        t.Text = node.InnerXml;
                        t.Enabled = protectedFields.Contains(node.Name.ToLower()) ? false : true;
                        t.Width = Convert.ToInt32(tableLayoutPanel1.Width - tableLayoutPanel1.ColumnStyles[0].Width) - 8;
                        t.Height = Convert.ToInt32(t.Height * (1.0 + (Math.Truncate(t.TextLength / 60.0))));
                        tableLayoutPanel1.SetCellPosition(t, posRight);
                        tableLayoutPanel1.Controls.Add(t);

                        row++;
                    }
                }
                this.Visible = true;
                tableLayoutPanel1.Visible = true;
                SetSaveVisibility();
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
            finally
            {
                this.ResumeLayout();
            }
        }
Example #3
0
        // This utility method determines if a cell position
        // is adjacent to the empty cell.
        internal static bool IsValidDragSource(
            TableLayoutPanelCellPosition sourcePos,
            TableLayoutPanelCellPosition emptyPos)
        {
            bool returnValue = false;

            // A cell is considered to be a valid drag source if it
            // is adjacent to the empty cell. Cells that are positioned
            // on a diagonal are not valid.
            if (((sourcePos.Column == emptyPos.Column - 1) && (sourcePos.Row == emptyPos.Row)) ||
                ((sourcePos.Column == emptyPos.Column + 1) && (sourcePos.Row == emptyPos.Row)) ||
                ((sourcePos.Column == emptyPos.Column) && (sourcePos.Row == emptyPos.Row - 1)) ||
                ((sourcePos.Column == emptyPos.Column) && (sourcePos.Row == emptyPos.Row + 1)))
            {
                returnValue = true;
            }

            return returnValue;
        }
Example #4
0
        //The method to get the position of the cell under the mouse.
        private TableLayoutPanelCellPosition GetCellPosition(TableLayoutPanel panel)
        {
            //mouse position
            System.Drawing.Point p = panel.PointToClient(Control.MousePosition);
            Debug.Assert(p.X >= 0);
            Debug.Assert(p.Y >= 0);
            //Cell position
            TableLayoutPanelCellPosition pos = new TableLayoutPanelCellPosition(0, 0);
            //Panel size.
            Size size = panel.Size;
            //average cell size.
            SizeF cellAutoSize = new SizeF(size.Width / panel.ColumnCount, size.Height / panel.RowCount);

            //Get the cell row.
            //y coordinate
            float y = 0;
            for (int i = 0; i < panel.RowCount; i++)
            {
                //Calculate the summary of the row heights.
                SizeType type = panel.RowStyles[i].SizeType;
                float height = panel.RowStyles[i].Height;
                switch (type)
                {
                    case SizeType.Absolute:
                        y += height;
                        break;
                    case SizeType.Percent:
                        y += height / 100 * size.Height;
                        break;
                    case SizeType.AutoSize:
                        y += cellAutoSize.Height;
                        break;
                }
                //Check the mouse position to decide if the cell is in current row.
                if ((int)y > p.Y)
                {
                    pos.Row = i;
                    break;
                }
            }

            //Get the cell column.
            //x coordinate
            float x = 0;
            for (int i = 0; i < panel.ColumnCount; i++)
            {
                //Calculate the summary of the row widths.
                SizeType type = panel.ColumnStyles[i].SizeType;
                float width = panel.GetColumnWidths()[i];
                switch (type)
                {
                    case SizeType.Absolute:
                        x += width;
                        break;
                    case SizeType.Percent:
                        x += width / 100 * size.Width;
                        break;
                    case SizeType.AutoSize:
                        x += cellAutoSize.Width;
                        break;
                }
                //Check the mouse position to decide if the cell is in current column.
                if ((int)x > p.X)
                {
                    pos.Column = i;
                    break;
                }
            }

            //return the mouse position.
            return pos;
        }
Example #5
0
        private TableLayoutPanelCellPosition CalculerPosition(BlocHoraire bloc)
        {
            TableLayoutPanelCellPosition pos = new TableLayoutPanelCellPosition(-1, -1);

            pos.Column = (int)bloc.Jour * NbJours + (int)bloc.Local;
            pos.Row = bloc.HeureDebut - HeureDebutJournee;

            return pos;
        }
Example #6
0
 public void SetCellPosition(object control, TableLayoutPanelCellPosition cellPosition)
 {
     throw null;
 }
 public static CellPos Add(this CellPos pos, CellPos addend) => pos.Add(addend.Column, addend.Row);
Example #8
0
        public void DisplayEditor(JobsEditor _js, string xmlText, bool _isEditMode)
        {
            js = _js;
            isEditMode = _isEditMode;

            try
            {
                this.SuspendLayout();

                Clear();
                ResizeEditor();

                if (!xmlText.Equals(String.Empty))
                {
                    xdoc = new XmlDocument();
                    xdoc.LoadXml(xmlText);

                    string moduleType = xdoc.FirstChild.Attributes["moduleType"].Value;

                    int row = 0;
                    foreach (XmlNode node in xdoc.FirstChild.Attributes)
                    {
                        tableLayoutPanel1.RowCount = row + 1;

                        TableLayoutPanelCellPosition posLeft = new TableLayoutPanelCellPosition(0, row);
                        Label l = new Label();
                        l.Text = node.Name;
                        l.TextAlign = ContentAlignment.MiddleLeft;
                        l.Width = Convert.ToInt32(tableLayoutPanel1.ColumnStyles[0].Width);
                        tableLayoutPanel1.SetCellPosition(l, posLeft);
                        tableLayoutPanel1.Controls.Add(l);

                        if (moduleType.Equals("DataTableJoiner") && node.Name.Equals("OutputColumns"))
                        {
                            Panel p = new Panel();
                            p.Height = 140;
                            p.Width = Convert.ToInt32(tableLayoutPanel1.Width - tableLayoutPanel1.ColumnStyles[0].Width) - 28;

                            string[] list = node.InnerXml.Split(';');

                            TableLayoutPanelCellPosition posRight = new TableLayoutPanelCellPosition(1, row);
                            el = new EditableList();
                            el.ListBox.DataSource = list;
                            el.Enabled = protectedFields.Contains(node.Name.ToLower()) ? false : true;
                            if (isEditMode)
                                el.TextChanged += new EventHandler(XmlNodeTextChanged);
                            el.Width = p.Width - 180;
                            el.Height = 140;
                            el.Top = 0;
                            el.Left = 0;

                            Button bAdd = new Button();
                            bAdd.Text = "Add";
                            bAdd.Top = 10;
                            bAdd.Left = p.Width - 150;
                            bAdd.Click += new EventHandler(bAdd_Click);

                            Button bRemove = new Button();
                            bRemove.Text = "Remove";
                            bRemove.Top = 50;
                            bRemove.Left = p.Width - 150;
                            bRemove.Click += new EventHandler(bRemove_Click);                                

                            p.Controls.AddRange(new Control[] { el, bAdd, bRemove });
                            tableLayoutPanel1.SetCellPosition(p, posRight);
                            tableLayoutPanel1.Controls.Add(p);

                        }
                        else
                        {

                            TableLayoutPanelCellPosition posRight = new TableLayoutPanelCellPosition(1, row);
                            TextBox t = new TextBox();
                            t.Multiline = true;
                            t.WordWrap = true;
                            t.Text = node.InnerXml;
                            t.Enabled = protectedFields.Contains(node.Name.ToLower()) ? false : true;
                            if (isEditMode)
                                t.TextChanged += new EventHandler(XmlNodeTextChanged);
                            t.Width = Convert.ToInt32(tableLayoutPanel1.Width - tableLayoutPanel1.ColumnStyles[0].Width) - 8;
                            t.Height = Convert.ToInt32(t.Height * (1.0 + (Math.Truncate(t.TextLength / 60.0))));
                            tableLayoutPanel1.SetCellPosition(t, posRight);
                            tableLayoutPanel1.Controls.Add(t);

                        }
                        row++;
                    }
                }
                this.Visible = true;
                tableLayoutPanel1.Visible = true;
                SetSaveVisibility();

                EnableUpdateButton(isEditMode);
                isDirty = false;
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
            finally
            {
                this.ResumeLayout();
            }
        }
Example #9
0
		public Control GetControlFromPosition (int column, int row)
		{
			if (column < 0 || row < 0)
				throw new ArgumentException ();

			TableLayoutPanelCellPosition pos = new TableLayoutPanelCellPosition (column, row);

			foreach (Control c in this.Controls)
				if (settings.GetCellPosition (c) == pos)
					return c;

			return null;
		}
 public void SetCellPosition(object control, TableLayoutPanelCellPosition cellPosition)
 {
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     this.SetCellPosition(control, cellPosition.Row, cellPosition.Column, true, true);
 }
Example #11
0
        private void ClickTile(object sender, EventArgs e)
        {
            selectedTile = theGrid.GetPositionFromControl(((Control)sender));
            Point TileLocation = new Point(selectedTile.Column, selectedTile.Row);
            short[] TileData = getTileData(selectedTile.Column, selectedTile.Row);
            switch (tabControl1.SelectedTab.Name)
            {
                case "StandardTab":
                case "ClassroomViewer":
                    if (TileData[0] != 5)   // not a classroom
                        break;

                    SelectedClassroomValue = -1;

                    for (int ClassroomNumber = 0; ClassroomNumber < Classrooms.Count; ClassroomNumber++)
                        foreach (Point Location in Classrooms[ClassroomNumber].Locations)
                            if (Location == TileLocation)
                                SelectedClassroomValue = ClassroomNumber;

                    if (SelectedClassroomValue == -1)
                        MessageBox.Show("Selected classroom has no data!");
                    else
                        OpenClassroom(SelectedClassroomValue);

                    break;
                case "DebugMenu":
                    changeTile.Show(Cursor.Position);
                    break;
                case "BuilderTab":
                    #region
                    if (BuilderRelPoints == null)
                        break;
                    //if (Blueprints[SelectedBlueprint, Rotation].Price > Money)
                    //    break;

                    clearSprites();
                    bool CanBuild = true;

                    foreach (Point RelPoint in BuilderRelPoints)
                    {
                        if (selectedTile.Column + RelPoint.X >= columncount || selectedTile.Column + RelPoint.X < 0 || selectedTile.Row + RelPoint.Y >= rowcount || selectedTile.Row + RelPoint.Y < 0)
                        {
                            CanBuild = false;
                            continue;
                        }
                        TileData = getTileData(selectedTile.Column + RelPoint.X, selectedTile.Row + RelPoint.Y);
                        if (!BlockTypes[TileData[0]][TileData[1]].Buildable)
                            CanBuild = false;
                    }
                    Sprite sprite = CanBuild ? Sprite.BlueprintGreen : Sprite.BlueprintRed;
                    foreach (Point RelPoint in BuilderRelPoints)
                    {
                        if (selectedTile.Column + RelPoint.X >= columncount || selectedTile.Column + RelPoint.X < 0 || selectedTile.Row + RelPoint.Y >= rowcount || selectedTile.Row + RelPoint.Y < 0)
                            continue;

                        setSprite(selectedTile.Column + RelPoint.X, selectedTile.Row + RelPoint.Y, sprite);
                    }
                    BuildLocation = new Point(selectedTile.Column, selectedTile.Row);
                    CBbuildButton.Enabled = CanBuild;
                    break;
                    #endregion
                case "InventoryTab":
                    SelectedClassroomValue = -1;

                    clearSprites();
                    if (TileData[0] != 5)   // not a classroom
                    {
                        button6.Enabled = false;
                        setSprite(selectedTile.Column, selectedTile.Row, Sprite.BlueprintRed);
                        break;
                    }

                    button6.Enabled = InventoryViewer.SelectedItems.Count != 0;

                    for (int ClassroomNumber = 0; ClassroomNumber < Classrooms.Count; ClassroomNumber++)
                        foreach (Point Location in Classrooms[ClassroomNumber].Locations)
                            if (Location == TileLocation)
                                SelectedClassroomValue = ClassroomNumber;

                    if (SelectedClassroomValue == -1)
                    {
                        button6.Enabled = false;
                        setSprite(selectedTile.Column, selectedTile.Row, Sprite.BlueprintRed);
                        MessageBox.Show("Selected classroom has no data!");
                    }
                    else
                    {
                        button6.Enabled = InventoryViewer.SelectedItems.Count != 0;
                        setSprite(selectedTile.Column, selectedTile.Row, Sprite.BlueprintGreen);
                    }

                    break;
                default:
                    break;
            }
        }
Example #12
0
        // This utility method initializes the TableLayoutPanel
        // which contains the ToolStripButton controls.
        private void InitializeTableLayoutSettings()
        {
            // Specify the numbers of rows and columns in the GridStrip control.
            this.tableSettings = base.LayoutSettings as TableLayoutSettings;
            this.tableSettings.ColumnCount = this.rows;
            this.tableSettings.RowCount = this.columns;

            // Create a dummy bitmap with the dimensions of each tile.
            // The GridStrip control sizes itself based on these dimensions.
            Bitmap b = new Bitmap(tileSize.Width, tileSize.Height);

            // Populate the GridStrip control with ToolStripButton controls.
            for (int i = 0; i < this.tableSettings.ColumnCount; i++)
            {
                for (int j = 0; j < this.tableSettings.RowCount; j++)
                {
                    // Create a new ToolStripButton control.
                    ToolStripButton btn = new ToolStripButton();
                    btn.DisplayStyle = ToolStripItemDisplayStyle.Image;
                    btn.Image = b;
                    btn.ImageAlign = ContentAlignment.MiddleCenter;
                    btn.ImageScaling = ToolStripItemImageScaling.None;
                    btn.Margin = Padding.Empty;
                    btn.Padding = Padding.Empty;

                    // Add the new ToolStripButton control to the GridStrip.
                    this.Items.Add(btn);

                    // Set the cell position of the ToolStripButton control.
                    TableLayoutPanelCellPosition cellPos = new TableLayoutPanelCellPosition(i, j);
                    this.tableSettings.SetCellPosition(btn, cellPos);

                    // If this is the ToolStripButton control at cell (0,0),
                    // assign it as the empty cell button.
                    if (i == 0 && j == 0)
                    {
                        btn.Text = "Empty Cell";
                        btn.Image = b;
                        this.emptyCellButton = btn;
                    }
                }
            }
        }
Example #13
0
 public void SelectCell(CustomBlockTimelineCell cell)
 {
     if (cell != null)
     {
         cell.IsSelected = true;
         _current_position = tableLayoutPanel1.GetPositionFromControl(cell);
         Console.WriteLine("CurrentPosition {0}", _current_position.ToString());
     }
 }
Example #14
0
        public void SetCellPosition(object control, TableLayoutPanelCellPosition cellPosition)
        {
            ArgumentNullException.ThrowIfNull(control);

            SetCellPosition(control, cellPosition.Row, cellPosition.Column, rowSpecified: true, colSpecified: true);
        }
Example #15
0
        void t_combo_SelectedIndexChanged(object sender, EventArgs e)
        {
            TableLayoutPanelCellPosition pos = new TableLayoutPanelCellPosition();
            Control ctr = new Control();
            Control ctrParent = new Control();
            TableLayoutPanel ctrGrandParent = new TableLayoutPanel();
            TextBox t_txtBox2 = new TextBox();

            ctr = (Control)sender; // cast combobox control
            ctrParent = ctr.Parent; // get panel control
            ctrGrandParent = (TableLayoutPanel)ctrParent.Parent; // get tablelayoutpanel control
            pos = ctrGrandParent.GetPositionFromControl(ctrParent); // get panel position

            if (ctrParent.Controls.Count < 2 & ctr.Text == "Other")
            {
                t_txtBox2.Location = new Point(3, 30);
                t_txtBox2.Text = ctr.Tag.ToString();
                ctrParent.Controls.Add(t_txtBox2);
            }
            else if (ctrParent.Controls.Count == 2 & ctr.Text != "Other")
            {
                ctrGrandParent.GetControlFromPosition(pos.Column, pos.Row).Controls.RemoveAt(1);
            }
        }
Example #16
0
        private void setTableLayout(TableLayoutPanel t)
        {
            // tableLayoutPanel1.SuspendLayout();
            t.Controls.Clear();
            int _rowNum = t.RowCount;
            int _colNum = t.ColumnCount;
            t.Dock = DockStyle.Fill;
            //int _height = t.Height;
            int _width = t.Width;
            int _cellHeight = 20;//高度固定
            int _cellWidth = _width / _colNum;
            for (int i = 0; i < _rowNum; i++)
            {
                t.RowStyles[i].SizeType = SizeType.Absolute;
                t.RowStyles[i].Height = _cellHeight;
            }
            for (int j = 0; j < _colNum; j++)
            {
                t.ColumnStyles[j].SizeType = SizeType.Absolute;
                t.ColumnStyles[j].Width = _cellWidth;
            }

            for (int i = 0; i < _rowNum; i++)
            {
                for (int j = 0; j < _colNum; j++)
                {
                    //if (i == 0 && j == 0) break;
                    TextBox tBox= new TextBox();//一定要在这里new一下,不然就是未引用对象到实例
                    t.Controls.Add(tBox);
                    tBox.Text = i.ToString() + ":" + j.ToString();
                    tBox.Name = "tBox" + i.ToString() + "_" + j.ToString();
                    TableLayoutPanelCellPosition p = new TableLayoutPanelCellPosition(j, i);
                    t.SetCellPosition(tBox, p);

                }
            }
            t.Height = _cellHeight * _rowNum;
            //tableLayoutPanel1.ResumeLayout();
        }
 public void SetCellPosition(object control, TableLayoutPanelCellPosition cellPosition) {
    if (control == null) {
         throw new ArgumentNullException("control");
    }
    SetCellPosition(control, cellPosition.Row, cellPosition.Column,  /*rowSpecified=*/true, /*colSpecified=*/true);
    
 }
Example #18
0
 private int GetHeure(TableLayoutPanelCellPosition pos)
 {
     return pos.Row + HeureDebutJournee;
 }
Example #19
0
        /// <summary>
        /// Permet d'obtenir le jours de la semaine selon la position de la cellule dans le tablelayoutpanel
        /// </summary>
        /// <param name="pos"></param>
        private Journee GetJour(TableLayoutPanelCellPosition pos)
        {
            Journee jour = (Journee)(pos.Column / Enum.GetNames(typeof(Local)).Length);

            return jour;
        }
Example #20
0
 /// <summary>
 /// Permet d'obtenir le numéro du local à partir de la position dans le tablelayoutpanel
 /// </summary>
 /// <param name="pos"></param>
 /// <returns></returns>
 private Local GetLocal(TableLayoutPanelCellPosition pos)
 {
     return (Local)(pos.Column % NbJours);
 }
Example #21
0
		public void SetCellPosition (Control control, TableLayoutPanelCellPosition position)
		{
			settings.SetCellPosition (control, position);
		}
Example #22
0
        private void MettreAjourBlocFromPos(TableLayoutPanelCellPosition pos, BlocHoraire bloc)
        {
            //On obtien le jour de la semaine selon la position dans la grille
            bloc.Jour = GetJour(pos);

            //on obtien le numéro du local selon la position dans la grille
            bloc.Local = GetLocal(pos);

            //on obtien l'heure
            bloc.HeureDebut = GetHeure(pos);
        }
 public static CellPos Add(this CellPos pos, int column, int row) => new CellPos(pos.Column + column, pos.Row + row);
Example #24
0
        private void tableLayoutPanel1_DragDrop(object sender, DragEventArgs e)
        {
            //On vérifie s'il s'agit d'un noeud du treeview ou un label du tablelayoutpanel
             if(e.Data.GetDataPresent(typeof (System.Windows.Forms.TreeNode)))
             {
                 TreeNode node = ((TreeNode)e.Data.GetData(typeof(System.Windows.Forms.TreeNode)));

                 if (node != null)
                 {
                     List<object> oTagInfo  = (List<object>) node.Tag;

                     String prof = (string)oTagInfo.ElementAt(0);
                     Cours cours = (Cours)oTagInfo.ElementAt(1);
                     BlocHoraire bloc = (BlocHoraire)oTagInfo.ElementAt(2);

                     //On obtient la position de la cellule du Drop
                     TableLayoutPanelCellPosition pos = GetCellPosition(this.tableLayoutPanel1);

                     MettreAjourBlocFromPos(pos, bloc);

                     AfficherBlocHoraire(oTagInfo, prof, cours, bloc);

                     this.treeView1.Nodes.Remove(node);
                 }
             }
             else if (e.Data.GetDataPresent(typeof(System.Windows.Forms.Label)))
             {
                 System.Windows.Forms.Label  lblCours = (( System.Windows.Forms.Label)e.Data.GetData(typeof(System.Windows.Forms.Label)));
                 TableLayoutPanelCellPosition pos = new TableLayoutPanelCellPosition();
                 System.Drawing.Point loc = this.tableLayoutPanel1.PointToClient(new System.Drawing.Point(e.X, e.Y));

                 //detemine the cell location
                 pos.Column = -1;
                 pos.Row = -1;
                 int x = 0;
                 int y = 0;
                 while (pos.Column <= this.tableLayoutPanel1.ColumnCount)
                 {
                     if (loc.X < x)
                     {
                         break;
                     }
                     pos.Column++;
                     x += this.tableLayoutPanel1.GetColumnWidths()[pos.Column];
                 }
                 while (pos.Row <= this.tableLayoutPanel1.RowCount)
                 {
                     if (loc.Y < y)
                     {
                         break;
                     }
                     pos.Row++;
                     y += this.tableLayoutPanel1.GetRowHeights()[pos.Row];
                 }

                 this.tableLayoutPanel1.Controls.Add(lblCours, pos.Column, pos.Row);

                 //On obtient la nouvelle position de la cellule du Drop
                 pos = GetCellPosition(this.tableLayoutPanel1);

                 List<object> oTagInfo = (List<object>) lblCours.Tag;

                 Cours cours = (Cours)oTagInfo.ElementAt(1);

                 BlocHoraire bloc = (BlocHoraire)oTagInfo.ElementAt(2);

                 MettreAjourBlocFromPos(pos, bloc);

                 //On remplace la valeur du blocHoraire
                 oTagInfo.RemoveAt(2);
                 oTagInfo.Insert(2, bloc);

                 lblCours.Tag = oTagInfo;
             }
        }
Example #25
0
		public void SetCellPosition (Object control, TableLayoutPanelCellPosition cellPosition)
		{
			if (control == null)
				throw new ArgumentNullException ();

			columns[control] = cellPosition.Column;
			rows[control] = cellPosition.Row;

			if (panel != null)
				panel.PerformLayout ();
		}
Example #26
0
 //set the row and column of the control
 /// <include file='doc\TableLayoutPanel.uex' path='docs/doc[@for="TableLayoutPanel.SetRow"]/*' />
 public void SetCellPosition(Control control, TableLayoutPanelCellPosition position)
 {
     _tableLayoutSettings.SetCellPosition(control, position);
 }