Q:

How to split one class' code into a few files?

I'm working with visual studio 2010.
I'd like to split one class into a few .cs files. Is it possible?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
             InitializeComponent();
        }

        int i = 5;
        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

I'd like to add method public void laugh() into public partial class Form1, but in a different file. How to do that? I don't want that method in a Form1.cs

A:

Add a new class to your project with an appropriate name (you cannot use Form1.cs because it already exists), for example Form1.Code.cs. Then this works:
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public void laugh()
        {
            MessageBox.Show("Haha");
        }
    }
}

