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(, );
item.TextAlign = ContentAlignment.MiddleLeft;
item.ForeColor = Color.White;
item.Font = new Font("微软雅黑", 12f, FontStyle.Bold);
//34, 95, 129
item.BackColor = System.Drawing.Color.FromArgb(, , );
item.BorderStyle = BorderStyle.FixedSingle; if (panel.Controls.Count == ) item.Location = new Point();
else
{
int y = ;
int x = ;
if (panel.Controls.Count % > )
{
y = panel.Controls[panel.Controls.Count - ].Location.Y;
x = panel.Controls[panel.Controls.Count - ].Location.X + item.Width;
}
else
{
y = panel.Controls[panel.Controls.Count - ].Location.Y + item.Height;
x = panel.Controls[panel.Controls.Count - ].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控件使用的更多相关文章
- WPF 精修篇 WPF嵌入Winfrom控件
原文:WPF 精修篇 WPF嵌入Winfrom控件 先增加DLL 支持 使用 WindowsFormsHost 来加载Forms的控件 引用命名空间 xmlns:forms="clr-na ...
- Winfrom控件 特效
链接:https://pan.baidu.com/s/1O9e7sxnYFYWD55Vh5fxFQg 提取码:5cey 复制这段内容后打开百度网盘手机App,操作更方便哦 Winfrom控件查询手册. ...
- C#winfrom控件命名规范
※用红字标记的部分表示有重复出现,括号内为替代表示方案 1.标准控件 序号 控件类型简写 控件类型 1 btn Button 2 chk CheckBox 3 ckl CheckedListBox ...
- winfrom控件——基本工具
窗体事件:属性—事件—load(双击添加) 窗体加载完之后的事件: 删除事件:先将属性事件里挂号的事件名删掉(行为里的load)再删后台代码里的事件. 控件:工具箱里(搜索—双击或点击拖动到窗体界面) ...
- 调整Winfrom控件WebBrowser的默认浏览器内核版本
一.问题解析: 今天在调试程序的时候,需要使用C#的客户端远程登录一个Web页面,用到了WebBrowser控件.但是却发现了一件很神奇的事情:当前浏览器使用的内核,可以通过访问下面这个网站获取:ht ...
- c# vs2010 winfrom控件检测网络环境
写下以作备用,代码附上. public partial class UserControl1 : UserControl, IObjectSafety { //检测网络状态 [DllImport(&q ...
- winfrom 控件的显示隐藏方法
使用Panel作为容器 Panel2.Visible = true; //显示 Panel1.Visible = false; //隐藏
- WinFrom控件双向绑定
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- winfrom控件圆角
刚好用到这个功能,看了好些例子.我就不明白,简单的一个事,一些文章里的代码写的那个长啊,还让人看么. 精简后,就其实一点,只要有paint事件的组件,都可画圆角,没有的外面套一个panel就行了. u ...
随机推荐
- threejs path controls example html
<!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - pa ...
- Python网络爬虫第二弹《http和https协议》
一.HTTP协议 1.官方概念: HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文 ...
- [LeetCode&Python] Problem 100. Same Tree
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- HDU 1014 G题
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- (8)Python连接操作MySQL
pymysql模块下的方法 '''必须实例化对象才能建立连接''' 1.pymysql.connect #和MySQL建立连接 '''得由对象去调用定义游标''' 2.xxx.sursor() # ...
- 【Jmeter】插件
一.插件管理 前提:很多时候,尤其是性能测试的时候,我们需要用到很多场景,需要得到一些参数值等等. 二.插件地址 URL : https://jmeter-plugins.org/downloads/ ...
- mysqldump-1045
mysqldump: [Warning] Using a password on the command line interface can be insecure.mysqldump: Got e ...
- Using gcc stack debug skill
The stack error is hard to debug, but we can debug it assisted by the tool provided by GCC. As we kn ...
- A* 寻路学习
启发式搜索:启发式搜索就是在状态空间中的搜索.对每一个搜索的位置进行评估,得到最好的位置,再从这个位置进行搜索直到目标.这样可以省略大量无谓的搜索路径,提高了效率.在启发式搜索中,对位置的估价是十分重 ...
- 关于C# winform怎么调用webapi来获取到json数据
C/S系统也可以和B/S系统一样实现“前后端分离”,那这样写winform就相当于纯粹的前端页面了,然后再单独部署一个webapi项目,通过api调用数据库进行数据的操作,有利于维护和数据安全性的提高 ...