开始总结一下控件的基本用法,方便以后查阅。

一、Label

Label 的使用频率很高,基本上也没有什么难度。

             #region Winform
//label
label.Text = "这是一个Label";
label.Font = new Font("微软雅黑", , FontStyle.Regular, GraphicsUnit.Pixel);
label.ForeColor = Color.Red;
//labelNoAutoSize
labelNoAutoSize.AutoSize = false;
labelNoAutoSize.AutoEllipsis = true;
labelNoAutoSize.Font = new Font("微软雅黑", , FontStyle.Regular, GraphicsUnit.Pixel);
labelNoAutoSize.Size = new System.Drawing.Size(, );
labelNoAutoSize.Text = "这是一个很长很长很长很长很长很长的Label";
#endregion #region Dev
//labelControl
labelControl.AllowHtmlString = true;
labelControl.Text = " <color=#ff0000>这是</color><color=#00ff00>一个</color><color=#0000ff>LabelControl</color>";
labelControl.Font = new Font("微软雅黑", , FontStyle.Regular, GraphicsUnit.Pixel);
labelControl.ToolTip = "这是一个LabelControl";
labelControl.AppearanceHovered.BackColor = Color.Pink;
#endregion

但是有时会遇到在一个Label中字体颜色不同的情况,Winform中的Label是不支持这种情况的,只能想其他办法或更换控件,而Dev的labelControl支持这种情况。

labelControl.AllowHtmlString = true;
labelControl.Text = " <color=#ff0000>这是</color><color=#00ff00>一个</color><color=#0000ff>LabelControl</color>";

二、Button

按钮也是极其常用的控件之一,也需要对其常用的属性有一定的了解。

             #region Winform
//button
button.Text = "button按钮";
button.Font = new Font("微软雅黑", , FontStyle.Regular, GraphicsUnit.Pixel);
button.AutoSize = true;
button.Cursor = System.Windows.Forms.Cursors.Hand;
button.BackColor = Color.FromKnownColor(KnownColor.Control);
//只有FlatStyle为FlatStyle.Flat时,FlatAppearance属性才有效
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = ; //悬停色
button.FlatAppearance.MouseOverBackColor = Color.Red;
//按下时的颜色
button.FlatAppearance.MouseDownBackColor = Color.Green; //Click事件
button.Click += (s1, e1) =>
{
MessageBox.Show(button.Text);
}; #endregion #region Dev
//simpleButton
simpleButton.Text = "simpleButton按钮";
simpleButton.Font = new Font("微软雅黑", , FontStyle.Regular, GraphicsUnit.Pixel);
simpleButton.AutoSize = true;
simpleButton.Cursor = System.Windows.Forms.Cursors.Hand;
simpleButton.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
//取消聚焦框 Winform想要取消可没这么轻松
simpleButton.ShowFocusRectangle = DevExpress.Utils.DefaultBoolean.False;
//颜色设置
simpleButton.Appearance.BackColor = Color.FromKnownColor(KnownColor.Control);
simpleButton.AppearanceHovered.BackColor = Color.Red;
simpleButton.AppearancePressed.BackColor = Color.Green; simpleButton.Click += (s1, e1) =>
{
MessageBox.Show(simpleButton.Text);
}; #endregion

Winfom按钮取消聚焦框的解决方法可以参考:菜鸟互啄:WINFORM如何实现无聚焦框的Button按钮

Winform 控件的入门级使用(一)的更多相关文章

  1. 在WPF中使用WinForm控件方法

    1.      首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll. 2.      在要使用WinForm控 ...

  2. WPF 调用WinForm控件

    WPF可以使用WindowsFormsHost控件做为容器去显示WinForm控件,类似的用法网上到处都是,就是拖一个WindowsFormsHost控件winHost1到WPF页面上,让后设置win ...

  3. WinForm控件TreeView 只部分节点显示 CheckBox

    WinForm控件TreeView 只部分节点显示  CheckBox 用过asp.net的应该知道,要在treeview中实现上述功能可以使用ShowCheckBox 属性指定那些节点显示check ...

  4. Winform控件重写

    Winform控件重写 因为最近的项目中越来越多的遇到了比较特殊的一些控件,有时候我们自己封装一下可能更加方便我们的使用,下面是我们项目中用到的,简单做一个记录. TextBox控件重写 主要的控制代 ...

  5. 通过WinForm控件创建的WPF控件无法输入的问题

    今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在我的机器上却是好好的. 最开始以为是输入法的问题,弄了好一阵子 ...

  6. c#Winform控件总结

    1. C# WinForm控件.自定义控件整理(大全) (http://www.cnblogs.com/top5/archive/2010/04/29/1724039.html) 2. c#窗体控件用 ...

  7. 在WPF中调用Winform控件

    最近在项目中用到了人脸识别和指纹识别,需要调用外部设备和接口,这里就用到了在WPF中调用Winform控件. 第一步,添加程序集引用.System.Windows.Forms和WindowsForms ...

  8. echart图表控件配置入门(二)常用图表数据动态绑定

    上一节 <echart图表控件配置入门(一)>介绍了echarts图表控件的入门配置,使开发人员可以快速搭建出一个静态的图表.但是在实际开发过程这还是不够的,不可能所有的图表控件都是静态数 ...

  9. echart图表控件配置入门(一)

    现在主流的web图表控件主要有hightchart.fusionchart.echart: echart作为百度前端部门近期推出的一个基于html5的免费图表控件,以其丰富图表类型和良好的兼容性速度得 ...

随机推荐

  1. php-删除非空目录

    function deldir($path){ if(!is_dir($path)){ return false; } $dh = opendir($path); while(($file = rea ...

  2. x的x次幂的值为10,求x的近似值

    public class Main { static double eps = 1e-7; public static void main(String[] args){ double l = 2,r ...

  3. swiper轮播问题之二:默认显示3张图片,中间显示全部两边显示部分

    其二:项目遇到比较有点要求的轮播图,默认显示3张图片,中间显示全部,两边显示部分.如图: 网上找了也没有找到合适的,最后经过自己摸索写了出来,贴出代码分享给大家.         CSS .swipe ...

  4. postfix : 452 4.3.1 Insufficient system storage

    postfix Error Message: 452 4.3.1 Insufficient system storage --> 空间不足. 但是实际情况是我的各个分区都没有满,只是我的20G ...

  5. StringMVC @RequestParam属性

    1.jsp: <a href="springmvc/testRequestParam?username=allen&age=sss">test RequsetP ...

  6. 七行代码开始flask

    前言: 对于现有的企业接口服务实现方式来说,Java比较适用于大型的并发式的业务场景:而对一些低IO的且功能简单的数据接口来说,Python似乎更合适.近几年流行的Flask可以说是专为接口式开发而生 ...

  7. 计算机基础理论知识梳理篇(三):VLAN与VLAN网卡相关概念

    VLAN(Virtual Local Area Network) 虚拟局域网(VLAN,802.1Q)是一组逻辑上的设备和用户,这些设备和用户并不受物理位置的限制,可以根据功能.部门及应用等因素将它们 ...

  8. IE8及其以下浏览器关于圆角表框的问题

    css部分 yuan { border: 2px solid #C0C0C0; -moz-border-radius: 50%; -webkit-border-radius: 50%; border- ...

  9. entity framework学习

    资源 Entity Framework技术导游系列开篇与热身

  10. 【树状数组】BZOJ3132 上帝造题的七分钟

    3132: 上帝造题的七分钟 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1004  Solved: 445[Submit][Status][Dis ...