Exemplo n.º 1
0
        private Control createTextArea(Question q)
        {
            int innerPanelLength = 0;
            FlowLayoutPanel pnlInner = new FlowLayoutPanel();
            pnlInner.FlowDirection = FlowDirection.LeftToRight;
            pnlInner.Width = 120;

            //pnl.BackColor = System.Drawing.Color.Green;
            Label lbl = this.createLabel(q.GetQuestionLabel());
            pnlInner.Controls.Add(lbl);
            innerPanelLength += lbl.Width + 6;
            if (string.IsNullOrEmpty(q.GetQuestionLabel()))
                lbl.Height = 0;

            TextBox txt = new TextBox();
            txt.Enabled = false;
            txt.Name = q.GetQuestionName();
            txt.Multiline = true;
            txt.Width = pnlInner.Width - 6;
            txt.Height = q.GetRows() * 20;
            txt.TextAlign = HorizontalAlignment.Left;
            txt.ScrollBars = ScrollBars.Vertical;
            txt.Tag = q;
            txt.TextChanged += new EventHandler(txt_TextChanged);

            //調整寬度 , the default width of textarea  is FILL
            pnlInner.Width = this.contentPanel.Width - 6;
            txt.Width = pnlInner.Width - 6;

            if (!string.IsNullOrEmpty(q.GetWidth()))
            {
                if (q.GetWidth().ToUpper() != "FILL")
                {
                    int width = 0;
                    bool isnum = int.TryParse(q.GetWidth(), out width);
                    if (isnum)
                        txt.Width = width;
                }
            }

            //txt.Text = q.GetQuestionName();
            pnlInner.Controls.Add(txt);
            this.allQControls.Add(txt.Name, txt);

            //pnlInner.Width = this.contentPanel.Width - 6;
            pnlInner.Height = txt.Height + lbl.Height + 10;

            //adjust height
            this.contentPanel.Height = pnlInner.Height + 6;

            this.pnlQGroup.Height = this.contentPanel.Height + 6;
            return pnlInner;
        }
Exemplo n.º 2
0
        private Control createTextBoxDropDown(Question q)
        {
            int innerPanelLength = 0;
            FlowLayoutPanel pnlInner = new FlowLayoutPanel();
            pnlInner.FlowDirection = FlowDirection.LeftToRight;
            pnlInner.Width = 120;
            //pnl.BackColor = System.Drawing.Color.Green;

            Label lbl = this.createLabel(q.GetQuestionLabel());
            pnlInner.Controls.Add(lbl);
            innerPanelLength += lbl.Width + 6;

            TextBoxDropDown txt = new TextBoxDropDown();
            txt.Enabled = false;
            txt.Name = q.GetQuestionName();
            txt.DropDownControl = this.getDropDownControl(q);
            txt.ButtonDropDown.Text = "...";
            txt.ButtonDropDown.Visible = true;
            txt.Width = 150;
            txt.Height = 20;
            txt.TextAlign = HorizontalAlignment.Left;
            txt.Tag = q;
            txt.TextChanged += new EventHandler(txt_TextChanged);
            txt.ButtonDropDownClick += new System.ComponentModel.CancelEventHandler(txt_ButtonDropDownClick);

            //調整寬度
            pnlInner.Width = innerPanelLength + txt.Width + 6;

            if (!string.IsNullOrEmpty(q.GetWidth()))
            {
                if (q.GetWidth().ToUpper() == "FILL")
                {
                    pnlInner.Width = this.contentPanel.Width - 12;
                    txt.Width = pnlInner.Width - innerPanelLength - 12;
                }
                else
                {
                    int width = 0;
                    bool isnum = int.TryParse(q.GetWidth(), out width);
                    if (isnum)
                    {
                        txt.Width = width;
                        pnlInner.Width = innerPanelLength + txt.Width + 6;
                    }
                }
            }

            //txt.Text = q.GetQuestionName();
            pnlInner.Controls.Add(txt);
            this.allQControls.Add(txt.Name, txt);

            //pnlInner.Width = innerPanelLength + txt.Width + 6;
            pnlInner.Height = txt.Height + 6;

            //adjust height
            int periodCount = 4;
            this.contentPanel.Height = 6 + 20 * ((this.questionGroup.GetQuestions().Count % periodCount == 0) ? (this.questionGroup.GetQuestions().Count / periodCount + 1) : (this.questionGroup.GetListItems().Count / periodCount + 2));

            this.pnlQGroup.Height = this.contentPanel.Height + 6;
            return pnlInner;
        }
Exemplo n.º 3
0
        private Control createComboBox(Question q)
        {
            FlowLayoutPanel pnlInner = new FlowLayoutPanel();
            pnlInner.FlowDirection = FlowDirection.LeftToRight;

            int innerPanelLength = 0;

            //如果 Question 有 Label ,則要在前面加上 Label
            if (q.HasLabel)
            {
                Label lbl = this.createLabel(q.GetQuestionLabel());
                pnlInner.Controls.Add(lbl);
                innerPanelLength += lbl.Width + 6;
            }

            //create combobox
            ComboBoxEx cbo = new ComboBoxEx();
            cbo.Enabled = false;
            cbo.Name = q.GetQuestionName();
            cbo.DropDownStyle = ComboBoxStyle.DropDown;
            cbo.Tag = q;
            cbo.TextChanged += new EventHandler(txt_TextChanged); ;
            Graphics g = cbo.CreateGraphics();
            SizeF maxSize = new SizeF();

            Font f = this.pnlQGroup.Font;
            foreach (QuestionListItem item in this.questionGroup.GetListItems())
            {
                int index = cbo.Items.Add(item.GetLabel());
                if (item.Selected)
                    cbo.SelectedText = item.GetLabel();

                SizeF theSize = g.MeasureString(item.GetLabel(), f);
                if (theSize.Width > maxSize.Width)
                    maxSize = theSize;
            }

            cbo.Width = (int)maxSize.Width + 25;
            pnlInner.Controls.Add(cbo);
            this.allQControls.Add(cbo.Name, cbo);

            pnlInner.Width = innerPanelLength + cbo.Width + 6;
            pnlInner.Height = cbo.Height + 6;

            //adjust height
            int periodCount = 4;
            this.contentPanel.Height = 6 + 20 * ((this.questionGroup.GetQuestions().Count % periodCount == 0) ? (this.questionGroup.GetQuestions().Count / periodCount + 1) : (this.questionGroup.GetQuestions().Count / periodCount + 2));

            this.pnlQGroup.Height = this.contentPanel.Height + 6;
            return pnlInner;
        }