Пример #1
0
		/// <summary>Returns the required height.</summary>
		private int ArrangeControls(Graphics g){
			//580 is the initial width of the panel
			int inputW=280;//The input section on the right.
			int promptW=580-20-inputW;//20 is for the scrollbar on the right
			panelMain.Controls.Clear();
			int yPos=5;
			int itemH=0;//item height
			labels=new Label[Parameters.Count];
			inputs=new Control[Parameters.Count];
			for(int i=0;i<Parameters.Count;i++){
				//Calculate height
				itemH=(int)g.MeasureString(Parameters[i].Prompt,Font,promptW).Height;
				if(itemH<20)
					itemH=20;
				//promptingText
				labels[i]=new Label();
				labels[i].Location=new Point(5,yPos);
				//labels[i].Name="Label"+i.ToString();
				labels[i].Size=new Size(promptW-8,itemH);
				labels[i].Text=Parameters[i].Prompt;
				labels[i].TextAlign=ContentAlignment.MiddleRight;
				//labels[i].BorderStyle=BorderStyle.FixedSingle;//just used in debugging layout
				panelMain.Controls.Add(labels[i]);
				if(Parameters[i].ValueType==ParamValueType.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(Parameters[i].CurrentValues.Count==0)
						((CheckBox)inputs[i]).Checked=false;
					else
						((CheckBox)inputs[i]).Checked=true;
					((CheckBox)inputs[i]).FlatStyle=FlatStyle.System;
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.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(Parameters[i].CurrentValues.Count>0){
						DateTime myDate=(DateTime)Parameters[i].CurrentValues[0];
						inputs[i].Text=myDate.ToShortDateString();
					}
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.Enum){
					//add a psuedo combobox filled with values for one enumeration
					inputs[i]=new ComboBoxMulti();
					Type eType=Type.GetType("ODR."+Parameters[i].EnumerationType.ToString());
					for(int j=0;j<Enum.GetNames(eType).Length;j++){
						((ComboBoxMulti)inputs[i]).Items.Add(Enum.GetNames(eType)[j]);
						if(Parameters[i].CurrentValues.Count > 0
							&& Parameters[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);
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.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(Parameters[i].CurrentValues.Count>0){
						inputs[i].Text=((int)Parameters[i].CurrentValues[0]).ToString();
					}
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.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(Parameters[i].CurrentValues.Count>0){
						inputs[i].Text=((double)Parameters[i].CurrentValues[0]).ToString("n");
					}
					panelMain.Controls.Add(inputs[i]);
				}
				else if(Parameters[i].ValueType==ParamValueType.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(Parameters[i].CurrentValues.Count>0){
						inputs[i].Text=Parameters[i].CurrentValues[0].ToString();
					}
					panelMain.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 yPos;
		}
Пример #2
0
        /// <summary>Returns the required height.</summary>
        private int ArrangeControls(Graphics g)
        {
            //580 is the initial width of the panel
            int inputW  = 280;               //The input section on the right.
            int promptW = 580 - 20 - inputW; //20 is for the scrollbar on the right

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

            labels = new Label[Parameters.Count];
            inputs = new Control[Parameters.Count];
            for (int i = 0; i < Parameters.Count; i++)
            {
                //Calculate height
                itemH = (int)g.MeasureString(Parameters[i].Prompt, Font, promptW).Height;
                if (itemH < 20)
                {
                    itemH = 20;
                }
                //promptingText
                labels[i]          = new Label();
                labels[i].Location = new Point(5, yPos);
                //labels[i].Name="Label"+i.ToString();
                labels[i].Size      = new Size(promptW - 8, itemH);
                labels[i].Text      = Parameters[i].Prompt;
                labels[i].TextAlign = ContentAlignment.MiddleRight;
                //labels[i].BorderStyle=BorderStyle.FixedSingle;//just used in debugging layout
                panelMain.Controls.Add(labels[i]);
                if (Parameters[i].ValueType == ParamValueType.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 (Parameters[i].CurrentValues.Count == 0)
                    {
                        ((CheckBox)inputs[i]).Checked = false;
                    }
                    else
                    {
                        ((CheckBox)inputs[i]).Checked = true;
                    }
                    ((CheckBox)inputs[i]).FlatStyle = FlatStyle.System;
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.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 (Parameters[i].CurrentValues.Count > 0)
                    {
                        DateTime myDate = (DateTime)Parameters[i].CurrentValues[0];
                        inputs[i].Text = myDate.ToShortDateString();
                    }
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.Enum)
                {
                    //add a psuedo combobox filled with values for one enumeration
                    inputs[i] = new ComboBoxMulti();
                    Type eType = Type.GetType("ODR." + Parameters[i].EnumerationType.ToString());
                    for (int j = 0; j < Enum.GetNames(eType).Length; j++)
                    {
                        ((ComboBoxMulti)inputs[i]).Items.Add(Enum.GetNames(eType)[j]);
                        if (Parameters[i].CurrentValues.Count > 0 &&
                            Parameters[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);
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.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 (Parameters[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = ((int)Parameters[i].CurrentValues[0]).ToString();
                    }
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.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 (Parameters[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = ((double)Parameters[i].CurrentValues[0]).ToString("n");
                    }
                    panelMain.Controls.Add(inputs[i]);
                }
                else if (Parameters[i].ValueType == ParamValueType.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 (Parameters[i].CurrentValues.Count > 0)
                    {
                        inputs[i].Text = Parameters[i].CurrentValues[0].ToString();
                    }
                    panelMain.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(yPos);
        }