FormatCode Code Formatter is based on serveral powerful syntax parser engines
so you can exactly control the appearance of your source code. Here is the code formatting demo of
FormatCode C# Code Formatter to prove the ability of code formatting
functions of FormatCode:
namespace DataSetExample{using System;using System.Drawing;using
System.Collections;using System.ComponentModel;using System.WinForms;using
System.Data;using System.Data.SQL;/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1:System.WinForms.Form{/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components;private
System.WinForms.MenuItem ExitTest;private System.WinForms.MenuItem RunTest;
private System.WinForms.MenuItem menuItem1;private System.WinForms.MainMenu
mainMenu1;private System.WinForms.DataGrid grid;public Form1(){InitializeComponent();}/// <summary>
/// Clean up any resources being used.
/// </summary>
public override void Dispose(){base.Dispose();components.Dispose();}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent(){this.components=new
System.ComponentModel.Container();this.mainMenu1=new System.WinForms.MainMenu()
;this.RunTest=new System.WinForms.MenuItem();this.grid=new
System.WinForms.DataGrid();this.menuItem1=new System.WinForms.MenuItem();
this.ExitTest=new System.WinForms.MenuItem();grid.BeginInit();
mainMenu1.MenuItems.All=new System.WinForms.MenuItem[1]{this.menuItem1};
RunTest.Text="&Run Test";RunTest.Index=0;RunTest.Click+=new System.EventHandler
(this.RunTest_Click);grid.Location=new System.Drawing.Point(8,8);grid.Size=new
System.Drawing.Size(488,456);grid.DataMember="";grid.TabIndex=0;grid.Anchor=
System.WinForms.AnchorStyles.All;menuItem1.Text="&File";menuItem1.Index=0;
menuItem1.MenuItems.All=new System.WinForms.MenuItem[2]{this.RunTest,
this.ExitTest};ExitTest.Text="&Exit";ExitTest.Index=1;ExitTest.Click+=new
System.EventHandler(this.ExitItem_Click);this.Text="DataSet Example Project";
this.StartPosition=System.WinForms.FormStartPosition.CenterScreen;
this.AutoScaleBaseSize=new System.Drawing.Size(5,13);this.Menu=this.mainMenu1;
this.ClientSize=new System.Drawing.Size(504,469);this.Controls.Add(this.grid);
grid.EndInit();}protected void RunTest_Click(object sender,System.EventArgs e){
SQLConnection conn=new SQLConnection("www.adoguy.com","adonet","adonet",
"ADONET");try{conn.Open();}catch(Exception ex){DumpError(
"Failed to Open Connection.",ex);return;}DataSet ds=new DataSet();SQLDataSetCommand dscPatients=new SQLDataSetCommand(
"SELECT * FROM Patients",conn);SQLDataSetCommand dscVisits=new
SQLDataSetCommand("SELECT * FROM Visits",conn);try{
dscPatients.TableMappings.Add("Table","Patients");dscPatients.FillDataSet(ds,
"Patients");
dscVisits.TableMappings.Add("Table","Visits");dscVisits.FillDataSet(ds,"Visits"
);ds.Relations.Add(ds.Tables["Patients"].Columns["PID"],ds.Tables["Visits"]
.Columns["PID"]);}catch(Exception ex){DumpError("Failed to Fill Dataset.",ex);
return;}try{DataSetView dsv=new DataSetView(ds);grid.DataSource=dsv;grid.DataMember=
"Patients";}catch(Exception ex){DumpError("Failed to Bind. ",ex);return;}
conn.Close();return;}public void DumpError(string sProblem,Exception ex){
String sMsg=sProblem+" Reason: "+ex.Message;Exception innerEx=ex.InnerException
;while(innerEx!=null){sMsg+="\r\nInner->"+innerEx.Message;innerEx=
innerEx.InnerException;}MessageBox.Show(sMsg);}protected void ExitItem_Click(
object sender,System.EventArgs e){Application.Exit();}/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[]args){Application.Run(new Form1());}}}
namespace DataSetExample
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.WinForms;
using System.Data;
using System.Data.SQL;
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1: System.WinForms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components;
private System.WinForms.MenuItem ExitTest;
private System.WinForms.MenuItem RunTest;
private System.WinForms.MenuItem menuItem1;
private System.WinForms.MainMenu mainMenu1;
private System.WinForms.DataGrid grid;
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.mainMenu1 = new System.WinForms.MainMenu();
this.RunTest = new System.WinForms.MenuItem();
this.grid = new System.WinForms.DataGrid();
this.menuItem1 = new System.WinForms.MenuItem();
this.ExitTest = new System.WinForms.MenuItem();
grid.BeginInit();
mainMenu1.MenuItems.All = new System.WinForms.MenuItem[1]
{
this.menuItem1
};
RunTest.Text = "&Run Test";
RunTest.Index = 0;
RunTest.Click += new System.EventHandler(this.RunTest_Click);
grid.Location = new System.Drawing.Point(8, 8);
grid.Size = new System.Drawing.Size(488, 456);
grid.DataMember = "";
grid.TabIndex = 0;
grid.Anchor = System.WinForms.AnchorStyles.All;
menuItem1.Text = "&File";
menuItem1.Index = 0;
menuItem1.MenuItems.All = new System.WinForms.MenuItem[2]
{
this.RunTest, this.ExitTest
};
ExitTest.Text = "&Exit";
ExitTest.Index = 1;
ExitTest.Click += new System.EventHandler(this.ExitItem_Click);
this.Text = "DataSet Example Project";
this.StartPosition = System.WinForms.FormStartPosition.CenterScreen;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.Menu = this.mainMenu1;
this.ClientSize = new System.Drawing.Size(504, 469);
this.Controls.Add(this.grid);
grid.EndInit();
}
protected void RunTest_Click(object sender, System.EventArgs e)
{
SQLConnection conn = new SQLConnection("www.adoguy.com", "adonet",
"adonet", "ADONET");
try
{
conn.Open();
}
catch (Exception ex)
{
DumpError("Failed to Open Connection.", ex);
return ;
}
DataSet ds = new DataSet();
SQLDataSetCommand dscPatients = new SQLDataSetCommand(
"SELECT * FROM Patients", conn);
SQLDataSetCommand dscVisits = new SQLDataSetCommand(
"SELECT * FROM Visits", conn);
try
{
dscPatients.TableMappings.Add("Table", "Patients");
dscPatients.FillDataSet(ds, "Patients");
dscVisits.TableMappings.Add("Table", "Visits");
dscVisits.FillDataSet(ds, "Visits");
ds.Relations.Add(ds.Tables["Patients"].Columns["PID"], ds.Tables[
"Visits"].Columns["PID"]);
}
catch (Exception ex)
{
DumpError("Failed to Fill Dataset.", ex);
return ;
}
try
{
DataSetView dsv = new DataSetView(ds);
grid.DataSource = dsv;
grid.DataMember = "Patients";
}
catch (Exception ex)
{
DumpError("Failed to Bind. ", ex);
return ;
}
conn.Close();
return ;
}
public void DumpError(string sProblem, Exception ex)
{
String sMsg = sProblem + " Reason: " + ex.Message;
Exception innerEx = ex.InnerException;
while (innerEx != null)
{
sMsg += "\r\nInner->" + innerEx.Message;
innerEx = innerEx.InnerException;
}
MessageBox.Show(sMsg);
}
protected void ExitItem_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
Application.Run(new Form1());
}
}
}
Click here to preview the C# Code Formatting Demo 2.
With FormatCode C# Code Formatters, you can format and transform any foreign C# source code to meet your preferred coding style or any common code convention in several seconds!
|