• 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)
    {
    }
  • 相关阅读:
    树状数组求区间最大值
    ABP Zero最新版源码
    abp zero mysql版正式发布
    基于ABP的Easyui admin framework正式开放源代码
    【推荐】ImageProcessor.Web,再也不用自己生成缩略图了
    ABP教程(四)- 开始一个简单的任务管理系统
    Abp Framework中文文档上线
    【开源】基于EF6+MVC5+API2+Easyui1.4.5+Easyui管理模板开发的管理系统
    web+ admin template,spa管理应用后台,easyui后台正式发布
    ABP教程(三)- 开始一个简单的任务管理系统 – 后端编码
  • 原文地址:https://www.cnblogs.com/YYkun/p/7419340.html
Copyright © 2020-2023  润新知