Many times in the past I've been asked to help and elaborate on one SharePoint topic and that is building Web Parts for SharePoint. I've talked about this in my community events as well as conferences where I presented. I've also blogged about some more advanced development of Web Parts but I've never done a more basic explanation of how to develop simple Web Parts. After this last request I finally gave in, so here it is.
Coolest thing about web parts in SharePoint is its complete utilisation of ASP.NET 2.0 platform and what it has to offer. SharePoint web pages are basically a combination of the precompiled DLL and a ASPX page. If you change and/or customize a page in SharePoint the changes are stored in the database, so the final ASPX page that you see is a combination of the original ASPX page and changes stored in a database.
Getting to the point of WebParts, webparts can be insanely easy to be make or they can drive you crazy if they're way too complex.
Very easy way to create (with AJAX) is actually described in my post which is actually done in VS2005 ( http://dotnet.org.za/zlatan/archive/2007/10/12/developing-ajax-web-parts-in-sharepoint-2007.aspx). Example also contains source code of the webpart I designed to show new tasks from the SharePoint task list as they arrive (without the need to refresh), this code can also be used to rotate news or other list items dynamically and many other things.
If you're not interested in using AJAX in your webparts then just ignore the instructions 1-3 and go to 4 (which is the very beginning of the code):
First, make sure you're using:
Visual Studio 2005 with Office SharePoint Server 2007 SDK 1.3 (or Windows SharePoint Services SDK 1.3) and Visual Studio 2005 extensions for Windows SharePoint Services 1.1.
http://dotnet.org.za/zlatan/archive/2008/03/09/sharepoint-server-2007-version-1-3-and-wss-3-0-version-1-3-available.aspx
http://dotnet.org.za/zlatan/archive/2008/02/13/final-release-of-vsewss-1-1-visual-studio-extensions-for-windows-sharepoint-services.aspx
You can also develop Web Parts with Visual Studio 2008, but without the templates (for the time being) that do help a lot, especially if you're a beginner.
1. Start the VS choose Web Part (template) under SharePoint section.
2. SharePoint WebPart inherits from an abstract base class called Microsoft.SharePoint.WebPartPages.WebPart, which inherits from System.Web.UI.WebParts.WebPart, so since you got two classes to choose from, which one do you choose?
Safe bet is the ASP.NET 2.0 abstract class, ie. System.Web.UI.WebControls.WebParts.WebPart. Anyway, that's the one that you'll see when your template loads.
3. You would be presented with the code below:
Next you override CreateChildControls to create the control tree, later override any other method from the System.Web.UI control class.
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace WebPart1
{
[Guid("720e3e34-4127-438b-a4fb-d159d5a082e7")]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{
public WebPart1()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
// TODO: add custom rendering code here.
// Label label = new Label();
// label.Text = "Hello World";
// this.Controls.Add(label);
}
}
}
4. Press F5 and when the Web Part is deployed add it on the SharePoint 2007 page from the library (if you don't specify otherwise then you'll find it under "Miscellaneous")

If you're using any earlier SDK or extensions, once you compile your WebPart Project follow these steps to deploy the solution:
1. First drag and drop the compiled assembly into the GAC (by default c:\windows\assembly).
2. Open the properties of the dll to get the public key token.
3. Now register the safe control in the web.config. (i.e. '<SafeControl Assembly="WebPartForYou, Version=1.0.0.0, Culture=neutral, PublicKeyToken=74e5f216d6256126" Namespace="WebPartForYou" TypeName="*" Safe="True" /> )
4. In SharePoint, click 'Site Actions', 'Site Settings' and then under 'Site Collection Administration' click 'Go to top level site settings'.
5. Under 'Galleries', click 'Web Parts'. Then click 'New'.
6. Now, the new webpart(s) will appear in the list. If not, try an IISRESET and refresh the page.
Select the webpart we've just created and click 'Populate Gallery'.
Now when you edit your SharePoint page you'll find your WebPart listed, most likely in Miscellaneous section, click to Add it and Voila.
(note that if you're using the above SDKs and extensions, all of these steps above are done automatically for you).
Hope that this helps, it should get you started