Solved

Help with "partial" user control problem

Posted on 2007-04-07
2
179 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

861 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now