【WinForm窗体控件开发】之四 DesignerSerializationVisibilityAttribute 控件属性的串行化

winform自定义控件(gdi+)(2)———为自定义控件添加系统自带属性 我们在自定义控件的时候,难免需要给自定义控件类添加一系列的属性,本文就来讲解如何实现 阅读详情

转自:http://www.cnblogs.com/bobbychencj/archive/2010/12/02/1894648.html

这次我们来说说控件属性的串行化。

目的:


我们要明确控件属性为什么要串行化?

关于串行化的定义如果你还不熟悉的话可以Baidu下,简单的说就是,我们要将我们在控件属性上设定的值持久化到代码中,这样我们下次再查看控件的值依然是我们最后一次设定的值。

备注:


关于DesignerSerializationVisibilityAttribute的解释

  指示一个属性是否串行化和如何串行化,它的值是一个枚举,一共有三种类型Content,Hidden,Visible。

  Content 指示代码生成器为对象包含的内容生成代码,而不是为对象本身;

  Hidden 指示代码生成器不为对象生成代码;

  Visible 指示代码生成器为对象生成代码。

1.假如你的控件有一个集合属性,又想在设计时自动将集合属性的内容生成代码,那么就使用这个Attribute,并将值设为DesignerSerializationVisibility.Content;

2.没有DesignerSerializationVisibilityAttribute的成员将被视为具有值为 Visible 的 DesignerSerializationVisibilityAttribute,如果可能,序列化程序会将标记为 Visible 的属性 (Property) 值序列化为该类型;

下面我来看下窗体控件的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinFormControlLibrary
{
    public partial class ThirdControl自定义控件属性的串行化 : Control
    {
        #region Field
        /// <summary>
        /// 名
        /// </summary>
        private String _firstName = "Bobby";
        /// <summary>
        /// 姓
        /// </summary>
        private String _lastName = "Chen";

        /// <summary>
        /// 集合1
        /// </summary>
        private List<Int32> _collection1 = new List<Int32>();
        /// <summary>
        /// 集合2
        /// </summary>
        private List<Int32> _collection2 = new List<Int32>();
        
        [BrowsableAttribute(true)]
        // 若不设置,则默认为 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public List<Int32> Collection1
        {
            get { return _collection1; }
            set { _collection1 = value; }
        }

        [BrowsableAttribute(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public List<Int32> Collection2
        {
            get { return _collection2; }
            set { _collection2 = value; }
        }

        [
        BrowsableAttribute(true),
        BindableAttribute(false),
        CategoryAttribute("自定义项目"),
        DescriptionAttribute("名"),
        ]
        public String FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }

        [
        BrowsableAttribute(true),
        BindableAttribute(false),
        CategoryAttribute("自定义项目"),
        DescriptionAttribute("姓"),
        ]
        public String LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }
        #endregion

        public ThirdControl自定义控件属性的串行化()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            #region 重绘控件
            Graphics g = pe.Graphics;

            //
            // 设定大小区域
            //
            Size size = new Size(Size.Width - 1, Size.Height - 1);
            //
            // 设定Control 的大小
            //
            Rectangle rectagle = new Rectangle(Point.Empty, size);

            // 绘制控件边框
            g.DrawRectangle(Pens.Black, rectagle);

            // 绘制控件内容
            for (Int32 i = 0; i < _collection1.Count; i++)
            {
                g.DrawString(_collection1[i].ToString(), Font, Brushes.Red, 1, i * FontHeight);
            }

            for (Int32 i = 0; i < _collection2.Count; i++)
            {
                g.DrawString(_collection2[i].ToString(), Font, Brushes.Red, 10, i * FontHeight);
            }
            #endregion
        }
    }
}

在这个控件中,我们定义了两个泛型集合Collection1 和 Collection2 。

Collection1默认没有使用DesignerSerializationVisibilityAttribute属性,因此会默认提供为控件指定DesignerSerializationVisibilityAttribute.Visible值;

Collection2则指定了DesignerSerializationVisibilityAttribute.Content值;

我们将控件添加到一个窗体中,并为Collection1赋值 1,2,3,4,为Collection2赋值 5,6,7,8

下面我们来看一下这个控件在窗体中的代码:

namespace 自定义窗体控件Demo
{
    partial class 之四窗体控件实现属性的串行化
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(之四窗体控件实现属性的串行化));
            this.thirdControl自定义控件属性的串行化1 = new WinFormControlLibrary.ThirdControl自定义控件属性的串行化();
            this.SuspendLayout();
            // 
            // thirdControl自定义控件属性的串行化1
            // 
            this.thirdControl自定义控件属性的串行化1.Collection1 = ((System.Collections.Generic.List<int>)(resources.GetObject("thirdControl自定义控件属性的串行化1.Collection1")));
            this.thirdControl自定义控件属性的串行化1.Collection2.Add(4);
            this.thirdControl自定义控件属性的串行化1.Collection2.Add(5);
            this.thirdControl自定义控件属性的串行化1.Collection2.Add(6);
            this.thirdControl自定义控件属性的串行化1.Collection2.Add(7);
            this.thirdControl自定义控件属性的串行化1.FirstName = "Bobby";
            this.thirdControl自定义控件属性的串行化1.LastName = "Chen";
            this.thirdControl自定义控件属性的串行化1.Location = new System.Drawing.Point(30, 12);
            this.thirdControl自定义控件属性的串行化1.Name = "thirdControl自定义控件属性的串行化1";
            this.thirdControl自定义控件属性的串行化1.Size = new System.Drawing.Size(133, 93);
            this.thirdControl自定义控件属性的串行化1.TabIndex = 0;
            this.thirdControl自定义控件属性的串行化1.Text = "thirdControl自定义控件属性的串行化1";
            // 
            // 之四窗体控件实现属性的串行化
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(297, 262);
            this.Controls.Add(this.thirdControl自定义控件属性的串行化1);
            this.Name = "之四窗体控件实现属性的串行化";
            this.Text = "之四窗体控件实现属性的串行化";
            this.ResumeLayout(false);

        }

        #endregion

        private WinFormControlLibrary.ThirdControl自定义控件属性的串行化 thirdControl自定义控件属性的串行化1;
    }
}
em.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(之四窗体控件实现属性的串行化));
            this.thirdControl自定义控件属性的串行化1 = new WinFormControlLibrary.ThirdControl自定义控件属性的串行化();
            this.SuspendLayout();
            // 
            // thirdControl自定义控件属性的串行化1
            // 
            this.thirdControl自定义控件属性的串行化1.Collection1 = ((System.Collections.Generic.List<int>)(resources.GetObject("thirdControl自定义控件属性的串行化1.Collection1")));
            this.thirdControl自定义控件属性的串行化1.Collection2.Add(4);
            this.thirdControl自定义控件属性的串行化1.Collection2.Add(5);
            this.thirdControl自定义控件属性的串行化1.Collection2.Add(6);
            this.thirdControl自定义控件属性的串行化1.Collection2.Add(7);
            this.thirdControl自定义控件属性的串行化1.FirstName = "Bobby";
            this.thirdControl自定义控件属性的串行化1.LastName = "Chen";
            this.thirdControl自定义控件属性的串行化1.Location = new System.Drawing.Point(30, 12);
            this.thirdControl自定义控件属性的串行化1.Name = "thirdControl自定义控件属性的串行化1";
            this.thirdControl自定义控件属性的串行化1.Size = new System.Drawing.Size(133, 93);
            this.thirdControl自定义控件属性的串行化1.TabIndex = 0;
            this.thirdControl自定义控件属性的串行化1.Text = "thirdControl自定义控件属性的串行化1";
            // 
            // 之四窗体控件实现属性的串行化
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(297, 262);
            this.Controls.Add(this.thirdControl自定义控件属性的串行化1);
            this.Name = "之四窗体控件实现属性的串行化";
            this.Text = "之四窗体控件实现属性的串行化";
            this.ResumeLayout(false);

        }

        #endregion

        private WinFormControlLibrary.ThirdControl自定义控件属性的串行化 thirdControl自定义控件属性的串行化1;
    }
}

我们重点看一下 thirdControl自定义控件属性的串行化1 这个代码,我把它单独列出来,如下:

// 
// thirdControl自定义控件属性的串行化1
// 
this.thirdControl自定义控件属性的串行化1.Collection1 = ((System.Collections.Generic.List<int>)(resources.GetObject("thirdControl自定义控件属性的串行化1.Collection1")));
this.thirdControl自定义控件属性的串行化1.Collection2.Add(4);
this.thirdControl自定义控件属性的串行化1.Collection2.Add(5);
this.thirdControl自定义控件属性的串行化1.Collection2.Add(6);
this.thirdControl自定义控件属性的串行化1.Collection2.Add(7);
this.thirdControl自定义控件属性的串行化1.FirstName = "Bobby";
this.thirdControl自定义控件属性的串行化1.LastName = "Chen";
this.thirdControl自定义控件属性的串行化1.Location = new System.Drawing.Point(30, 12);
this.thirdControl自定义控件属性的串行化1.Name = "thirdControl自定义控件属性的串行化1";
this.thirdControl自定义控件属性的串行化1.Size = new System.Drawing.Size(133, 93);
this.thirdControl自定义控件属性的串行化1.TabIndex = 0;
this.thirdControl自定义控件属性的串行化1.Text = "thirdControl自定义控件属性的串行化1";

Collection1中添加的数值(1,2,3,4)没有在窗体的Designer中生成代码,其实他被编译到窗体的资源文件中去了;

Collection2中的数值我们可以清楚的看见,因为使用了DesignerSerializationVisibilityAttribute.Content 所以指定的在窗体的Designer中自动产生了代码;

我们再来看看窗体中是怎样调用资源文件的:

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(之四窗体控件实现属性的串行化));
this.thirdControl自定义控件属性的串行化1 = new WinFormControlLibrary.ThirdControl自定义控件属性的串行化();
this.SuspendLayout();

最后我们看下效果:

好了,基本上如何使用DesignerSerializationVisibilityAttribute属性就是这些内容了。

做到这里有肯能有人要问如果得的Collection是一个自定义类型,我要如何在窗体中进行设置呢,下一次我们讲TypeConverterAttribute类型转换属性将解决这个问题。


05-SA8155 QNX Display框架及代码分析(1) 显示是非常重要的一个模块,人机交互的桥梁。那么SA8155 Hypervisor显示是如何处理的呢。对处理流程非常的好奇O(∩_∩)O哈哈~。TODO。 阅读详情

相关推荐

如何打开本地网络的防火墙端口(Windows版)解决ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。问题

ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。 最开始在遇到这个报错的时候十分不解,后来经过思考,有可能是服务器端口占用,或者并没有放行。因此搜查问题的关键是要先去排查问题。 在搜索栏输入控制面板 选择防火墙 选择开关 保证这些选项是开着的 选择高级设置 新建规则 创建协议端口 选择端口 允许连接 点击下一步 创建规则后点击下一步(后命名) 选择任意端口ALL即可 问题排查完毕!socket创建网络通信时,有读者

weixin_46900108的博客 9万+

C#用户控件的创建

频繁要用到的控件,在系统控件或者第三方控件又找不到合适的,就做成用户控件,节约时间,方便使用。 这里以自定义按钮控件为例,介绍用户控件创建过程。 1. 新建windows窗体控件库项目。 2. 创建成功后,即可看到控件的原始形态。将UserControl1类重命名为MyButton。 3. 这里我们要实现一个自定义的按钮,按钮

已被格式化的叔叔 7011

海康威视摄像头CVE-2017-7921漏洞复现:从零到一的实战指南(含解密工具下载)

本文详细解析了海康威视摄像头CVE-2017-7921漏洞的技术原理与复现方法,提供从环境搭建到实战利用的完整指南。通过认证绕过漏洞,攻击者可获取敏感信息并执行高权限操作,文章还包含解密工具下载与防御建议,助力安全研究人员深入理解物联网设备安全风险。

weixin_29325515的博客 803

【WinForm窗体控件开发】之四 DesignerSerializationVisibilityAttribute 控件属性的串行化...

这次我们来说说控件属性的串行化。 目的: 我们要明确控件属性为什么要串行化? 关于串行化的定义如果你还不熟悉的话可以Baidu下,简单的说就是,我们要将我们在控件属性上设定的值持久化到代码中,这样我们下次再查看控件的值依然是我们最后一次设定的值。 备注: 关于DesignerSerializationVisibilityAttribute的解释   指示一个属性是否串行化和如何...

weixin_30292745的博客 400

Stata实战:5步搞定PSM倾向得分匹配(附完整代码与常见报错解决)

本文详细介绍了使用Stata进行PSM(倾向得分匹配)的5步实战流程,包括数据预处理、模型构建、匹配算法选择、匹配质量诊断和结果解释。提供完整代码示例和常见报错解决方案,帮助研究者高效完成实证分析,提升匹配成功率。

weixin_29214559的博客 590

2026年AI技能进阶指南:从提示词工程到智能体开发实战

提示词工程作为AI时代的基础沟通技能,其核心原理是通过系统化的交互方法论实现与大模型的高效对话。这项技术通过明确性、具体性和可操作性的设计原则,显著提升了AI生成内容的质量和实用性。在工程实践层面,提示词工程已经发展出角色扮演、步骤分解等成熟模式,广泛应用于代码生成、技术方案设计等场景。随着AI智能体开发的兴起,提示词工程进一步演化为定义智能体身份认知和行为规范的系统接口设计,成为构建自主AI系统的关键技术基础。掌握从基础提示词到智能体开发的完整技能栈,能够帮助开发者在AI技术浪潮中保持核心竞争力。

weixin_33139275的博客 332

.net组件开发——DesignerSerializationVisibility

指定属性是否以及如何在代码中序列化, &lt;wbr&gt;&lt;/wbr&gt; 其值为DesignerSerializationVis&lt;wbr&gt;ibility的枚举值,存在3种设置方式:&lt;/wbr&gt; &lt;wbr&gt;&lt;/wbr&gt; DesignerSerializationVis&lt;wbr&gt;ibility.&lt;strong

bulote 534

解锁Jetbrains AI助手:中国开发者实战配置与效率跃迁指南

本文为中国开发者提供了一份详细的Jetbrains AI助手实战配置指南。针对服务地域限制,核心解决方案是通过修改Jetbrains账户区域信息并配置网络代理,实现插件的稳定启用。文章进一步分享了AI助手在解读遗留代码、生成中文提交信息、智能问答等场景下的具体应用,旨在帮助开发者深度集成这一工具,实现编码生产力的显著提升。

weixin_28832121的博客 569

.net组件开发--DesignerSerializationVisibility

指定属性是否以及如何在代码中序列化, 其值为DesignerSerializationVisibility的枚举值,存在3种设置方式: DesignerSerializationVisibility.Hidden 指定序列化程序不应该序列化属性值; DesignerSerializationVisibility.Visible 指定应该允许序列化程序序列化属性的值; DesignerS...

weixin_30703911的博客 1095

测试人必看!正交表与Allpairs工具对比:如何选择最适合你的组合测试方案?

本文深入对比了正交表、PICT与Allpairs三种主流组合测试方案,帮助测试人员根据项目场景做出最佳选择。文章分析了各自的核心原理、优劣势及适用场景,特别强调了在涉及复杂约束时PICT工具的强大功能,并提供了从原理学习到CI/CD集成的实战选型指南。

weixin_29224309的博客 267

基于Android Studio的校园智能点餐系统开发实战(附完整源码与部署指南)

本文详细介绍了基于Android Studio开发校园智能点餐系统的完整流程,包括需求分析、环境搭建、数据库设计、客户端与后台功能实现。系统采用SSM框架和MySQL数据库,解决了校园食堂高峰期排队问题,提供高效的点餐体验。附完整源码与部署指南,助力开发者快速构建类似应用。

weixin_29015801的博客 558

设计时属性:设计时属性相关类型

属性的设计时特性.NET Framework为控件设计时属性提供了很多丰富的类,这些属性的功能非常灵活,控制范围广泛,比如可以控制该属性在属性窗口中的显示模式,如:是否在属性窗口中显示该属性,也可以指定此属性必须接收值类型描述,按组分类等,也可以控制文本的标记呈现格式等,甚至可以自己定义一个属性类,实现自己想实现的功能。下面讲一下常用的.NET Framework的属性类对控件的支持功能。Bi

wonsoft的专栏 3095

Aurix TC387 Ethernet代码解析之二_移植

英飞凌官方仅提供了TC397的例程,故需通过TC397例程来移植到TC387新建工程里。TC397官方例程名称【Ethernet_1_KIT_TC397_TFT】,网络上可以免费获取到,此处不赘述。使用工具【

m0_69929716的博客 884

自定控件设置控件属性用到的一些类

DesignerSerializationVisibility: 自定义控件时,在属性中设置DesignerSerializationVisibility为Hidden,可以保持组件设计时的值,不在拖拽组件时InitializeComponent()方法中再重新生成。 MSDN中的详细介绍: 字段   名称 说明 Content 指定

编织梦想 977

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

C#入门学习-----选项卡(更改显示样式、动态添加/删除、获得名称)

欢迎大家提出意见,一起讨论! 转载请标明是引用于 http://blog.youkuaiyun.com/chenyujing1234 需要源码请与我联系。   运行效果如下: 1、更改显选项卡的显示样式 1、1 关键技术: 用到了TabControl控件的ImageList属性和Appearance属性。 (1) ImageList属性  此属性用来获取或设置在控件的选项卡上显示的图像,

chenyujing1234的专栏 2万+

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

DesignerSerializationVisibility, Browsable,Category Attribute

DesignerSerializationVisibility, Browsable,Category Attribute 1. DesignerSerializationVisibility 指在design time的时候,在property grid中设置的某个属性的值是否应该插入到InitializeCompone...

weixin_30243533的博客 419

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

C#中的自定义控件中的属性、事件及一些相关特性的总结(转)

摘要: C#中的自定义控件中的属性(Property)、事件(Event)及一些相关特性(Attribute)的总结 今天学习了下C#用户控件开发添加自定义属性的事件,主要参考了MSDN,总结并实验了一些用于开发自定义属性和事件的特性(Attribute)。 在这里先说一下我的环境: 操作系统:Windows7旗舰版(Service Pack 1) VS版本:Microsoft Visual Studio Ultimate 2012,版本 11.0.50727.1 RTMREL .NET Framework

qq_39300041的博客 6447

【C#】winform自定义控件在工具箱中显示和属性在属性面板中显示

在开发自定义控件件时,有好些Design属性是要使用的,如ToolboxItem, ToolboxBitmap, Category, Description等等,不知道这些属性其实也可以将控件搞出来,不过,知道了,会令事件更加简单,令控件更加专业和实用。有时,不知道用法,会令到项目的其他同事好烦,因为这个控件是你提供的。下面对一些常用的Design属性做一个简单的生产介绍。 ToolboxIte...

catshitone的专栏 1万+

C#-winform自定义控件在工具箱中显示和属性在属性面板中显示

【C#】winform自定义控件在工具箱中显示和属性在属性面板中显示 转载JimCarter最后发布于2019-02-12 17:35:07阅读数 2923收藏 展开 在开发自定义控件件时,有好些Design属性是要使用的,如ToolboxItem,ToolboxBitmap,Category,Description等等,不知道这些属性其实也可以将控件搞出来,不过,知道了,会令...

cxu123321的博客 1943

[译] WinForms:分析一下(我用 Visual Basic 写的)

▲点击上方“DotNet NB”关注公众号回复“1”获取开发者路线图学习分享丨作者/郑子铭这是DotNetNB公众号的第233篇原创文章原文 | Klaus Loeffelmann翻译 | 郑子铭如果您从未看过电影《分析这一点》,下面是简短的介绍:假设一个纽约家族的成员有可疑的习惯,他决定认真考虑接受治疗以改善他的精神状态。在比利·克里斯托和罗伯特·德尼罗的推动下,剧情一定...

dotNET跨平台 183

web控件开发系列(四) 自定义控件属性(下)

控件在WEB开发时经常要用到,虽然有部分已经存在工具箱里,但有时总需要根据自己的要求,开发一些合适自己的控件。接上一节,已经说过了控件的属性, 例如,我们需要一组属性的集合时,这时我们需要用到的就是复杂属性了,简单的属性满足不了我们的要求,例如:大家熟悉的字体信息设置那栏。下面为大家介绍一下实现的几种代码与注意细节 一、连字符形式的复杂属性标记&lt;asp:Button ID="Button1...

weixin_33890499的博客 179

C#中的自定义控件中的属性、事件及一些相关特性的总结

今天学习了下C#用户控件开发添加自定义属性的事件,主要参考了MSDN,总结并实验了一些用于开发自定义属性和事件的特性(Attribute)。 在这里先说一下我的环境: 操作系统:Windows7旗舰版(Service Pack 1) VS版本:Microsoft Visual Studi...

770

C#窗体自定义控件特性(Attribute)的使用

摘要: C#中的自定义控件中的属性(Property)、事件(Event)及一些相关特性(Attribute)的总结 今天学习了下C#用户控件开发添加自定义属性的事件,主要参考了MSDN,总结并实验了一些用于开发自定义属性和事件的特性(Attribute)。 在这里先说一下我的环境: 操作系统:Windows7旗舰版(Service Pack 1) VS版本:Microsoft Visua...

breakbridge的博客 1526

C# 特性(attribute)

特性的定义:公共语言运行时允许添加类似关键字的描述声明,叫做attribute,它对程序中的元素进行标注,如类型、字段、方法、和属性等。attribute和.NetFramework文件的元数据保存在一起,可以用来在运行时描述你的代码,或者在程序运行的时候影响应用程序的行为。定制特性attribute,本质上是一个雷,其为目标元素提供关联附加信息,并在运行期以反射的方式来获取附加信息。1、定制特性应用范围定制特性可以应用的目标元素包括:程序集(assembly);模块(module);

1628

在VS2008中创建自定义控件(十一)添加在属性窗口中可折叠的属性(一)

什么是在属性窗口中可折叠的属性?废话少说,先上图,看看图一马上就明白了。 图一 在大多数服务器控件的属性窗口中可以看到如上图所示的Font属性,这个属性是用于设置控件中文字的字体。由于文字字体包括是否加粗、是否斜体、使用什么字体、字体大小是多少等内容,因此,可以把这个内容以子属性的方式放在Font属性下,而这个Font属性就是一个在属性窗口中可折叠的属性。 我们接着《在VS2008中创建自定义控件(九)添加属性》来,现在我们要添加一个唐诗作者的属性,由于古人除了姓名之

没有标题,只有问题 5068

集合属性的持久化——用集合编辑器编辑集合属性并自动生成代码

集合属性,集合编辑器,持久化,自动生成代码

lubiaopan的专栏 6835
上一篇: 【WinForm窗体控件开发】之三续 窗体控件设计时的事件属性
下一篇: 【Winform窗体控件开发】之五 实现类型转换器TypeConverterAttribute
「已注销」
博客等级 码龄14年 116粉丝 43原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值