My project is to create controls inside a class library and then display them in another application. I already added the class library to my reference inside the application and added System.Windows.Forms to my class library.

Here is the code in the class library:

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace InterfaceLibrary
{


    public class Interface : Form
    {


        public void RegisterInterface()
        {

            InitializeComponent();

        }




            private void InitializeComponent()
            {
                this.btnConnect = new System.Windows.Forms.Button();
                this.lblInterface = new System.Windows.Forms.Label();
                this.cboInterface = new System.Windows.Forms.ComboBox();
                this.lblAddress = new System.Windows.Forms.Label();
                this.cboAddress = new System.Windows.Forms.ComboBox();
                this.SuspendLayout();
                // 
                // btnConnect
                // 
                this.btnConnect.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.btnConnect.Location = new System.Drawing.Point(61, 187);
                this.btnConnect.Name = "btnConnect";
                this.btnConnect.Size = new System.Drawing.Size(120, 39);
                this.btnConnect.TabIndex = 3;
                this.btnConnect.Text = "Connect";
                this.btnConnect.UseVisualStyleBackColor = false;
                // 
                // lblInterface
                // 
                this.lblInterface.AutoSize = true;
                this.lblInterface.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lblInterface.Location = new System.Drawing.Point(42, 44);
                this.lblInterface.Name = "lblInterface";
                this.lblInterface.Size = new System.Drawing.Size(57, 15);
                this.lblInterface.TabIndex = 0;
                this.lblInterface.Text = "Interface:";
                // 
                // cboInterface
                // 
                this.cboInterface.DisplayMember = "I2C";
                this.cboInterface.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
                this.cboInterface.FormattingEnabled = true;
                this.cboInterface.Location = new System.Drawing.Point(105, 41);
                this.cboInterface.Name = "cboInterface";
                this.cboInterface.Size = new System.Drawing.Size(63, 21);
                this.cboInterface.TabIndex = 1;
                // 
                // lblAddress
                // 
                this.lblAddress.AutoSize = true;
                this.lblAddress.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lblAddress.Location = new System.Drawing.Point(5, 121);
                this.lblAddress.Name = "lblAddress";
                this.lblAddress.Size = new System.Drawing.Size(44, 15);
                this.lblAddress.TabIndex = 0;
                this.lblAddress.Text = "label1:";
                // 
                // cboAddress
                // 
                this.cboAddress.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
                this.cboAddress.FormattingEnabled = true;
                this.cboAddress.Location = new System.Drawing.Point(105, 118);
                this.cboAddress.Name = "cboAddress";
                this.cboAddress.Size = new System.Drawing.Size(120, 21);
                this.cboAddress.TabIndex = 2;
                // 
                // Interface
                // 
                this.ClientSize = new System.Drawing.Size(327, 262);
                this.Name = "Interface";
                this.ResumeLayout(false);

            } 

            private System.Windows.Forms.Button btnConnect;
            private System.Windows.Forms.Label lblInterface;
            private System.Windows.Forms.ComboBox cboInterface;
            private System.Windows.Forms.Label lblAddress;
            private System.Windows.Forms.ComboBox cboAddress;
    }
}

So I've made some changes. Instead of creating gui controls in my class library, I made a whole form and passed it to my application, iFaceForm is the form inside of the class library.

  class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new iFaceForm());

        }

    }

If I want to add call back functions/structs/enums that would be called inside the class library API, where would I put them? Need some help asap, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.