简体   繁体   中英

WinForms UserControl design

I've created user control which hosts datagridview and other controls. Then I drop it onto a form. How do I allow myself to customize grid's properties (like which columns are shown) in a target form?
I thought setting its modifier to public will suffice.

That should do it, then you can address the grid through your user control instance. Assuming you control is named "MyControl" and your grid within the control is named "MyGrid" then you should be able to use MyControl.MyGrid. to get to the properties.

您可以向您的UserControl添加属性,以帮助您从不同形式更改控件的设计。

Problem not solved in that general way I initially posed it.
As a quick hack I declared public properties for some of the grid properties I needed (like Columns collection) Tnanx for your help, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM