Exemple #1
0
 private void GenerateControls()
 {
     try
     {
         form = (Form)host.CreateComponent(typeof(Form), null);
         form.Controls.Clear();
         form.TopLevel = false;
         form.Text     = "Design view";
         DataTable dtControlsList = DBEngine.execReturnDataTable("FormLayout_ControlList", "@FormName", this.Name);
         if (dtControlsList != null && dtControlsList.Rows.Count > 0)
         {
             foreach (DataRow dr in dtControlsList.Rows)
             {
                 if (dr["ControlName"] != DBNull.Value && !dr["ControlName"].ToString().Trim().Equals(string.Empty) && !dr["ControlName"].ToString().Equals(this.Name))
                 {
                     Control ctr = (Control)host.CreateComponent(dr["SystemType"].ToString(), dr["ControlName"].ToString());
                     ctr.Location = new Point((int)dr["LocationX"], (int)dr["LocationY"]);
                     ctr.Text     = HPA.Common.UIMessage.Get_Message(ctr.Name);
                     ctr.Size     = new Size((int)dr["Width"], (int)dr["Height"]);
                     ctr.Visible  = Convert.ToBoolean(dr["Visible"]);
                     ctr.Enabled  = Convert.ToBoolean(dr["Enabled"]);
                     if (dr[CommonConst.TabIndex] != DBNull.Value)
                     {
                         ctr.TabIndex = Convert.ToInt32(dr[CommonConst.TabIndex]);
                     }
                     // set font style
                     if (dr["FontName"] != DBNull.Value)
                     {
                         HPA.Common.LayOutControlHelper.SetFontStyle(ref ctr, dr);
                     }
                     if (dr[CommonConst.ForeColor] != DBNull.Value)
                     {
                         HPA.Common.LayOutControlHelper.SetForeColor(ref ctr, dr);
                     }
                     if (ctr is PictureBox)
                     {
                         ((PictureBox)ctr).Image = CImageUtility.byteArrayToImage((byte[])dr["Image"]);
                     }
                     form.Controls.Add(ctr);
                 }
                 else if (dr["ControlName"].ToString().Equals(this.Name) || (dr["SystemType"].ToString().Equals("System.Windows.Forms.SplitterPanel,System.Windows.Forms") && dr["ControlName"].ToString().Trim().Equals(string.Empty)))
                 {
                     form.Size = new Size((int)dr["Width"], (int)dr["Height"]);
                     form.Name = dr["FormName"].ToString();
                 }
             }
             foreach (DataRow dr in dtControlsList.Rows)
             {
                 if (dr["ParentControl"] == DBNull.Value)
                 {
                     continue;
                 }
                 string PrentCtrName = dr["ParentControl"].ToString();
                 if (PrentCtrName.Trim().Equals(string.Empty))
                 {
                     PrentCtrName = form.Name;
                 }
                 if (!PrentCtrName.Equals(form.Name) && !dr["ControlName"].ToString().Trim().Equals(string.Empty))
                 {
                     if (form.Controls.Find(PrentCtrName, true).Length > 0 && form.Controls.Find(dr["ControlName"].ToString(), true).Length > 0)
                     {
                         form.Controls.Find(PrentCtrName, true)[0].Controls.Add(form.Controls.Find(dr["ControlName"].ToString(), true)[0]);
                     }
                 }
             }
         }
         IRootDesigner rootDesigner = (IRootDesigner)host.GetDesigner(form);
         Control       designView   = (Control)rootDesigner.GetView(ViewTechnology.Default);
         designView.Dock = DockStyle.Fill;
         designSurfacePanel.Controls.Add(designView);
     }
     catch (Exception ex)
     {
         HPA.Common.Helper.LogError(ex, this.Text, "GenerateControls");
     }
 }