Click here to Skip to main content
14,970,418 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to start out saying this is part of a homework assignment, but I'm not asking for any code. I have to create a abstract base class, with 2 subclasses, including a virtual method, and a interface. I have made all my classes and the interface, but I am stuck in creating a class to test the GUI. I have referenced all the class libraries with subclasses and the interface, but my book has another class called PresentationGUI.cs in the example. I have created the class before the form, but do not know how to implement this class to "work" with the form, I have set the presentation class as a startup project, but cannot figure out how to make it communicate with the Windows Form Designer code. In the book the presentation class, has Windows Forms code generated along with references to the namespaces of the different classes, within this presentation class, along with parts of the subclasses, but I am lost at how to accomplish this. The code in the book looks like this (I shortened it to save time):

01	using System;                //// I get an error if I type this in
02	using System.Drawing;
03	using System.Collections.Generic;
04	using System.ComponentModel;
05	using System.Windows.Forms;
06	using System.Data;
07	using ClubNamespace;       //// to reference the subclasses
08	using IntermuralNamespace;
10	namespace PresentationGUI
11	{
12	public class PresentationGUI : System.Windows.Forms.Form
13	{
14	private Club aClub;
15	private Intermural aIntermural;
16	private System.Windows.Forms.GroupBox groupbox1;
17	private System.Windows.Forms.Label label1;
18	//// and other Windows.Forms object oriented buttons and so-forth
20	public PresentationGUI ()
21	{
22	Initialize Component ();
23	}
24	/// #Windows Designer Code to add controls
25	static void Main()
26	{
27	Application.Run(new PresentationGUI());
28	}
29	private void Presentation_Load(object sender, System.EventArgs e)
30	{
31	aClub = new Club ("ACM", "Jones", "Davis 203", "Tuesday");
32	aIntermural = new Intermural ("Winners", "Joe Smith", "Gym 3", "VolleyBall")
33	}

My instructor said that by creating the PresentationGUI class and setting it as startup, before adding controls to the form will create the private Systems.Windows.Forms.Label label1; to the class itself, but that doesn't happen when I create my class. I have even added my subclasses as references to the PresentationGUI class after I made it a startup project, even the interface, I omitted it in my code above (I used my exact code from the book which is not using a interface). Does this have to do with adding the using System part at the top, or do I have to add the private Windows.Forms part myself to reference the controls? Or is there a different way that I need to create the PresentationGUI class library? How can I make a class with a Initialize Component() and Main() method? Do I somehow need to reference this with the Form Design, or is it part of the Form Design, if it is how can I make it part of the Form design? Sorry for all the questions and I know the answer is probably simple, but there is extremely little about this in my book and online, and I can't figure out what I need to do to implement this. Thank you for all your help!
Clifford Nelson 10-May-12 22:34pm
Are you stuck with WinForms, or can you use WPF?
Shahin Khorshidnia 14-May-12 13:36pm
I think its winform. (public class PresentationGUI : System.Windows.Forms.Form

1 solution


Firstly, Initialize Component (); is wrong. it's really InitializeComponent();

You can't run ClassLibrary. You can use it from another projects.
Open a new WinForm project and Add Refrence to DLL file of classLibrary.
Then you can use PresentationGUI

PresentationGUI presentationGUI = new PresentationGUI();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900