简体   繁体   中英

C# winform: communation between winform and usercontrol

I want to develop a custom button which contain a properity that can be changed dynamics according to the content. This button would be used more that once in the same form.

for example: the custom button contain a string: str. if we want the button update the database, we just need to set the string in the mainform: str= "update mytable * *". if we want the delete function, we just need to set the string into: str="delete from my table....." in the main form.

Can you give me an example? I am a newer in C#.

Its quite easy to achieve this you just need to override button class of the .net framwork and need to write you own code

you can check this blog post wheer i did the same thing for the textbox : Enhanced Textbox Control

You can create the public properties in the usercontrol and also public methods, that will be accessible from your form. Then you can allocate the value to property and call the appropriate method to execute the database tranascation statement.

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