SharpDevelop安装与配置

SharpDevelop是一个用于C#开发的IDE,相比于VisualStudio的臃肿,SharpDevelop的小巧能让人专注于C#开发。
SharpDevelop官方下载地址: http://www.icsharpcode.net/OpenSource/SD/Download/
官方github: https://github.com/icsharpcode/SharpDevelop

注意:最新的5.1不支持XP,如果想在XP上使用,建议下载4.4版

安装SharpDevelop之前必须安装.NetFramework,VC++2008运行库

.NET Framework4.5.1下载地址:http://www.microsoft.com/zh-CN/download/details.aspx?id=40772

IIS Express 8.0下载地址:http://www.microsoft.com/zh-cn/download/details.aspx?id=34679

更多的下载地址,SharpDevelop下载页面有链接

一、安装篇

1.安装.NET Framework4.5.1

双击之后需要一段时间解压,之后弹出安装界面

点击我已阅读并接受许可条款前的复选框,点击安装

接下来就是等待安装

这段安装时间比较长,本人8G内存真机安装了半个小时,虚拟机安了1个小时,再看最后两张图

2.安装SharpDevelop

双击SharpDevelop

下面这个页面可以改安装路径

点击Install等进度条走完基本就安装完了

3.安装IIS Express

双击iisexpress

后面基本傻瓜式了



二、配置篇

1.语言设置

初始界面

Tool-->Option


在Option窗口中,选择General-->UI Language,然后选择右侧的Chinese

之后就变成中文界面了

SharpDevelop安装完成之后的图标

启动画面

初始画面

三、测试功能用的例子

1.C#控制台程序

文件-->新建--解决方案

在弹出的窗口中,类别一栏选择C#-->Windows应用程序,模板版本选择:.NET Framework 4.0,然后点击控制台应用程序,在名称中填写HelloWorld,位置自己改,点击建立

SharpDevelop会自动生成一个HelloWorld项目

自动生成的Program.cs代码如下:

[csharp]  view plain  copy
  1. /* 
  2.  * 由SharpDevelop创建。 
  3.  * 用户: LENOVO 
  4.  * 日期: 2015/9/19 
  5.  * 时间: 20:09 
  6.  *  
  7.  * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 
  8.  */  
  9. using System;  
  10.   
  11. namespace HelloWorld  
  12. {  
  13.     class Program  
  14.     {  
  15.         public static void Main(string[] args)  
  16.         {  
  17.             Console.WriteLine("Hello World!");  
  18.               
  19.             // TODO: Implement Functionality Here  
  20.               
  21.             Console.Write("Press any key to continue . . . ");  
  22.             Console.ReadKey(true);  
  23.         }  
  24.     }  
  25. }  
点击工具栏中的绿色小箭头运行

运行结果:


再来个例子

[csharp]  view plain  copy
  1. /* 
  2.  * 由SharpDevelop创建。 
  3.  * 用户: LENOVO 
  4.  * 日期: 2015/9/13 
  5.  * 时间: 20:04 
  6.  *  
  7.  * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 
  8.  */  
  9. using System;  
  10.   
  11. namespace HelloWorld  
  12. {  
  13.     class Program  
  14.     {  
  15.         public static void Main(string[] args)  
  16.         {  
  17.             Console.WriteLine("Hello World!");  
  18.             int a = 2;  
  19.             int b = 3;  
  20.             Console.WriteLine("{0}+{1}={2}",a,b,a+b);  
  21.               
  22.               
  23.             // TODO: Implement Functionality Here  
  24.               
  25.             Console.Write("Press any key to continue . . . ");  
  26.             Console.ReadKey(true);  
  27.         }  
  28.     }  
  29. }  

2.C#控制台+网络下载的例子

新建解决方案名称为WebRequestApp

更改Program.cs如下:

[csharp]  view plain  copy
  1. /* 
  2.  * 由SharpDevelop创建。 
  3.  * 用户: LENOVO 
  4.  * 日期: 2015/9/14 
  5.  * 时间: 17:07 
  6.  *  
  7.  * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 
  8.  */  
  9. using System;  
  10. using System.Net;  
  11. using System.IO;  
  12. using System.Text;  
  13.   
  14. namespace WebRequesterApp  
  15. {  
  16.     class Program  
  17.     {  
  18.         public static void Main(string[] args)  
  19.         {  
  20.             WebRequest req = WebRequest.Create("http://www.baidu.com");  
  21.             WebResponse resp = req.GetResponse();  
  22.             StreamReader reader = new StreamReader(resp.GetResponseStream(),Encoding.UTF8);  
  23.             Console.WriteLine(reader.ReadToEnd());  
  24.             Console.Write("Press any key to continue . . . ");  
  25.             Console.ReadKey(true);  
  26.         }  
  27.     }  
  28. }  

运行结果:



如果出现如下System.Net.WebException异常,请首先检查IE代理设置,因为WebRequest会自动使用IE设置的代理,建议首先把你要访问的网址放到IE浏览器里访问:


[plain]  view plain  copy
  1. System.Net.WebException: 无法连接到远程服务器 ---> System.Net.Sockets.SocketException: 由于目标计算机积极拒绝,无法连接。  
  2.   
  3.    在 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)  
  4.    在 System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)  
  5.    在 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)  
  6.    --- 内部异常堆栈跟踪的结尾 ---  
  7.    在 System.Net.HttpWebRequest.GetResponse()  
  8.    在 WebRequesterApp.Program.Main(String[] args) 位置 d:\SharpDevelop Projects\WebRequesterApp\WebRequesterApp\Program.cs:行号 21  

为了防止上述异常,建议在调用GetResponse()之前加一句req.Proxy=null;

修改后的代码如下:

[csharp]  view plain  copy
  1. /* 
  2.  * 由SharpDevelop创建。 
  3.  * 用户: LENOVO 
  4.  * 日期: 2015/9/14 
  5.  * 时间: 17:07 
  6.  *  
  7.  * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 
  8.  */  
  9. using System;  
  10. using System.Net;  
  11. using System.IO;  
  12. using System.Text;  
  13.   
  14. namespace WebRequesterApp  
  15. {  
  16.     class Program  
  17.     {  
  18.         public static void Main(string[] args)  
  19.         {  
  20.   
  21.             WebRequest req = WebRequest.Create("http://www.baidu.com");  
  22.             req.Proxy=null;  
  23.             WebResponse resp = req.GetResponse();  
  24.             StreamReader reader = new StreamReader(resp.GetResponseStream(),Encoding.UTF8);  
  25.             Console.WriteLine(reader.ReadToEnd());  
  26.             Console.Write("Press any key to continue . . . ");  
  27.             Console.ReadKey(true);  
  28.         }  
  29.     }  
  30. }  

这样就不会自动设置为IE的代理了。

3.C#窗口程序

依然是新建解决方案,名称这里填HelloWorldForm,只不过我们这次选择模板类型Windows 应用程序


软件会自动生成一部分代码,我们在这里加一句

[csharp]  view plain  copy
  1. MessageBox.Show("HelloWorld","Messsage from C#");  

运行结果:

点击确定,回到这个窗口

4.ASP.NET程序GET提交

新建解决方案,类型选C#中的ASP.NET,模板选ASP.Net 网页项目,名称任意

程序会自动生成Default.aspx,这里不管它


在解决方案名称上,右键-->添加-->新建项

类别选择Web,模板选择空HTML页,名称填index,html

在index.html写如下代码:

[html]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <title>ASP.NET简单登录</title>  
  5.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />  
  6.     <style type="text/css">  
  7.         body{font:100 15px/20px "宋体";}  
  8.         #maxdiv{width:300px;height:140px;border:1px solid red;margin-top:20%;margin-left:40%}  
  9.         .divcenter{text-align:center;margin-top:10px}  
  10.         .text{border:1px solid #b4b4b4;width:180px;height:20px}  
  11.         .btnsubmit{width:80px;height:25px;color:blue}  
  12.     </style>  
  13. </head>  
  14. <body>  
  15.     <div id="maxdiv">  
  16.         <div class="divcenter">  
  17.             <form method="get" action="tijiao.aspx">  
  18.             <span>用户名:</span>  
  19.             <input type="text" name="name" value="aaaa" class="text" />  
  20.             <br /><br />  
  21.             <span>密  码:</span>  
  22.             <input type="password" name="password" value="bbbb" class="text" />  
  23.             <br /><br />  
  24.             <input type="submit" value="提  交" class="btnsubmit" />  
  25.             </form>   
  26.         </div>  
  27.     </div>  
  28. </body>  
  29. </html>  
然后新建一个aspx页。

在解决方案名称上,右键-->添加-->新建项,然后类别选择C#中的ASP.NET,模板选择ASP.NET Web窗体,名称填tijiao.aspx

在tijiao.aspx写如下代码:

[html]  view plain  copy
  1. <%@Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <html xmlns="http://www.w3.org/1999/xhtml">  
  5. <head>  
  6.     <title>ASP.NET登录结果</title>  
  7.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />  
  8. </head>  
  9. <body>  
  10.     <%  
  11.     string n1=Request.QueryString["name"];  
  12.     string n2=Request.QueryString["password"];  
  13.     Response.Write("你的用户名:");  
  14.     %></br>  
  15.     <%Response.Write(n1);  
  16.     %></br>  
  17.     <%Response.Write("你的密码:");  
  18.     %></br>  
  19.     <%Response.Write(n2);  
  20.     %></br>      
  21.     </body>  
  22. </html>  

点击保存。

解决方案名称-->右键-->属性

生成选项卡的目标CPU选择32为Intel处理器

在网络选项卡中配置IIS服务器,选择Use IIS Express Web Server,最后点击创建应用程序或虚拟目录

在调试选项卡中,选中在URL中启动浏览器,并填上初始访问地址:http://localhost:8080/index.html

保存,最后点击绿色三角形运行

运行结果如图:


5.ASP.NET程序POST提交

在ASP.NET中的html页面通过form表单POST提交时,不能提交到其他页,但是aspx页面的form表单可以。

将4中的index.html直接改名为index.aspx,代码如下:

[html]  view plain  copy
  1. <%@Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <html xmlns="http://www.w3.org/1999/xhtml">  
  5. <head>  
  6.     <title>ASP.NET简单登录</title>  
  7.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />  
  8.     <style type="text/css">  
  9.         body{font:100 15px/20px "宋体";}  
  10.         #maxdiv{width:300px;height:140px;border:1px solid red;margin-top:20%;margin-left:40%}  
  11.         .divcenter{text-align:center;margin-top:10px}  
  12.         .text{border:1px solid #b4b4b4;width:180px;height:20px}  
  13.         .btnsubmit{width:80px;height:25px;color:blue}  
  14.     </style>  
  15. </head>  
  16. <body>  
  17.     <div id="maxdiv">  
  18.         <div class="divcenter">  
  19.             <form method="post" action="tijiao.aspx">  
  20.             <span>用户名:</span>  
  21.             <input type="text" name="name" value="aaaa" class="text" />  
  22.             <br /><br />  
  23.             <span>密  码:</span>  
  24.             <input type="password" name="password" value="bbbb" class="text" />  
  25.             <br /><br />  
  26.             <input type="submit" value="提  交" class="btnsubmit" />  
  27.             </form>   
  28.         </div>  
  29.     </div>  
  30. </body>  
  31. </html>  
tijiao.aspx代码如下:

[html]  view plain  copy
  1. <%@Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <html xmlns="http://www.w3.org/1999/xhtml">  
  5. <head>  
  6.     <title>ASP.NET登录结果</title>  
  7.     <meta http-equiv="content-type" content="text/html; charset=utf-8" />  
  8. </head>  
  9. <body>  
  10.     <%  
  11.     string n1=Request.Form["name"];  
  12.     string n2=Request.Form["password"];  
  13.     Response.Write("你的用户名:");  
  14.     %></br>  
  15.     <%Response.Write(n1);  
  16.     %></br>  
  17.     <%Response.Write("你的密码:");  
  18.     %></br>  
  19.     <%Response.Write(n2);  
  20.     %></br>      
  21.     </body>  
  22. </html>  
运行结果如图,注意与上一个例子地址栏的区别




转自 :http://blog.youkuaiyun.com/gsls200808/article/details/48578679

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值