C# 窗体程序获取图片路径

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();
                }
            }
        }

 

转载于:https://www.cnblogs.com/Echo529/p/4092483.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值