Working with SharpDevelop
You may be asking yourself what is SharpDevelop, will SharpDevelop is a
free open source IDE for the .Net Framework. It will allow you to develop C#
and VB.Net and C++.Net applications. So for those of you who don't have the bucks
to purchase VB.Net or .Net Studio and want to lean .Net this is the perfect
solution.
At first glance it looks a lot like Microsoft's Visual Studio.Net: it
has a Start Page, Solution Explorer, Toolbox, Clipboard Ring, Class Viewer and Task
List.
The editor in SharpDevelop supports syntax highlighting for C#, HTML,
ASP, ASP.NET, VBScript, VB.NET, XML and code completion for C# and VB.Net. The editor
also supports collapsible code regions like VS.Net and SharpDevelop provides
a WinForms designer.
Other Features
* A Windows Forms designer for C# and
VB.NET
* Code completion for C# and VB.NET
(including Ctrl+Space support)
* Function folding
* Code AutoInsert
* A C#?VB.NET converter
* Completely written in C#
* Compile C#, VB.NET in the IDE
out-of-the-box
* ILAsm and C++ backends
* Integrated NUnit support
* Assembly Analyzer ("FxCop on steroids")
* XML documentation preview
* Everything templated: add new project
or file types, or even compilers to SharpDevelop
* Write C#, ASP.NET, ADO.NET, XML, HTML
code
* Rich project options
* Syntax highlighting for C#, HTML, ASP,
ASP.NET, VBScript, VB.NET, XML
* Intelligent braces
* Bookmarking
* Code template support
* Easily extensible with external tools
* Easily extensible with addins
As with all my Hands On project I will provide links to download the
software and links to any other resources.
So lets get started!
I will go through the menu items and discuss relevant items.
File Menu
There are two thing to be pointed out there, the import and export
features. import will allow you to import a C# or A VB.Net project form
Visual Studio in
to an SharpDevelop file. The export will export the SharpDevelop
project to a Visual Studio file.
You can also translate whole projects from VB.NET to C# and vice-versa.
View Menu
This will allow you to view the different windows, i.e. properties, project, task
list etc.
Project
Run Test - will run the application in test mode
Run VB.Doc - VB.DOC extracts the xml comments in your source code to a
single xml file. It can be configured under the Project Options under
Configuration tab.
Deploy - This will allow you to deploy your project to the directory
you specified in the Deployment options. To set the deployment options
click on Projects,
Project Options, General, Deploy. There you can specify where you want
your project
deployed what files to include and how you want it deployed.
Deploy
Generate Documentation - generates class library documentation from
.NET assemblies and the XML documentation files generated by the C#
compiler (or with an add-on tool for VB.NET).
HTML Export - This will export your project AssemblyInfo and MainForm to html. MainForm
AssemblyInfo
Project Options - This will allow you to configure SharpDevelop's project, compile and
deploy options. You can also setup the configuration options.
http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.ProjectOptions
Ok the first thing we need to do is download SharpDevelop and if you don't have the .Net
Framework SDK you will need to download that as well. Just remember that the .Net Framework
is a very large file, 108MB I believe. You should also know that SharpDevelop will only
work on .Net SDK 1.1, they are in the process of testing it with the new .Net SDK but
that's still in the works. You can download both the SharpDevelop and the SDK 1.1 at
the link below
http://www.icsharpcode.net/OpenSource/SD/Download/
Instilling is pretty straight forward, during installation make sure that you say yes
to generating the code completion database. That database is necessary for the forms editor as well as for code completion.
Once you have installed SharpDevelop its now time to run it. You will be presented
with the following screen. Since you have not created any projects your start page will look different.
While that is the default view you can customize the IDE to fit your needs.
The Tools
We are going to take a quick look at SharpDevelop's IDE, first up the
"Tools" tab.
The tools scouts allows you to insert blocks of text from predefined
lists directly into your code. As well as drag and drop controls on to
your forms. When SD
first starts up you have the following tools available to you. ASCII
Table, C#
Documentation Tags, Licenses, #develop, XSL-T, General and Clipboard
Ring.
You may be asking where are the Windows Forms and Components? Well
don't worry
all you have to do is start a new project and click on the "Design" tab
then
the "Windows Forms" which holds all the controls like TextBox, Labels,
Check Box etc, "Data" which allows you to connect to a Database and the
"Components" which has the FileSystemWatcher, Event Log, and Timer etc.
will be accessible.
New Project
Ok, so its not original, but I cant break with tradition so we have to do the
hello world project.
So start up SharpDevelop, Then click on File, New, Combine then click on the
VB.Net folder. Select the Window Application icon then type MyTest in the
Name text box. You can then set the location where you want the file to be or
you can accept the default click on create. Your screen should look like this.
Startup Screen
Now click on the design tab at the bottom left hand portion of the window
an lets put some controls on the form. When you click on the Design tab you
will notice you have more control tabs on the Tool bar. First we are going to
put a command button on the form, so double click on the button control
and then click the place on the form you want the button. Or you can click the
button control and draw the button on the form.
Next we are going to add a text box so double click the text box and click
the place on the form you wish the text box to be. The screen should now look
like this.
Main Form
Now comes the coding which of course is very simple, just double click
on the button and the code window will appear now all you have to do is
type the following
code under the ButtonClick event.
Textbox1.Text = "Hello World!"
You will notice that when you type Textbox1. the code completion screen will popup.
Now we are going to build the project, and you have two options to do that. The first
is to select the "Build" menu item and select Build Combine or you can click the
second blue icon at the top right hand portion of the screen next to the green arrow.
If all went well you should get Build complete 0 errors, 0 warnings in
the output window. Now click the green arrow to run the program. You
will also notice that you can click the green arrow and it will
atomically build and run the program.
That's it our first application built using SharpDevelop!
Build
Build Combines - #develop uses the terms "Combine" and "Project".
Briefly, a Project is a collection or source files (i.e. code) and
other resources (such as images, icons, etc.) that can be compiled into
a .NET Assembly. A "Combine" is a collection (a 'combination') of one
or more Projects.
To set your combines options click on Combine AppName and right click and select
Combine options.
Rebuild - No need for an explanation there.
Build - Just builds the project.
Rebuild - No need for an explanation there.
Debug - This will debug your project, the debug options can be found by selecting
Project Options and Configurations.
Tools
Regular expression tool kit - are used by many text editors and
utilities to search and manipulate bodies of text based on certain
patterns
Addin Scout - Will allow you to add custom controls to the tools bar.
Notepad - Will launch notepad and copy the source code of the form you are on.
NProf - Is designed to be not
only a fully-fledged profiler for .NET applications, but also a
complete API that can be used to build other profiler front-ends, as
well as extend the default GUI with new visualization tools.
You can see some screen shots here: http://nprof.sourceforge.net/Site/Screenshots.html
IL dasm - intermediate language disassembler, will convert binary format to high-level source codes.
Insert PInvoke signatures - Lets you call one of the many Win32 API
functions that are not available directly from the .NET framework. You
can find more information regarding PInvoke
at the links below.
http://www.pinvoke.net/
http://www.geocities.com/Jeff_Louie/COM_Interop/pinvoke.htm
SharpReport - This will allow you to create repots with in SharpDevelop. It's
equivalent to VB's Data Report.
Message Box wizard - Does as it's name applies, it will create a message box for you
and add the code to your project.
Quick XML Doc - Turns your source code in to a XML document.
Options - Will allow you to configure SharpDevelop to your liking as well as to your
language since it comes with 22 different
languages.
Now that we've gone over the some of the features let start using them.
This tutorial is by no means a tutorial on using VB.Net but rather SharpDevelop
features and what it can do. So over the next couple of days we will be creating
small project with SharpDevelop showing off its built in features that will make
developing with SharpDevelop quick and easy.
Since Database programming with VB is important I thought I would provide a simple
program that will access a Database and display its contents. You will notice that
in ADO.Net the recordset is gone and has been replaced by the Dataset.
So lets startup a new project and name it DBConnect, now add a DataGrid and a
button to your project. Now we need to add the dataset to our project, so click
the "Data" tab on the tools bar, then double click the "DataSet" icon and click
on the main form and the DataSet control will be place in the project. Your
program should look like this.
Now the coding behind the button.
Since we are going to be working with databases we will need to import some
libraries to our program.
Imports System
Imports System.Drawing
Imports System.Windows.Forms
-------------------------------
Imports System.Data
Imports System.Data.OleDb
We need to add the Data and OleDb the other libraries above the dotted line were
automatically added when you put controls on the form.
Now the code that will connect to the database and display the records. Like I
said this is not a tutorial on using VB.Net so I have removed all the code excapt
the code that is behind the button.click here
When all is said and done when you run the program it will connect to the database
and desplay all the employess names.
click here
That's it the hardest thing to do was write the code, adding the controls was a
snap.
While my example shows you how to connect to an Access database the
examples below show you how to connect to a MySQL and SQL server
database.
Connecting to MySQL
http://www.lecenio.outsys.net/sharpdev/mysql/mysqlsample.html
Connecting to SQL Server
http://www.lecenio.outsys.net/sharpdev/sqlserver/sqlserver.html
It's really easy to convert a C# project to VB.Net and visa versa. All you do is open the
C# project then under "Tools" select the "Convert C# Buffer to VB.Net that's it. If
you were converting a VB.Net to C# you would select "Convert Buffer VB.Net to C#.
The code will be converted and place in a new window named, "Generated.VB or CS if
it was a VB project that you were converting. The example below converted our,
"Hello World" VB.Net to C#.
VB - Hello World
This is what your project will look like when the code is converted.
Source code added
This is what the code will look like once its converted form VB to C#.
Converted to C#
Last time we discussed converting your code form VB to C# and visa
versa. Today
will well discuss importing a Visual Studio project to SharpDevelop
project and Exporting a SharpDevelop project to VS. You can find the
file that we will be
converting here.
Once again this is very easy, to import a VS VB project in to SharpDevelop click on
File then, "Import Project". The Import Project dialog box will tell you what type of supported formats it will convert. Now click the box next to the Project to import
text box. Find the project you want to convert and click open then click start. Once it's
done you will get a message box telling you this. Once you click OK the project will loaded.
At first glance you may think that the project did not load, but all you have to do is
click on the "Projects" tab on the lower left hand corner of the window. Then double click
on the Form1.vb and the source and design windows will appear.
That's it, simple wasn't it? You would do the same thing if it was a C# project you were importing.
By the way that code will limit the number of characters in a multi line textbox, so you
if you do program in VB.Net you might want to keep that code for later on.
Exporting is just as easy, you load the project you wish to export, under File select
Export Project you will get the following dialog box. Set the location you want the exported files to be and click
start.
That's it importing and exporting project is a snap with SharpDevelop.
Over the next few days I will be providing links to videos on some of the
features I have discussed in my earlier posts. You will need Microsoft Media Player in order to view these videos.
Here's a little back ground on NAnt: http://nant.sourceforge.net/
NAnt the video 5.52 mins: http://laputa.sharpdevelop.net/content/binary/NAntAddin.wmv
This video shows you how to use the PInvoke feature. If you haven't a chance to take
a look do so, it will help in understanding how powerful this feature is.
http://www.pinvoke.net/
PInvoke 1:30 mins
http://laputa.sharpdevelop.net/content/binary/PInvokeAddin.wmv
This video demonstrates how to add web servers to your SharpDevelop projects
This video is 3.44 mins long
http://laputa.sharpdevelop.net/content/binary/WebReferences.wmv
Today we will take a look at the video on XML editing, intellisense,
folding and validation that is integrated in to SharpDevelop.
This video is 6:10 mins long.
http://laputa.sharpdevelop.net/content/binary/XmlEditing.wmv
The link below shows you how to use SharpDevelop to develop C++ applicaions.
http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.CppDevelopment
The link below shows you how to debug in SharpDevelop
http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.DebuggingInSharpDevelop
The link below shows you how to embed a file as a resource.
http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.UsingResources
The link below shows you how to develop PocketPC application using SharpDevelop.
http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.CompactFrameworkDevelopment
The links below are SharpDevelop resources links, forums and more tips and tricks.
Resource page - http://wiki.sharpdevelop.net/default.aspx/
SharpDevelop Forums - http://community.sharpdevelop.net/forums/
Keyboard Shortcuts - http://wiki.sharpdevelop.net/default.aspx/SharpDevelop.KeyboardShortcuts1x
Copyright© 2006 Marietta Crockett
Disclaimer