how do I make my app such that it implements a custom form object?

how do I make my app such that it implements a custom form object?
LVL 2
Thunder_screamAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GENTPCommented:


class myWindowsForm : System.Windows.Forms.Form
{
// Put your special methods, properties in here

}

class frmMain : myWindowsForm
{
 // Program code goes here
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thunder_screamAuthor Commented:
Hi! again sorry I have been away for a while..

ok thanks for the quick response...
Thunder_screamAuthor Commented:
So I have followed your example, creating a small program with a button that when pressed changes a rectangle drawing to a circle.

but the compiler complains that the initcomp does not exist...could you perhaps tell me what might be wrong? do I need to create a constructor for the customForm aswell? and put initcomp inside?

here is the code

using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;


namespace CFproject
{
    public class myCustomForm : Form
    {
                       
        // Required designer variable.
        private System.ComponentModel.IContainer components = null;

        //Clean up any resources being used.
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
       
       
        private void InitComp()
        {
            this.btn1 = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.txtBxShapeInfo = new System.Windows.Forms.TextBox();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            //
            // btn1
            //
            this.btn1.Location = new System.Drawing.Point(161, 19);
            this.btn1.Name = "btn1";
            this.btn1.Size = new System.Drawing.Size(92, 23);
            this.btn1.TabIndex = 0;
            this.btn1.Text = "Change shape?";
            this.btn1.UseVisualStyleBackColor = true;
            //this.btn1.Click += new System.EventHandler(this.btn1_Click);
            //
            // groupBox1
            //
            this.groupBox1.Controls.Add(this.txtBxShapeInfo);
            this.groupBox1.Controls.Add(this.btn1);
            this.groupBox1.Location = new System.Drawing.Point(12, 202);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(268, 52);
            this.groupBox1.TabIndex = 1;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "ToolBox";
            //
            // txtBxShapeInfo
            //
            this.txtBxShapeInfo.Location = new System.Drawing.Point(27, 21);
            this.txtBxShapeInfo.Name = "txtBxShapeInfo";
            this.txtBxShapeInfo.ReadOnly = true;
            this.txtBxShapeInfo.Size = new System.Drawing.Size(100, 20);
            this.txtBxShapeInfo.TabIndex = 1;
            this.txtBxShapeInfo.Text = "Rectangle";
            this.txtBxShapeInfo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            //
            // CustomForm
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.groupBox1);
            this.Name = "Form1";
            this.Text = "Exercise One";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);

        }
        private System.Windows.Forms.Button btn1;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.TextBox txtBxShapeInfo;
    }//end of customform class

   
    public class mainF : myCustomForm
    {
        private Graphics gObj;
        SolidBrush brush = new SolidBrush(Color.Blue);

        public mainF()
        {    
            Initcomp();
            gObj = this.CreateGraphics();
        }

        /*
        private void btn1_Click(object sender, EventArgs e)
        {
            if (txtBxShapeInfo.Text == "Circle")
            {
                //change the text box info
                this.txtBxShapeInfo.Text = "Rectangle";
                //clean the form
                gObj.Clear(this.BackColor);
                // set brush to blue
                brush.Color = Color.Blue;
                // create filled rectangle
                gObj.FillRectangle(brush, 90, 30, 150, 90);
            }
            else
            {
                //change the text box info
                this.txtBxShapeInfo.Text = "Circle";
                //clean the form
                gObj.Clear(this.BackColor);
                // set brush to red
                brush.Color = Color.Red;
                // draw Ellipse outline
                gObj.FillEllipse(brush, 90, 30, 100, 100);
            }
        }*/

        // override Form OnPaint method
        protected override void OnPaint(PaintEventArgs paintEvent)
        {
            // get graphics object
            Graphics g = paintEvent.Graphics;

            // create filled rectangle
            g.FillRectangle(brush, 90, 30, 150, 90);

        } // end method OnPaint*/
    }  
}


using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;

namespace CFproject
{
    static class mainprog
    {
        /// The main entry point for the application.
       
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainF());
        }
    }
}
Thunder_screamAuthor Commented:
sorry it was the spelling that caused the problem.... but the question still remains should I call it in the customform or the mainform?
Thunder_screamAuthor Commented:
the InitComp that is
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.