0

Here are the steps I have used to create the winforms Project OneB
Using Visual Studio 2019 with Net 4.8 I created OneB
Then I created a Windows Forms Class Library named CLP.
Opened OneB and Added Existing Project CLP and then Added Reference to CLP.
Here is the code in OneB The issue is with this line of code form.Show();

namespace OneB
{
    public partial class frmStart : Form
    {
        string SS;

        public frmStart()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnShowLib_Click(object sender, EventArgs e)
        {
            SS = "HI we are from OneB";
            var form = new CLP.Form1();
            form.UdpateTextBoxWith(SS);
            form.Show();
        }
    }

Now the code in CLP the Class Library
This code references a textbox1 BUT the project has no Form that the textbox1 can live on.

namespace CLP
{

    public class Form1
        {
        private object textbox1;
        private object newText;

        public object SS { get; private set; }

        public void UdpateTextBoxWith(string v)
            {
                newText = SS;
                textbox1 = newText;
            }
        public void Show()
        {
            // This is intelesense suggestion YEP it throws
            throw new NotImplementedException();
        }
    }

OK Number of Issues here
How do I call the Class Library ?
With NO form to show the textox1 text change should I be using a Control Library ?
This is just a test project my final goal is to use a Library Class or Control Library to
call CRUD methods for a SQLite DB
Side NOTE I made this change from 5 to 4.8 in both projects

<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
Vector
  • 3,066
  • 5
  • 27
  • 54
  • It looks like you just added a class and named it `Form1` and expected it to work as a form. Forms have to inherit the `Form` class which provides a lot of base functionality for them. Get rid of your class and actually add a Windows Form, just as you would in an application project. I don't think you should have to create a Control Library project for that. i think the only difference is a Class Library adds a simple class by default while a Control Library adds a user control. – jmcilhinney Mar 15 '23 at 03:52
  • @jmcilhinney OK I can make it work with a Form added but now the Class Library is codeless and does Nothing so I am not sure this Class Library is even need with this design Not what I had in mind – Vector Mar 15 '23 at 05:33
  • How can it be codeless if it has a form in it? A form is a class so it has all the code associated with that class. If you expect to be able to update a `TextBox` then you need to add a `TextBox` to that form. I don't see why you're trying to treat this form differently to every other form you've ever used. The fact that it's in a library project rather than an application project is irrelevant. Treat it like every other form. – jmcilhinney Mar 15 '23 at 05:38
  • @jmcilhinney I stand corrected YES I do need the Class Library and the form need to be part of the Class Library When I said codeless the form I added looked like it was not part of the Class Library. I deleted the Class Library and learned my lesson NEVER doubt JMC are you still in Hawaii ? My Best – Vector Mar 15 '23 at 06:07

0 Answers0