Solved

Help with "partial" user control problem

Posted on 2007-04-07
2
178 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

17 Experts available now in Live!

Get 1:1 Help Now