Reputation: 414
I want to handle and control a Class Library project in C# with another application.
I intend to follow below steps,
- Create a Class Library Project
- Add windows form inside this Class Library Project
Create another project but this time a Windows Form Application
Open the Windows form (created in step 2) inside that Class library project through Windows Form Application (Created in step 3)
.
I have previously used UI automation to handle WPF or Windows form applications but how can i handle Class Library project?
Need guidance please.
EDIT:
I have opened the Class Library Form by adding the dlls in Windows Form Application and then creating the object and using the show method to display form like below,
ClassLibTestProject.Form1 f = new ClassLibTestProject.Form1();
f.Show();
Now, I want to change the text in the textbox which is present in ClassLibrary project. The name of the textbox is textbox1. I want to do something like this textbox1.text ="Text changed from Windows Form Application"; But how should I get the handle of this textbox in Windows Form Application?
Upvotes: 0
Views: 1228
Reputation: 32445
Do not expose form controls to "outside world", instead provide public method which can be called by form consumers.
Inside method you can update you control.
In library project
public class Form1
{
public void UdpateTextBoxWith(string newText)
{
textbox1.Text = newText;
}
}
In Winforms application
var form = new ClassLibTestProject.Form1();
form.Show();
form.UdpateTextBoxWith("New text");
Upvotes: 1