zoukankan      html  css  js  c++  java
  • Winfrom控件使用

    1.Lablelable添加图片,解决图片和字体重叠?

    Text属性添加足够空格即可,显示效果如下所示:

    2.根据窗体名称获取窗体并显示到指定panel?

    Label item = sender as Label;

    if (item == null) return;

    Assembly assembly = Assembly.GetExecutingAssembly();
    var path = "Namespace." + item.Name;
    Form form = assembly.CreateInstance(path) as Form;
    if (form == null) return;

    this.panelContent.Controls.Clear();
    form.TopLevel = false;
    form.FormBorderStyle = FormBorderStyle.None;
    form.Dock = DockStyle.Fill;
    form.Parent = this.panelContent;
    this.panelContent.Controls.Add(form);
    form.Show();

    注意:item.Name为获取到的窗体名称,如:LoginForm.

    3.panel添加控件并为控件添加事件?

    public class MenuItemNodes
        {
            public string Value { get; set; }
            public string Name { get; set; }
        }
      
    private void InitNavigation(List<MenuItemNodes> items)
            {
                if (items == null) return;
    
                this.panleNavigation.Controls.Clear();
                foreach (MenuItemNodes item in items)
                {
                    Add(new Label(), item, this.panleNavigation);
                }
            }
    
            private void Add(Label item, MenuItemNodes node, Panel panel)
            {
                item.Name = node.Name;
                item.Text = node.Value;
                item.Size = new Size(1500, 35);
                item.TextAlign = ContentAlignment.MiddleLeft;
                item.ForeColor = Color.White;
                item.Font = new Font("微软雅黑", 12f, FontStyle.Bold);
                //34, 95, 129
                item.BackColor = System.Drawing.Color.FromArgb(55, 139, 175);
                item.BorderStyle = BorderStyle.FixedSingle;
                
                if (panel.Controls.Count == 0) item.Location = new Point();
                else
                {
                    int y = 0;
                    int x = 0;
                    if (panel.Controls.Count % 1 > 0)
                    {
                        y = panel.Controls[panel.Controls.Count - 1].Location.Y;
                        x = panel.Controls[panel.Controls.Count - 1].Location.X + item.Width;
                    }
                    else
                    {
                        y = panel.Controls[panel.Controls.Count - 1].Location.Y + item.Height;
                        x = panel.Controls[panel.Controls.Count - 1].Location.X;
                    }
    
                    item.Location = new Point(x, y);
                }
                item.MouseClick -= item_MouseClick;
                item.MouseClick += new MouseEventHandler(item_MouseClick);  
    
                panel.Controls.Add(item);
            }
    
     void item_MouseClick(object sender, MouseEventArgs e)
    {
    }
  • 相关阅读:
    ASP.NET MVC 页面重定向
    Linux用户管理
    linux开机、重启和用户注销
    vi和vim
    Mac 与 Linux服务器上传下载
    linux 文件体系
    linux 常用命令及异常处理
    单独使用ueditor的图片上传功能,同时获得上传图片地址和缩略图
    mybatis oracle 插入自增记录 获取主键值 写回map参数
    MyBatis SpringMVC映射配置注意
  • 原文地址:https://www.cnblogs.com/YYkun/p/7419340.html
Copyright © 2011-2022 走看看