Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

I designed a myFormClass, inherited from C# 2013 .Net 4 winforms, (System.Windows.Forms.Form class).
And I place a PictureBox control (named it: pbxImage) in myFormClass.
Also I add a property to myFormClass (named it: PictureBoxImage) to assign a picture to pbxImage.BackgroundImage at design/run time.
Then, I add a windows form (named it: frmMain) to my project and inherit it from myFormClass.

Now I want:
1- access the pbxImage properties in myFormClass code behind. for exmaple from the PictureBoxImage get and set accessors.
2- and, in frmMain properties grid window (at design time), hide the pbxImage control from the combobox list.


If I set the pbxImage.GenerateMember to false, the number 2 is success, but number 1 is fail.

If I set the pbxImage.GenerateMember to true, and any selection of pbxImage.Modifier, the number 1 is success, but the number 2 is fail and pbxImage control appear in frmMain properties grid window.

What is your suggestion?

PE:
Sample project download link (175KB): Wikisend: free file sharing service[^]
and a picture download link(232KB): Wikisend: free file sharing service[^]
In the picture i don't want see the pbxImage in Properties grid components list, and I want stay accessible the frmMain.PictureBoxImage.

Thanks a lot for your posts.
Posted
Updated 2-Jan-16 19:42pm
v2

When you place a component on a Windows Form, two properties are provided by the design environment: GenerateMember and Modifiers. The GenerateMember property specifies when the Windows Forms Designer generates a member variable for a component. The Modifiers property is the access modifier assigned to that member variable. If the value of the GenerateMember property is false, the value of the Modifiers property has no effect

Take a look at this article:
How to: Use the Modifiers and GenerateMember Properties[^]
 
Share this answer
 
You need to add an attribute which marks your member as "non-browsable". This is how: BrowsableAttribute Class (System.ComponentModel)[^].

Also, I would suggest you review your class hierarchies to isolate data types from UI types. Even if you want to control some properties which affect your UI, it's much better to put such properties in pure data types and organize collaboration between types representing UI behavior and UI itself. This way, you can represent in your PropertyGrid only the data types the user could edit. However, I don't know your goals, so I cannot give you a 100% sure advice. At least think about it.

—SA
 
Share this answer
 
Comments
Reza552 4-Jan-16 0:21am    
The BrowsableAttribute, hide a PROPERTY from Properties grid window. But I want hide entire COMPONENT from Properties grid window. The only way I know is GenerateMember property and set it to false. Is there other way?
Sergey Alexandrovich Kryukov 4-Jan-16 0:39am    
Wrong. Strictly speaking there is no such thing as "component" (there are classes named based of the word "component", but this is not a part of technology). You show top object, and what you call a "component", can be a property of this object, or some other member.

My answer is exactly what you want.

Perhaps you want to hide all instances of some class, regardless of where they are used. I'm not 100% sure, but probably there is no a way to do it universally. Come to think about, I could not see where such feature may make sense.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900