Ejemplo n.º 1
0
        }//end InitializeLayout()

        //
        //
        //
        // ****			CreateObjectControl			****
        //
        /// <summary>
        /// If the parameter info type is an object, we search for known object types
        /// and create the appropriate control here. Otherwise, we ignore it.
        /// </summary>
        /// <param name="pInfo"></param>
        private void CreateObjectControl(ParameterInfo pInfo)
        {
            ParamControlBase control  = null;
            string           typeName = pInfo.ValueType.Name;

            // TODO: See if the object is derived from some interface, or search for
            // a method that returns a control that we can use, and call it to give us
            // such an control, and use it.
            // For Now:  I added this by hand:
            //if (typeName.Equals(typeof(BGTLib.Utilities.PositionBookEventArgs).Name))
            //    control = new ParamPositionBook(pInfo);
            //else
            control = new ParamUnknown(pInfo);


            // Add control if appropriate control was found.
            if (control != null)
            {
                m_ParamControl.Add(control);
                this.Controls.Add(control);
            }
        }//CreateObjectControl()
Ejemplo n.º 2
0
        /*
         * public EngineControl(int engineID, List<ParameterInfo> pInfoList)
         * {
         *  m_EngineID = engineID;
         *  m_ParamInfoList = pInfoList;
         *
         *  InitializeComponent();
         *
         *  this.SuspendLayout();
         *  InitializeLayout();
         *  this.ResumeLayout(false);
         * }//end constructor()
         */
        //
        /// <summary>
        /// Now its time to create the controls.
        /// Note:
        ///     Must be called by the UI thread.
        /// </summary>
        private void InitializeLayout()
        {
            // Controls will need to know to where they should send their events.
            //AppServices appService = AppServices.GetInstance();

            // Load the controls for each parameter.
            for (int i = 0; i < m_ParamInfoList.Count; ++i)
            {
                ParameterInfo    pInfo = m_ParamInfoList[i];
                TypeCode         type  = Type.GetTypeCode(pInfo.ValueType);
                ParamControlBase control;
                switch (type)
                {
                case TypeCode.Boolean:
                    control = new ParamBool2(pInfo);
                    m_ParamControl.Add(control);
                    this.Controls.Add(control);
                    break;

                case TypeCode.String:
                    control = new ParamString(pInfo);
                    m_ParamControl.Add(control);
                    this.Controls.Add(control);
                    break;

                case TypeCode.Int16:
                    control = new ParamInteger2(pInfo);
                    m_ParamControl.Add(control);
                    this.Controls.Add(control);
                    break;

                case TypeCode.Int32:
                    if (pInfo.ValueType.BaseType == typeof(Enum))
                    {
                        control = new ParamEnum(pInfo);
                    }
                    else
                    {
                        control = new ParamInteger2(pInfo);
                    }
                    if (control != null)
                    {
                        m_ParamControl.Add(control);
                        this.Controls.Add(control);
                    }
                    break;

                case TypeCode.Double:
                    control = new ParamDouble2(pInfo);
                    m_ParamControl.Add(control);
                    this.Controls.Add(control);
                    break;

                case TypeCode.Object:                                   // handle special parameter types.
                    CreateObjectControl(pInfo);
                    break;

                default:
                    control = new ParamUnknown(pInfo);
                    m_ParamControl.Add(control);
                    this.Controls.Add(control);
                    break;
                }
            }//next i
            //
            // Create the layout
            //
            int maxWidth  = 0;      // find the widest control, use that as the column width.
            int maxHeight = 0;

            foreach (Control control in m_ParamControl)
            {
                if (control.Width > (maxWidth))
                {
                    maxWidth = control.Width;
                }
                if (control.Height > maxHeight)
                {
                    maxHeight = control.Height;
                }
            }
            int trueWidth  = 0;
            int trueHeight = 0;
            int xLoc       = m_LeftMargin;
            int yLoc       = -maxHeight;   // set negative yLoc, since we increment first!

            for (int i = 0; i < m_ParamControl.Count; ++i)
            {
                // Detect new row.
                if (i % m_nColumns == 0)
                {
                    xLoc  = m_LeftMargin;           // reset to far left.
                    yLoc += maxHeight + m_TopMargin;
                }
                m_ParamControl[i].Location = new System.Drawing.Point(xLoc, yLoc);
                // Remember the largest size
                if (yLoc + m_ParamControl[i].Height > trueHeight)
                {
                    trueHeight = yLoc + m_ParamControl[i].Height;
                }                                                                                                  // take note of where bottom (max y) is.
                if (xLoc + m_ParamControl[i].Width > trueWidth)
                {
                    trueWidth = xLoc + m_ParamControl[i].Width;
                }                                                                                              // take note of where bottom (max y) is.

                // Increment cursor.
                xLoc += maxWidth + m_LeftMargin;                                                                        // increment x location.
                //xLoc += m_ParamControl[i].Width + m_LeftMargin;                   // increment x location.
            }
            //
            // Set size of this control.
            //
            int columns = Math.Min(m_nColumns, m_ParamControl.Count);

            //this.Size = new System.Drawing.Size( (maxWidth+m_LeftMargin)*columns, (maxHeight+m_TopMargin));
            this.Size = new System.Drawing.Size((trueWidth + m_LeftMargin), (trueHeight + m_TopMargin));
        }//end InitializeLayout()