Calling code in library.cs from a control of BaseControlLibrary

BenTam 1,801 Reputation points
2022-08-24T15:10:54.437+00:00

Dear All,

I am trying to call the code in "Library.cs" from a control in "BaseControlLibrary.cproj". I plan to add more controls to BaseControlLibrary.cproj. The complete code of the project is uploaded to https://github.com/benyltam/NewTims on GitHub.com. The errors are as follows. Could I know how to fix them?

234520-error.gif

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 81,971 Reputation points Volunteer Moderator
    2022-08-24T15:27:46.697+00:00

    your GitHub project does not include the referenced library project:

      <ProjectReference Include="..\..\..\Library\Library\Library\Library.csproj">  
    

    which is several folder above the repo root


  2. AgaveJoe 30,396 Reputation points
    2022-08-24T19:20:05.35+00:00

    There's a Library.exe in bin folders. The Library project should be a class library and produce a DLL not an EXE.


  3. Karen Payne MVP 35,591 Reputation points Volunteer Moderator
    2022-08-26T15:44:59.683+00:00

    A couple of things

    • The Lib class has conflicts
    • The Button code needs to change as per below

    Build results

    2>C:\OED\DotnetLand\VS2022\TimsSolution\BaseControlLibrary\CheckBox.cs(30,21,30,27): warning CS0108: 'CheckBox.Resize()' hides inherited member 'Control.Resize'. Use the new keyword if hiding was intended.  
    2>C:\OED\DotnetLand\VS2022\TimsSolution\BaseControlLibrary\CheckBox.cs(16,20,16,30): warning CS0169: The field 'CheckBox.DefaultTop' is never used  
    2>C:\OED\DotnetLand\VS2022\TimsSolution\BaseControlLibrary\CheckBox.cs(18,20,18,33): warning CS0169: The field 'CheckBox.DefaultHeight' is never used  
    2>C:\OED\DotnetLand\VS2022\TimsSolution\BaseControlLibrary\CheckBox.cs(17,20,17,31): warning CS0169: The field 'CheckBox.DefaultLeft' is never used  
    2>C:\OED\DotnetLand\VS2022\TimsSolution\BaseControlLibrary\CheckBox.cs(19,20,19,32): warning CS0169: The field 'CheckBox.DefaultWidth' is never used  
    2>  BaseControlLibrary -> C:\OED\DotnetLand\VS2022\TimsSolution\BaseControlLibrary\bin\Debug\BaseControlLibrary.dll  
    ========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========  
    

    Revised button code

    using System.Drawing;  
    using System.Windows.Forms;  
    using Library;  
      
      
    namespace BaseControlLibrary  
    {  
        [ToolboxBitmap(@"Button.bmp")]  
        public partial class Button : UserControl  
        {  
            static int DefaultTop;  
            static int DefaultLeft;  
            static int DefaultHeight;  
            static int DefaultWidth;  
            private readonly Lib _library = new Lib();  
      
            public Button()  
            {  
                InitializeComponent();  
                DefaultTop = Top;  
                DefaultLeft = Left;  
                DefaultHeight = Height;  
                DefaultWidth = Width;  
      
                //_library.ResizeCtrl(/* TODO */);  
            }  
              
              
        }  
    }  
    

    What I mean is rename one of the Library classes or use using aliases

    235331-tims.png

    • Also, I would advise that you take time to learn how to properly organize solutions
    • Understand static
    • Where code goes e.g. as in the Button class/control
    • Consider a unique name for your Button control

  4. AgaveJoe 30,396 Reputation points
    2022-08-27T11:43:31.647+00:00

    I try to put the DLL file into the bin folder.

    There are two default folders in the bin folders depending on the project type; Debug and Release. The DLL must go into Debug folder while the project is is configured for Debug and Release when the solution is configured for a Release build. Once deployed there will be one bin folder.

    However, do not copy the DLL yourself! Create a project reference to the Library project as I recommended several times!!!! From my perspective you're performing random tasks with no idea what you're doing and you're making no effort to learn.

    These forum expect foundational experience which you clearly do not have at this point. You might consider an instructor lead course so you can get one on one support with the instructor.

    My last effort to help you - I created a public GitHub project based on your posts. There is one solution named NewTims with three projects.

    https://github.com/mjgebhard/NewTims

    BaseControlLibrary - Windows Forms Control Library (.NET Framework)

    235464-capture.png

    Library - Class Library (.NET Framework)

    235447-capture.png

    NewTims - Windows Forms App (.NET Framework)

    235458-capture.png

    The three projects are all within a single folder named NewTims.

    235446-capture.png

    Use this GitHub project to compare what you are doing.


  5. BenTam 1,801 Reputation points
    2022-09-14T15:22:52.157+00:00

    Hi @Jack J Jun

    No, Jack. I just made an apology to the one that I reply.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.