zoukankan      html  css  js  c++  java
  • 构建winform控件数据缓存器

    DataBindingHelper使用手册

    1.引用Rabbit.Core.dll文件

    也就是我自己编写的功能库Rabbit.Core.dll呵呵。

    Rabbi.Core.DLL密码:dgqv        xml注释    密码:uxxk

    2.引用命名空间

    using Rabbit.Core;

    3.示例demo

    using System;
    using System.Windows.Forms;
    using Rabbit.UI.DataBindingHelper;
    using System.Collections.Generic;
    using Rabbit.Core;
    namespace WindowsFormsApplication3
    {
        public partial class Form1 : Form
        {
            #region 共有变量
            List<FieldBindingContent> fieldList = new List<FieldBindingContent>();
            #endregion
    
            public Form1()
            {
                InitializeComponent();
    
            }
    
            FieldBindingContent fbc;
            private void Form1_Load(object sender, EventArgs e)
            {
                List<a> aas = new List<a>();
                aas.Add(new a() { ID = "1", dispalyvalue = "" });
                aas.Add(new a() { ID = "2", dispalyvalue = "" });
                comboBox1.DataSource = aas;
                comboBox1.ValueMember = "ID";
                comboBox1.DisplayMember = "dispalyvalue";
                GetControlList();
            }
             //将需要操作的控件进行绑定
            public void GetControlList()
            {
                fieldList.Add(new FieldBindingContent("name", "文本框", textBox1, "Text", ""));
                fieldList.Add(new FieldBindingContent("remark", "富文本框", richTextBox1, "Text", ""));
                fieldList.Add(new FieldBindingContent("sex", "1", comboBox1, "SelectedValue", "2"));
                fieldList.Add(new FieldBindingContent("flag", "true", checkBox1, "Checked", false));
    
            }
            private void button1_Click(object sender, EventArgs e)
            {
                foreach (FieldBindingContent item in fieldList)
                {
                    if (item.FieldName != "sex") {
                        continue;
                    }
                    label5.Text = item.FieldValue.ToString();
                }
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                foreach (FieldBindingContent item in fieldList)
                {
    
                    item.SetDefaultProperty();
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                foreach (FieldBindingContent item in fieldList)
                {
                    if (item.FieldName == "remark")
                        item.SetProperty("hello!");
                }
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                foreach (FieldBindingContent item in fieldList)
                {
                    if (item.FieldName == "flag")
                        label6.Text = item.GetProperty().ToString();
                }
            }
    
            private void label5_Click(object sender, EventArgs e)
            {
              
            }
    
        
    
    
        }
        public class a
        {
            public string ID { get; set; }
            public string dispalyvalue { get; set; }
        }
    }

    4.演示效果

    5.主要操作方法说明

    I.public FieldBindingContent(string fieldName,
                                       object fieldValue,
                                       Control bindingControl,
                                       string bindingProperty,
                                       object defaultValue

                                       )

    主要是通过FieldBindingContent类的构造函数来实现控件于该类(作为数据源)的绑定

    参数说明:   

            /// <summary>
            /// 绑定控件属性
            /// </summary>
            /// <param name="fieldName">字段名绑定在控件的tag值上,以便搜索该控件</param>
            /// <param name="fieldValue">字段值,绑定控件的指定属性值</param>
            /// <param name="bindingControl">控件</param>
            /// <param name="bindingProperty">控件属性值</param>
            /// <param name="defaultValue">指定控件默认值</param>

    示例:看上面的代码,你懂的

    II. public object GetProperty()

    参数说明:

            /// <summary>
            /// 获取当前控件绑定的属性值
            /// </summary>
            /// <returns>返回属性值</returns>

    示例:看上面代码,你懂的

    III.  public void SetProperty(object Value);

    参数说明:

            /// <summary>
            /// 设置绑定的控件的属性值
            /// </summary>
            /// <param name="Value">待设置的数据</param>

    示例:看上面代码,你懂的

    IV.  public void SetDefaultProperty()

       参数说明:

            /// <summary>
            /// 控件属性恢复初始值
            /// </summary>

    示例:看上面代码,你懂的

    V.主要属性展示

             public bool AllowNull { get; set; }
            public Control BindingControl { get; set; }//控件
            public string BindingProperty { get; set; }//控件的属性名
            public object DefaultValue { get; set; }//控件的默认值
            public object FieldValue { get; set; }//绑定的属性值
            public string FieldName { get; set; }//绑定的字段名

    6.关于

    本人qq:739462304。找自己一起交流技术。我相信交流才能快速进步.另外如果觉得用起来不错,希望给个赞

  • 相关阅读:
    虚拟机中按键切回windows系统界面快捷键
    余数
    质数(素数)判断代码实现
    =excel========》函数使用
    python 正则表达式规则
    linux常用命令详解
    c指针
    visual studio 2015 开发时常见问题的解决方案
    python装饰器
    构造方法
  • 原文地址:https://www.cnblogs.com/huanxi/p/5709480.html
Copyright © 2011-2022 走看看