Exemplo n.º 1
0
		/// <summary>Returns the required height.</summary>
		private int ArrangeControls(Graphics g){
			//calculate width of input section
			int inputW=300;//the widest allowed for the input section on the right.
			if(IsQuestionnaire){
				inputW=450;
			}
			if(panelSlide.Width<600){
				inputW=panelSlide.Width/2;
			}
			int promptW=panelSlide.Width-inputW;
			panelSlide.Controls.Clear();
			int yPos=5;
			int itemH=0;//item height
			labels=new Label[multInputItems.Count];
			inputs=new Control[multInputItems.Count];
			for(int i=0;i<multInputItems.Count;i++){
				//Calculate height
				itemH=(int)g.MeasureString(((MultInputItem)multInputItems[i]).PromptingText,Font,promptW).Height;
				if(itemH<20)
					itemH=20;
				//promptingText
				labels[i]=new Label();
				labels[i].Location=new Point(2,yPos);
				//labels[i].Name="Label"+i.ToString();
				labels[i].Size=new Size(promptW-5,itemH);
				labels[i].Text=multInputItems[i].PromptingText;
				labels[i].TextAlign=ContentAlignment.MiddleRight;
				//labels[i].BorderStyle=BorderStyle.FixedSingle;//just used in debugging layout
				panelSlide.Controls.Add(labels[i]);
				if(multInputItems[i].ValueType==FieldValueType.Boolean){
					//add a checkbox
					inputs[i]=new CheckBox();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					inputs[i].Size=new Size(inputW-5,20);
					if(multInputItems[i].CurrentValues.Count==0)
						((CheckBox)inputs[i]).Checked=false;
					else
						((CheckBox)inputs[i]).Checked=true;
					((CheckBox)inputs[i]).FlatStyle=FlatStyle.System;
					panelSlide.Controls.Add(inputs[i]);
				}
				else if(multInputItems[i].ValueType==FieldValueType.Date){
					//add a validDate box
					inputs[i]=new ValidDate();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					if(inputW<100){//not enough room for a fullsize box
						inputs[i].Size=new Size(inputW-20,20);
					}
					else{
						inputs[i].Size=new Size(75,20);
					}
					;
					if(multInputItems[i].CurrentValues.Count>0){
						DateTime myDate=(DateTime)multInputItems[i].CurrentValues[0];
						inputs[i].Text=myDate.ToShortDateString();
					}
					panelSlide.Controls.Add(inputs[i]);
				}
				else if(multInputItems[i].ValueType==FieldValueType.Def){
					//add a psuedo combobox filled with visible defs for one category
					inputs[i]=new ComboBoxMulti();
					for(int j=0;j<DefC.Short[(int)multInputItems[i].DefCategory].Length;j++){
						((ComboBoxMulti)inputs[i]).Items.Add(DefC.Short[(int)multInputItems[i].DefCategory][j].ItemName);
						if(multInputItems[i].CurrentValues.Count > 0
							&& multInputItems[i].CurrentValues
							.Contains(DefC.Short[(int)multInputItems[i].DefCategory][j].DefNum))
						{
							((ComboBoxMulti)inputs[i]).SetSelected(j,true);
						}
					}
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					inputs[i].Size=new Size(inputW-5,20);
					panelSlide.Controls.Add(inputs[i]);
				}
				else if(multInputItems[i].ValueType==FieldValueType.Enum){
					//add a psuedo combobox filled with values for one enumeration
					inputs[i]=new ComboBoxMulti();
					Type eType=Type.GetType("OpenDental."+multInputItems[i].EnumerationType.ToString());
					for(int j=0;j<Enum.GetNames(eType).Length;j++){
						((ComboBoxMulti)inputs[i]).Items.Add(Enum.GetNames(eType)[j]);
						if(multInputItems[i].CurrentValues.Count > 0
							&& multInputItems[i].CurrentValues.Contains((int)(Enum.Parse(eType,Enum.GetNames(eType)[j])))  )
						{
							((ComboBoxMulti)inputs[i]).SetSelected(j,true);
						}
					}
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					inputs[i].Size=new Size(inputW-5,20);
					panelSlide.Controls.Add(inputs[i]);
				}
				else if(multInputItems[i].ValueType==FieldValueType.ForeignKey){
					//add a psuedo combobox filled with values from one table
					inputs[i]=new ComboBoxMulti();
					//these two arrays are matched item for item
					string[] foreignRows=GetFRows(multInputItems[i].FKType);
					long[] foreignKeys=GetFKeys(multInputItems[i].FKType);
					for(int j=0;j<foreignRows.Length;j++){
						((ComboBoxMulti)inputs[i]).Items.Add(foreignRows[j]);
						if(multInputItems[i].CurrentValues.Count > 0
							&& multInputItems[i].CurrentValues.Contains(foreignKeys[j])  )
						{
							((ComboBoxMulti)inputs[i]).SetSelected(j,true);
						}
					}
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					inputs[i].Size=new Size(inputW-5,20);
					panelSlide.Controls.Add(inputs[i]);
				}
				else if(multInputItems[i].ValueType==FieldValueType.Integer){
					//add a validNumber box
					inputs[i]=new ValidNumber();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					if(inputW<100){//not enough room for a fullsize box
						inputs[i].Size=new Size(inputW-20,20);
					}
					else{
						inputs[i].Size=new Size(75,20);
					}
					if(multInputItems[i].CurrentValues.Count>0){
						inputs[i].Text=((int)multInputItems[i].CurrentValues[0]).ToString();
					}
					panelSlide.Controls.Add(inputs[i]);
				}
				else if(multInputItems[i].ValueType==FieldValueType.Number){
					//add a validDouble box
					inputs[i]=new ValidDouble();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					if(inputW<100){//not enough room for a fullsize box
						inputs[i].Size=new Size(inputW-20,20);
					}
					else{
						inputs[i].Size=new Size(75,20);
					}
					if(multInputItems[i].CurrentValues.Count>0){
						inputs[i].Text=((double)multInputItems[i].CurrentValues[0]).ToString("n");
					}
					panelSlide.Controls.Add(inputs[i]);
				}
				else if(multInputItems[i].ValueType==FieldValueType.String){
					//add a textbox
					inputs[i]=new TextBox();
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					//inputs[i].Name=
					inputs[i].Size=new Size(inputW-5,20);
					if(multInputItems[i].CurrentValues.Count>0){
						inputs[i].Text=multInputItems[i].CurrentValues[0].ToString();
					}
					panelSlide.Controls.Add(inputs[i]);
				}
				else if(multInputItems[i].ValueType==FieldValueType.YesNoUnknown) {
					//add two checkboxes: Yes(1) and No(2).
					inputs[i]=new ContrYN();
					if(multInputItems[i].CurrentValues.Count>0){
						((ContrYN)inputs[i]).CurrentValue=(YN)multInputItems[i].CurrentValues[0];
					}
					inputs[i].Location=new Point(promptW,yPos+(itemH-20)/2);
					inputs[i].Size=new Size(inputW-5,20);
					panelSlide.Controls.Add(inputs[i]);
				}
				yPos+=itemH+5;
				if(yPos>panelMain.Height && !vScrollBar2.Visible)
					return yPos;//There's not enough room, so stop and make the scrollbar visible.
			}
			panelSlide.Height=yPos;
			vScrollBar2.Maximum=panelSlide.Height;
			vScrollBar2.Minimum=0;
			vScrollBar2.LargeChange=panelMain.Height;
			vScrollBar2.SmallChange=5;
			return -1;
		}
Exemplo n.º 2
0
        /// <summary>Returns the required height.</summary>
        private int ArrangeControls(Graphics g)
        {
            //calculate width of input section
            int inputW = 300;          //the widest allowed for the input section on the right.

            if (IsQuestionnaire)
            {
                inputW = 450;
            }
            if (panelSlide.Width < 600)
            {
                inputW = panelSlide.Width / 2;
            }
            int promptW = panelSlide.Width - inputW;

            panelSlide.Controls.Clear();
            int yPos  = 5;
            int itemH = 0;          //item height

            labels = new Label[multInputItems.Count];
            inputs = new Control[multInputItems.Count];
            for (int i = 0; i < multInputItems.Count; i++)
            {
                //Calculate height
                itemH = (int)g.MeasureString(((MultInputItem)multInputItems[i]).PromptingText, Font, promptW).Height;
                if (itemH < 20)
                {
                    itemH = 20;
                }
                //promptingText
                labels[i]          = new Label();
                labels[i].Location = new Point(2, yPos);
                //labels[i].Name="Label"+i.ToString();
                labels[i].Size      = new Size(promptW - 5, itemH);
                labels[i].Text      = multInputItems[i].PromptingText;
                labels[i].TextAlign = ContentAlignment.MiddleRight;
                //labels[i].BorderStyle=BorderStyle.FixedSingle;//just used in debugging layout
                panelSlide.Controls.Add(labels[i]);
                if (multInputItems[i].ValueType == FieldValueType.Boolean)
                {
                    //add a checkbox
                    inputs[i]          = new CheckBox();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    inputs[i].Size     = new Size(inputW - 5, 20);
                    if (multInputItems[i].CurrentValues.Count == 0)
                    {
                        ((CheckBox)inputs[i]).Checked = false;
                    }
                    else
                    {
                        ((CheckBox)inputs[i]).Checked = true;
                    }
                    ((CheckBox)inputs[i]).FlatStyle = FlatStyle.System;
                    panelSlide.Controls.Add(inputs[i]);
                }
                else if (multInputItems[i].ValueType == FieldValueType.Date)
                {
                    //add a validDate box
                    inputs[i]          = new ValidDate();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    if (inputW < 100)                  //not enough room for a fullsize box
                    {
                        inputs[i].Size = new Size(inputW - 20, 20);
                    }
                    else
                    {
                        inputs[i].Size = new Size(75, 20);
                    }
                    ;
                    if (multInputItems[i].CurrentValues.Count > 0)
                    {
                        DateTime myDate = (DateTime)multInputItems[i].CurrentValues[0];
                        inputs[i].Text = myDate.ToShortDateString();
                    }
                    panelSlide.Controls.Add(inputs[i]);
                }
                else if (multInputItems[i].ValueType == FieldValueType.Def)
                {
                    //add a psuedo combobox filled with visible defs for one category
                    inputs[i] = new ComboBoxMulti();
                    List <Def> listDefs = Defs.GetDefsForCategory(multInputItems[i].DefCategory, true);
                    for (int j = 0; j < listDefs.Count; j++)
                    {
                        ((ComboBoxMulti)inputs[i]).Items.Add(listDefs[j].ItemName);
                        if (multInputItems[i].CurrentValues.Count > 0 &&
                            multInputItems[i].CurrentValues
                            .Contains(listDefs[j].DefNum))
                        {
                            ((ComboBoxMulti)inputs[i]).SetSelected(j, true);
                        }
                    }
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    inputs[i].Size     = new Size(inputW - 5, 20);
                    panelSlide.Controls.Add(inputs[i]);
                }
                else if (multInputItems[i].ValueType == FieldValueType.Enum)
                {
                    //add a psuedo combobox filled with values for one enumeration
                    inputs[i] = new ComboBoxMulti();
                    Type eType = Type.GetType("OpenDental." + multInputItems[i].EnumerationType.ToString());
                    for (int j = 0; j < Enum.GetNames(eType).Length; j++)
                    {
                        ((ComboBoxMulti)inputs[i]).Items.Add(Enum.GetNames(eType)[j]);
                        if (multInputItems[i].CurrentValues.Count > 0 &&
                            multInputItems[i].CurrentValues.Contains((int)(Enum.Parse(eType, Enum.GetNames(eType)[j]))))
                        {
                            ((ComboBoxMulti)inputs[i]).SetSelected(j, true);
                        }
                    }
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    inputs[i].Size     = new Size(inputW - 5, 20);
                    panelSlide.Controls.Add(inputs[i]);
                }
                else if (multInputItems[i].ValueType == FieldValueType.ForeignKey)
                {
                    //add a psuedo combobox filled with values from one table
                    inputs[i] = new ComboBoxMulti();
                    //these two arrays are matched item for item
                    string[] foreignRows = GetFRows(multInputItems[i].FKType);
                    long[]   foreignKeys = GetFKeys(multInputItems[i].FKType);
                    for (int j = 0; j < foreignRows.Length; j++)
                    {
                        ((ComboBoxMulti)inputs[i]).Items.Add(foreignRows[j]);
                        if (multInputItems[i].CurrentValues.Count > 0 &&
                            multInputItems[i].CurrentValues.Contains(foreignKeys[j]))
                        {
                            ((ComboBoxMulti)inputs[i]).SetSelected(j, true);
                        }
                    }
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    inputs[i].Size     = new Size(inputW - 5, 20);
                    panelSlide.Controls.Add(inputs[i]);
                }
                else if (multInputItems[i].ValueType == FieldValueType.Integer)
                {
                    //add a validNumber box
                    inputs[i]          = new ValidNumber();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    if (inputW < 100)                  //not enough room for a fullsize box
                    {
                        inputs[i].Size = new Size(inputW - 20, 20);
                    }
                    else
                    {
                        inputs[i].Size = new Size(75, 20);
                    }
                    if (multInputItems[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = ((int)multInputItems[i].CurrentValues[0]).ToString();
                    }
                    panelSlide.Controls.Add(inputs[i]);
                }
                else if (multInputItems[i].ValueType == FieldValueType.Number)
                {
                    //add a validDouble box
                    inputs[i]          = new ValidDouble();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    if (inputW < 100)                  //not enough room for a fullsize box
                    {
                        inputs[i].Size = new Size(inputW - 20, 20);
                    }
                    else
                    {
                        inputs[i].Size = new Size(75, 20);
                    }
                    if (multInputItems[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = ((double)multInputItems[i].CurrentValues[0]).ToString("n");
                    }
                    panelSlide.Controls.Add(inputs[i]);
                }
                else if (multInputItems[i].ValueType == FieldValueType.String)
                {
                    //add a textbox
                    inputs[i]          = new TextBox();
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    //inputs[i].Name=
                    inputs[i].Size = new Size(inputW - 5, 20);
                    if (multInputItems[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = multInputItems[i].CurrentValues[0].ToString();
                    }
                    panelSlide.Controls.Add(inputs[i]);
                }
                else if (multInputItems[i].ValueType == FieldValueType.YesNoUnknown)
                {
                    //add two checkboxes: Yes(1) and No(2).
                    inputs[i] = new ContrYN();
                    if (multInputItems[i].CurrentValues.Count > 0)
                    {
                        ((ContrYN)inputs[i]).CurrentValue = (YN)multInputItems[i].CurrentValues[0];
                    }
                    inputs[i].Location = new Point(promptW, yPos + (itemH - 20) / 2);
                    inputs[i].Size     = new Size(inputW - 5, 20);
                    panelSlide.Controls.Add(inputs[i]);
                }
                yPos += itemH + 5;
                if (yPos > panelMain.Height && !vScrollBar2.Visible)
                {
                    return(yPos);                   //There's not enough room, so stop and make the scrollbar visible.
                }
            }
            panelSlide.Height       = yPos;
            vScrollBar2.Maximum     = panelSlide.Height;
            vScrollBar2.Minimum     = 0;
            vScrollBar2.LargeChange = panelMain.Height;
            vScrollBar2.SmallChange = 5;
            return(-1);
        }