Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between property and attribute of custom controls in C #

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you what is the difference between property and attribute of custom controls in C#, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.

These two days, in using c # custom control, the property window provided to us by. Net is very easy to use, we can change the property without writing code, so if we customize the control, can we change it directly in the property bar?

Yes, it is possible. .net has been figured out for us (they also use it in the development process).

First of all, for example, we need to add a string property to the control we define (if you don't understand the property, learn what a property is).

Private string mytext public string Mytext {get {return this.mytext;} set {this.mytext = value;}}

In this way, we can get or change the Mytext property in the program, but the property we have now can't be seen in the properties bar in the vs development environment. Why, because we still lack something. If we add something in front of the attribute, it will be fine.

Use C# custom controls like this

Private string mytext [Browsable (true)] / / specifies whether [DesignerSerializationVisibility (DesignerSerializationVisibility. Visible)] / / specifies the visibility of the property to the design-time serializer. Public string Mytext {get {return this.mytext;} set {this.mytext = value;}}

If we try again, we will find that we can set it in the property bar.

There are many other such attributes, if you are interested, you can take a look at the System.ComponentModel namespace

There seems to be a lot of attributes that can be used as long as the classes end with Attribute, so I won't enumerate them one by one here.

The System.ComponentModel namespace provides classes that implement the runtime and design-time behavior of components and controls. This namespace includes base classes and interfaces for implementing property and type converters, binding to data sources, and authorization components.

The classes in this namespace are divided into the following categories:

Core component class.

Component authorization.

Property.

Specifiers and persistence.

Type converter.

The above is all the content of the article "what is the difference between property and attribute of custom controls in C#". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report