zoukankan      html  css  js  c++  java
  • C# 自定义控件摘记

     

    C# 自定义控件属性  

    现有自定义控件,内有一textbox控件 TextBox1。控件有一属性 Value 定义为 [BrowsableAttribute(true)] [BindableAttribute(true)] public string Value { get{return TextBox1.Text;} set{TextBox1.Text =value;} } 将该控件的实例绑定到窗体的bind...展开
    跟踪了 当bindingSource.Current发生变更时,自定义属性和控件的普通控件属性的区别:
    自定义的属性:会触发2次BindingComplete事件 一次是BindingCompleteContext.ControlUpdate 控件把值更新到变更前的bindingSource行
    第二次是BindingCompleteContext.DataSourceUpdate,bindingSource的新行把数据给控件
    普通控件属性:只触发后面一次

    定义 DataBindings
    https://www.daniweb.com/programming/software-development/threads/255512/binding-an-application-setting-to-a-control-property
    class BindableToolStripMenuItem : ToolStripMenuItem,IBindableComponent
        {
            #region IBindableComponent Members
            private BindingContext bindingContext;
            private ControlBindingsCollection dataBindings;
            [Browsable(false)]
            public BindingContext BindingContext
            {
                get
                {
                    if (bindingContext == null)
                    {
                        bindingContext = new BindingContext();
                    }
                    return bindingContext;
                }
                set
                {
                    bindingContext = value;
                }
            }
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public ControlBindingsCollection DataBindings
            {
                get
                {
                    if (dataBindings == null)
                    {
                        dataBindings = new ControlBindingsCollection(this);
                    }
                    return dataBindings;
                }
            }
            #endregion
        }
    
    
    

    PropertyChanged;
            /// <summary>
            /// 外部修改ResultId值可以通知邦定的控件,内部修改无法通知邦定的控件???????
            /// </summary>
            [Description("属性:返回ID")]
            //[Bindable(true)]
            [BrowsableAttribute(true)]
            [System.ComponentModel.Bindable(true)] 
            public string ResultId
            {
                get
                {//InvokePropertyChanged("ResultId");
                    return _ResultId;
                    
                }
                set
                {
                    _ResultId = value;
                    InvokePropertyChanged("ResultId");
                }
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
            private void InvokePropertyChanged(string propName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }

     https://documentation.devexpress.com/#WindowsForms/CustomDocument113956/baseclass

    https://www.youtube.com/watch?v=U1eypjtM8JI

  • 相关阅读:
    当数据库结构改变时,需要将数据库删除再创建
    命名空间“System.Web.Mvc”中不存在类型或命名空间“Ajax”(是否缺少程序集引用?)
    jqGrid 各种参数 详解
    二维数组最小路径和
    动态规划:最大连续子序列和
    最长递增子序列
    java单例模式的几种实现
    java多线程的实现方法
    sleep与wait的区别
    数组旋转
  • 原文地址:https://www.cnblogs.com/lhyqzx/p/7007623.html
Copyright © 2011-2022 走看看