zoukankan      html  css  js  c++  java
  • Winform 控件的入门级使用(一)

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

    一、Label

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

                  

     1             #region Winform
     2             //label
     3             label.Text = "这是一个Label";
     4             label.Font = new Font("微软雅黑", 14, FontStyle.Regular, GraphicsUnit.Pixel);
     5             label.ForeColor = Color.Red;
     6             //labelNoAutoSize
     7             labelNoAutoSize.AutoSize = false;
     8             labelNoAutoSize.AutoEllipsis = true;
     9             labelNoAutoSize.Font = new Font("微软雅黑", 14, FontStyle.Regular, GraphicsUnit.Pixel);
    10             labelNoAutoSize.Size = new System.Drawing.Size(100, 20);
    11             labelNoAutoSize.Text = "这是一个很长很长很长很长很长很长的Label";
    12             #endregion
    13 
    14             #region Dev
    15             //labelControl
    16             labelControl.AllowHtmlString = true;
    17             labelControl.Text = " <color=#ff0000>这是</color><color=#00ff00>一个</color><color=#0000ff>LabelControl</color>";
    18             labelControl.Font = new Font("微软雅黑", 14, FontStyle.Regular, GraphicsUnit.Pixel);
    19             labelControl.ToolTip = "这是一个LabelControl";
    20             labelControl.AppearanceHovered.BackColor = Color.Pink;
    21             #endregion

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

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

     二、Button

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

            

     1             #region Winform
     2             //button
     3             button.Text = "button按钮";
     4             button.Font = new Font("微软雅黑", 14, FontStyle.Regular, GraphicsUnit.Pixel);
     5             button.AutoSize = true;
     6             button.Cursor = System.Windows.Forms.Cursors.Hand;
     7             button.BackColor = Color.FromKnownColor(KnownColor.Control);
     8             //只有FlatStyle为FlatStyle.Flat时,FlatAppearance属性才有效
     9             button.FlatStyle = FlatStyle.Flat;
    10             button.FlatAppearance.BorderSize = 0;
    11 
    12             //悬停色
    13             button.FlatAppearance.MouseOverBackColor = Color.Red;
    14             //按下时的颜色
    15             button.FlatAppearance.MouseDownBackColor = Color.Green;
    16 
    17             //Click事件
    18             button.Click += (s1, e1) =>
    19             {
    20                 MessageBox.Show(button.Text);
    21             };
    22 
    23             #endregion
    24 
    25             #region Dev
    26             //simpleButton
    27             simpleButton.Text = "simpleButton按钮";
    28             simpleButton.Font = new Font("微软雅黑", 14, FontStyle.Regular, GraphicsUnit.Pixel);
    29             simpleButton.AutoSize = true;
    30             simpleButton.Cursor = System.Windows.Forms.Cursors.Hand;
    31             simpleButton.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
    32             //取消聚焦框 Winform想要取消可没这么轻松
    33             simpleButton.ShowFocusRectangle = DevExpress.Utils.DefaultBoolean.False;
    34             //颜色设置
    35             simpleButton.Appearance.BackColor = Color.FromKnownColor(KnownColor.Control);
    36             simpleButton.AppearanceHovered.BackColor = Color.Red;
    37             simpleButton.AppearancePressed.BackColor = Color.Green;
    38 
    39             simpleButton.Click += (s1, e1) =>
    40             {
    41                 MessageBox.Show(simpleButton.Text);
    42             };
    43 
    44             #endregion

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

  • 相关阅读:
    HttpServletRequest对象,自己学习的心得。
    @PathVariable注解的使用和@Requestparam
    微信小程序授权 获取用户的openid和session_key【后端使用java语言编写】,我写的是get方式,目的是测试能否获取到微信服务器中的数据,后期我会写上post请求方式。
    (转)ubuntu 14.04下安装hadoop2.6(伪分布式)
    数据库范式
    C与Python变量的区别
    python3获取当前目录(转)
    最大连续子数组积的线性解法
    最大子数组的线性解法
    windows7下python3.4.3 添加库路径(转)
  • 原文地址:https://www.cnblogs.com/LikeHeart/p/7112704.html
Copyright © 2011-2022 走看看