lb.Image = Image.FromFile(Application.StartupPath+menu[i].Reserve1);//背景图片
//添加Button控件 public void CteateButton() { //获取主菜单,类型type=true,父菜单m_no不存在 List<v_user_menu> menu = wcf.GetMenuByUserNo(Helper.GlobalVariables.Gs_Current_User.No, true, null).ToList(); for (int i = 0; i < menu.Count(); i++) { Button btn = new Button(); #region 属性 btn.Cursor = Cursors.Hand; btn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(61)))), ((int)(((byte)(164))))); btn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; btn.FlatAppearance.BorderSize = 1; btn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(42)))), ((int)(((byte)(49)))), ((int)(((byte)(131))))); btn.ForeColor = Color.White; btn.Font = new Font("宋体", 12, FontStyle.Bold); ; btn.Location = new System.Drawing.Point(1, 0 + (40 * i)); btn.Name = "btn_" + (i + 1); btn.Size = new System.Drawing.Size(200, 40); btn.TextAlign = ContentAlignment.MiddleLeft; btn.TabIndex = 1; btn.Tag = menu[i].menu_no; //btn.Image=Image.FromFile(menu[i].Reserve1);//背景图片 if (Helper.GlobalVariables.Gi_Language_Type == 1) { btn.Text = menu[i].chinese; } else { btn.Text = menu[i].english; } btn.UseVisualStyleBackColor = true; #endregion #region 方法 btn.Click += new System.EventHandler(this.btn_Click); btn.MouseEnter += new System.EventHandler(this.btn_MouseEnter); btn.MouseLeave += new System.EventHandler(this.btn_MouseLeave); #endregion this.pl_Menu.Controls.Add(btn); } } //添加Label控件 public void CreatLabel(List<v_user_menu> menu) { ////获取主菜单,类型type=true,父菜单m_no不存在 //List<v_user_menu> menuImg = wcf.GetMenuByUserNo(Helper.GlobalVariables.Gs_Current_User.No, true, null).ToList(); for (int i = 0; i < menu.Count(); i++) { Label lb = new Label(); #region 属性 lb.BackColor = System.Drawing.SystemColors.Control; lb.Font = new System.Drawing.Font("微软雅黑", 10.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); #region 确定高度 //当前行数 int y = 1; //每行显示的个数 int num = 4; if (i < 4) { y = 1; } else if (i > 3 && i < 8) { y = 2; } else { y = 3; } #endregion //控件的位置 lb.Location = new Point(50 + 180 * (i - (num * (y - 1))), 50 + 120 * (y - 1)); lb.Name = "lb_" + (i + 1); lb.Size = new System.Drawing.Size(170, 100); lb.Cursor = Cursors.Hand; if (Helper.GlobalVariables.Gi_Language_Type == 1) { lb.Text = menu[i].chinese; } else { lb.Text = menu[i].english; } lb.Tag = menu[i].menu_no; if(menu[i].Reserve1==null) { return; }else { lb.Image = Image.FromFile(Application.StartupPath+menu[i].Reserve1);//背景图片 } lb.ImageAlign = ContentAlignment.MiddleCenter; lb.TextAlign = ContentAlignment.BottomCenter; #endregion #region 方法 lb.Click += new System.EventHandler(this.lb_Click); #endregion this.pl_content.Controls.Add(lb); } }
#region 视图查询 /// <summary> /// 根据用户ID查询根菜单模块 /// </summary> /// <param name="NO">用户ID</param> /// <param name="type">类型名称(true=根菜单,false=子菜单)</param> /// <param name="m_no">父菜单编号</param> /// <returns></returns> public List<v_user_menu> GetMenuByUserNo(string u_NO, bool IsP, string parent_no) { using (var _DataEntities = new ntasystemEntities()) { _DataEntities.ContextOptions.ProxyCreationEnabled = false; if (IsP) { //主菜单 return _DataEntities.v_user_menu.Where(c => c.No == u_NO && c.Module_flag == "0").ToList(); } else { //子菜单 return _DataEntities.v_user_menu.Where(c => c.No == u_NO && c.Module_flag == "1" && c.Tree_name_parent == parent_no).ToList(); } } }