Winfrom控件使用

2021-09-18 12:12

阅读:628

标签:使用   logs   for   border   微软雅黑   获取   控件   turn   nod   1.Lablelable添加图片,解决图片和字体重叠? Text属性添加足够空格即可,显示效果如下所示:   2.根据窗体名称获取窗体并显示到指定panel? Label item = sender as Label; if (item == null) return; Assembly assembly = Assembly.GetExecutingAssembly(); var path = "ZB.PISS.StatisticsSys.View." + 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 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) { }  Winfrom控件使用标签:使用   logs   for   border   微软雅黑   获取   控件   turn   nod   原文地址:http://www.cnblogs.com/YYkun/p/7419340.html


评论


亲,登录后才可以留言!