?
Solved

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

Posted on 2006-04-24
5
Medium Priority
?
241 Views
Last Modified: 2010-04-16
how do I make my app such that it implements a custom form object?
0
Comment
Question by:Thunder_scream
  • 4
5 Comments
 
LVL 5

Accepted Solution

by:
GENTP earned 150 total points
ID: 16527853


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

}

class frmMain : myWindowsForm
{
 // Program code goes here
}
0
 
LVL 2

Author Comment

by:Thunder_scream
ID: 16576755
Hi! again sorry I have been away for a while..

ok thanks for the quick response...
0
 
LVL 2

Author Comment

by:Thunder_scream
ID: 16576768
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
 
LVL 2

Author Comment

by:Thunder_scream
ID: 16576789
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
 
LVL 2

Author Comment

by:Thunder_scream
ID: 16576791
the InitComp that is
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question