Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a keyboard using a controller to use in multiple forms.
Using single creation i need to use it in different forms

What I have tried:

I made a panel and created buttons in it ,but this way I have to create panel in each forms
Posted
Updated 3-Sep-22 1:09am

1 solution

Create it as a UserControl: UserControl Class (System.Windows.Forms) | Microsoft Docs[^] it's kind of like a Panel, but it holds all your controls and acts as a single object you can add from the toolbox or programmatically.
 
Share this answer
 
Comments
Member 15310789 4-Sep-22 11:43am    
I created usercontrol and added buttons . but when i added this control in other form , not being able to access controls of that form (From usercontrol button click , want to sent data to textbox )
OriginalGriff 4-Sep-22 12:15pm    
You don't access containers from within contained controls: the UserControl is a "black box" that doesn't know anything about it's parent, in the same way that a Button doesn't know anything about the Form it's been dropped on. And it doesn't need to: it exposes properties (like Text) which provide information to the Form, and Events (like Click) which tell the Form that something has happened. The Form then handles the Event (if it wants to) and accesses the Text to do with what it will.

Your UserControl talks to the parent Form the same way: it provides Properties and Events. That may sound complicated, but it really isn't - it's pretty simple to do.
Have a look here:
Transferring information between two forms, Part 2: Child to Parent[^]
It shows how to set it all up - it's Form based, but UserControls are exactly the same code (as you'd expect since they are both derived from Control).

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