Click here to Skip to main content
15,886,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have two projects open in one solution in Visual Studio 2017 (VB.NET). I have linked a button from Project1 to Project2, but I want to copy the content of the TextBox as well.


I have a RichTextBox in Project1 and a normal TextBox in Project2. I want to add a function in the button that if I click it, then it will copy whatever is written in the RichTextBox to the TextBox of another project.


P.S. Currently, the button only opens the new project and does nothing else.



Following is the code I have written to open the new project.

What I have tried:

VB

Console.WriteLine(Application.StartupPath)
        Dim WinApp2Form1 As New BasicTest.Form1
        WinApp2Form1.Show()
Posted
Updated 10-Apr-18 1:40am

1 solution

You don't want to do that, or at least. not directly.
In order to access the textbox of a different form (be it in the same assembly / project or a different one) you have to expose it as Public to the world - and that's a bad idea because it "locks" the design of both forms: you can't change it without it potentially breaking other code.

Instead, use a property on the second form which the first accesses, and the second form Setter becomes responsible for updating the text box (or whatever controls it wants to use).

There is an example here: Transferring information between two forms, Part 1: Parent to Child[^] - the code is in C#, but it's pretty obvious, and online translators can convert it if you can't work it out.
 
Share this answer
 
Comments
OriginalGriff 10-Apr-18 9:55am    
Totally different question - which needs to be in it's own post so it attracts those that deal with such things; I don't!
Primo Chalice 12-Apr-18 0:54am    
Hello,

I actually made it work. Basically I used the Clipboard function to copy the text and the pasted it in the second project, using Clipboard function on a Button1_Click event.
OriginalGriff 12-Apr-18 3:10am    
NEVER DO THAT!

There is only one Clipboard for the whole machine, and if you mess with the content, you will seriously piss off users.
If I'm also working on a complex image for example, the clipboard may contain the results of an hours work clipping out a specific item from a bitmap. Along comes your app and throws that in the bin. Just how happy do you think I am going to be?

Never, ever, EVER, touch the clipboard without the specific express orders from the user - or your software will be uninstalled with extreme prejudice!

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