Solved

Help with "partial" user control problem

Posted on 2007-04-07
2
181 Views
Last Modified: 2012-05-05
I currently have a form that has 6 group boxes labeled grpbox1, grpbox2, etc.  There are several controls in each of these groupboxes: chklst1, txtbox1, chklst2, txtbox2, etc.  I want to create a single user control class that encompasses all the functionality and design so I can replace the individual ones with an array list of the user control class.  I did this same procedure before a long time ago and was successful.  I'm having a hell of time trying to do it again.  When I add a new user control object to my solution, I get the following:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Inhallation
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
    }
}

This is before I cut and paste anything.  What's different is this "partial" keyword appearing.  The other isolated class I made looks like this:

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace Inhallation
{
      /// <summary>
      /// Summary description for clsDisplay.
      /// </summary>
      public class clsDisplay : System.Windows.Forms.UserControl
      {
...............

What am I doing wrong?  I can't follow the same pattern to finish this new control.  Thanks!


0
Comment
Question by:jvalescu
2 Comments
 
LVL 5

Accepted Solution

by:
Yttribium earned 250 total points
ID: 18870326
Nothing as far as I'm aware, Partial classes is a feature of .NET 2.0 if I'm not mistaken.  This allows you to create a class in 2 seperate files.   e.g.

partial class ATest
      {
            public ATest()
            {
                  i = 5;
                  //contructor
            }
      }

      partial class ATest
      {
            public int i = 0;
      }

This will compile, and work as if it were like this

class ATest
      {
            public int i = 0;
            public ATest()
            {
                  i = 5;
                  //contructor
            }
      }

Hope this helps.
0
 
LVL 3

Assisted Solution

by:kingtam2000
kingtam2000 earned 250 total points
ID: 18870329
The partial keyword is allows for classes to be split into multiple parts, so here the partial keyword allows the user control to have part of the class be in one file, which contains only the data the user adds, while there is another file, called UserControl1.Designer.cs (or whatever the UserControl is called), which contains the data that the Form Designer uses, which will contain data on the controls, etc.  To access the Designer.cs file, click the + button on the left the user control file to in the Solution Explorer, which is in the top right hand corner to expand out to get the Designer.cs file.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 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