• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

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?
0
Thunder_scream
Asked:
Thunder_scream
  • 4
1 Solution
 
GENTPCommented:


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

}

class frmMain : myWindowsForm
{
 // Program code goes here
}
0
 
Thunder_screamAuthor Commented:
Hi! again sorry I have been away for a while..

ok thanks for the quick response...
0
 
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());
        }
    }
}
0
 
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?
0
 
Thunder_screamAuthor Commented:
the InitComp that is
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now