int oldTextSize = 0; //Hold measure of text in textbox, resize purposes

        #endregion Fields

        #region Constructors

        //Form layout
        public ScheduleForm()
        {
            allEmployees = EmployeeDatabase.GetAllEmployees();

            #region table layout calculations
            TableLayoutPanel table = new TableLayoutPanel();
            table.SuspendLayout();

            table.Location = new Point(40, 140);
            table.Size = new Size(800, 300);
            table.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;

            //Creating cells - TextBoxes
            TOTAL_ROWS = EmployeeDatabase.GetTotalEmployees();	//Get total number of employees - rows
            for (int i = 0; i < TOTAL_ROWS; i++)
            {
                table.RowStyles.Add(new RowStyle(SizeType.Percent, 50.0f));
                for (int j = 0; j < TOTAL_COLS + 1; j++)
                {
                    table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50.0f));

                    table.Controls.Add(new TextBox() {
                        Dock = DockStyle.Fill,
                        Anchor = AnchorStyles.Top | AnchorStyles.Left,
                        Font = new Font("Arial", 12, FontStyle.Regular),
                        Name = string.Format("{0},{1}", j, i)
                    },
                                        j, i);

                    //Setting specific textboxes
                    Control c = table.GetControlFromPosition(j, i);
                    if (j == 0)
                    {
                        if (i > 0 && allEmployees[i] != null)
                        {

                            c.Text = allEmployees[i].FirstName + " " + allEmployees[i].LastName;

                            //Change column width only if text is greater that last greater text
                            int newTextSize = TextRenderer.MeasureText(c.Text, c.Font).Width - 70;
                            if (newTextSize > oldTextSize)
                            {
                                table.ColumnStyles[0].Width = newTextSize;
                                oldTextSize = newTextSize;
                            }

                        }
                        else
                            c.Text = "Employee";
                    }
                    else if(j > 0 && i == 0)		//Days Labels
                    {
                        c.Text = (Day)(j - 1) + "";

                    }

                }
            }

            table.ResumeLayout();
            table.Show();

            this.Controls.Add(table);
            #endregion

            #region Print linklabel control
            LinkLabel printPage = new LinkLabel();
            printPage.Text = "Print";
            printPage.Font = new Font("Arial", 10, FontStyle.Regular);

            printPage.Location = new Point(table.Bounds.Right - 50, 20);
            printPage.Bounds = new Rectangle(printPage.Location,
                new Size(50, 20));

            //Assign event print
            printPage.LinkClicked += new LinkLabelLinkClickedEventHandler(lnkPrint_LinkClicked);

            this.Controls.Add(printPage);
            #endregion
        }
示例#2
0
文件: Business.cs 项目: fatbudy/CSSM
        private void set_TopDataColumn(Dictionary<string, ColumnSetting> dcs, DataTable dt)
        {
            TopflowLayoutPanel.SuspendLayout();
            ColumnSetting cs = null;

            foreach (DataColumn dc in dt.Columns)
            {
                if (dcs.ContainsKey(dc.ColumnName) && dcs[dc.ColumnName].Visiable)
                {
                    cs = dcs[dc.ColumnName];
                    TableLayoutPanel tlp = new TableLayoutPanel();

                    tlp.RowCount = 1;
                    tlp.Parent = TopflowLayoutPanel;
                    tlp.Height = 32;
                    tlp.Show();

                    Label lleft = new Label();
                    lleft.Text = dcs[dc.ColumnName].HeadText;
                    lleft.Anchor = AnchorStyles.None;
                    lleft.AutoSize = true;
                    lleft.Show();

                    Control rtb = null;
                    if (cs.ReadOnly)
                    {
                        rtb = new Label() {  BorderStyle= System.Windows.Forms.BorderStyle.FixedSingle };
                    }
                    else
                    {
                        rtb = new TextBox();
                    }

                    rtb.DataBindings.Add(new Binding("Text", topbs, dc.ColumnName, true));
                    rtb.Width = dcs[dc.ColumnName].Width;
                    rtb.Anchor = AnchorStyles.Left;
                    tlp.ColumnCount = 2;

                    rtb.Show();

                    tlp.Controls.AddRange(new Control[] { lleft, rtb });
                    tlp.SetColumn(lleft, 0);
                    tlp.SetColumn(rtb, 1);

                    //start list data link
                    if (cs.LinkData && !cs.ReadOnly)    //列表数据类型
                    {
                        rtb.Tag = cs;
                        //这种委托不知道是否是共用,还是每个实例一个,待确定
                        MouseEventHandler rtb_right = delegate(object sender, MouseEventArgs e)
                        {
                            if (e.Button == MouseButtons.Left)
                            {
                                //弹出窗体对话框,用于选择数据
                                SelectItemValue siv = SelectItemValue.Default;
                                TextBox rtb_tmp = (TextBox)sender;
                                ColumnSetting cs_rtb = (ColumnSetting)rtb_tmp.Tag;

                                siv.Text = string.Format("选择 {0} ...", cs_rtb.HeadText);
                                siv.SetColumnSetting(_dblClass, cs_rtb, ModelName, cs_rtb.HeadText);
                                if (siv.ShowDialog() == DialogResult.OK)
                                {
                                    rtb_tmp.Text = siv.SelectValue;
                                }
                            }
                        };
                        rtb.MouseDoubleClick += rtb_right;

                        //tlp.ColumnCount = 3;
                        //ComboBox cb = new ComboBox();
                        //cb.Width = 20;
                        //cb.DropDownWidth = 200;
                        //cb.DropDownStyle = ComboBoxStyle.DropDownList;
                        //cb.TabIndex = 0;
                        //_dblClass.RefreshColumnSettingLinkData(ref _sqlcommand, dc.ColumnName); //更新数据
                        //cb.DataSource = cs.LinkDataTable;
                        //cb.DisplayMember = cs.LinkColumnName ;
                        ////cb.DataBindings.Add("Text", cs.LinkDataTable, "Value");
                        //EventHandler _Commit = delegate(object sender, EventArgs e)
                        // {
                        //     rtb.Text = cb.Text;
                        // };
                        //cb.SelectionChangeCommitted += _Commit;
                        //cb.Show();

                        //tlp.Controls.Add(cb);
                        //tlp.SetColumn(cb, 2);
                    }
                    //end list data link
                    tlp.AutoSize = true;
                    tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                }

                //有些列后添加的,但是需要显示,只是没有配置信息的情况
                //此情况未处理
            }
            TopflowLayoutPanel.ResumeLayout();
        }