468,161 Members | 2,019 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,161 developers. It's quick & easy.

Breaking up Big FormX.CS files

A simple way to split your file:
- create a class BasicClient.cs:
using System;
namespace Test
{
public abstract class BasicClass{
public BasicClass(){}
public abstract string DoClient();
//add here other abstract methods
}
}
- create a class Client1.cs:
using System;
namespace Test
{
public class Client1:BasicClient{
public Client1(){}
public override string DoClient()
{return "DoJob Client 1"; //your code}
}
}
- create a class Client2.cs:
using System;
namespace Test
{
public class Client2:BasicClient{
public Client2(){}
public override string DoClient()
{return "DoJob Client 2"; //your code}
}
}
- in Form1.cs do something like this:
BasicClient objBC = null;
if (bIsClient1)
objBC = new Client1(); string strJB=objBC.DoClient();
else
if (bIsClient2)
objBC = new Client2(); string strJB=objBC.DoClient();
objBC = null;
-----Original Message-----
I have a WIN32 C# application which is basically a single main form and apreference dialog. I customize the behavior of this application for variousclient configurations, and my Form1.cs file is getting unwieldy. I'd liketo break the code up into distinct files (broken up by client), but I'm nothaving success doing that.

My application has a namespace

namespace WonderBoy

In the Form1.cs file, the following class is defined:

public class Form1 : System.Windows.Forms.Form

within that class I have various client-specific sections like:
private bool DoClient1()

private bool DoClient2()
I'd like to move DoClient1() to a new file (client1.cs) and DoClient2() toclient2.cs. When doing so, I can move the DoClient1() code to client1.cs,but then Form1 barks during compile link with an unresolved reference forDoClient1().

In C++, I could spread a large class over multiple files without problemsusing a common header file showing all of the class members. But I'mscratching my head as to how to do this in C#. Can anyone point me in theright direction?

TIA

Harry




.

Nov 15 '05 #1
2 1327
Or wait for Whidbey:
http://msdn.microsoft.com/vstudio/pr...p.aspx#whidbey
-mike
"Sacalul" <ka******@asconsulting.ro> wrote in message
news:04****************************@phx.gbl...
A simple way to split your file:

-----Original Message-----
I'd like
to break the code up into distinct files (broken up by

client), but I'm not
having success doing that.

Nov 15 '05 #2
That'll do it!! Thanks so much!

Harry
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

30 posts views Thread by Jive | last post: by
2 posts views Thread by Jacob | last post: by
22 posts views Thread by stevenkobes | last post: by
6 posts views Thread by Ritesh Raj Sarraf | last post: by
4 posts views Thread by Bit Byte | last post: by
13 posts views Thread by Andrew | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.