一步步,掌握SharpDevelop

 

SD是一款开源的.NET IDE,最新的版本是2.2
地址是:http://www.icsharpcode.net/OpenSource/SD/
SD最大的特点是,程序的核心是一插件管理系统,并不实现什么具体的功能,实现都是包含在插件中,
这样的好处是,在进行较大的程序开发的时候,可以方便地分给每一个成员完成,并且如果其中一个插件出现问题不会影响到其它的插件的运行,可以方便的Enable,Disable插件,
程序的在升级的时候,也是十分方便,安装一个插件就安装一个功能,多一个菜单项,或者工具条,这样多么方便啊,再也不用,打开整个的工程了,节省人力资源啊,及维护成本.

我在网上找了好些文章,其中比较详细是michael-zhang这位仁兄:他的博客地址是:
http://www.cnblogs.com/michael-zhang/articles/621148.html
他用的源代码是比较新的,因为他发表博客的时间是: 2007-01-15,想来不会太旧,

我是刚刚接触没有办法做太大的动作,我的第一步的目的是做一个多窗体的显示,
并在上边加入一个菜单项,和一个工具栏,,并显示一个子窗体

效果如下:

 

其实很简单,我就只贴一些代码,里边有非常详细的解释.

Main函数

public   static   void  Main( string [] args)
{
    
try
    
{
        LoggingService.Debug(
"cxy sharp 开始启动");
        
// Get a reference to the entry assembly (Startup.exe)
        Assembly exe = typeof(MainForm).Assembly; 
        
// "data/resources" for language resources, "data/options" for default options
        FileUtility.ApplicationRootPath = Path.GetDirectoryName(exe.Location);
        LoggingService.Debug(
"ApplicationRootPath is :"+FileUtility.ApplicationRootPath);
        LoggingService.Info(
"启动核心服务..."); 
        
        
//传入的参数是默认的显示消息时的标题
        
//默认的路径是:%Application Data%%参数名%,我们可以从写c.ConfigDirectory
        CoreStartup coreStartup = new CoreStartup("cxySharp"); 
        
//指定属性文件的名称:如appproperties.xml
        coreStartup.PropertiesName = "AppProperties";
        
        
//初始化其它服务,如:ResourceService, PropertyService
        coreStartup.StartCoreServices();
        
        
//注册文字及图片资源,资源文件被作为嵌入式资源编译进去
        
//本地化资源,自动加载进去放在data/resources目录下边的资源
        ResourceService.RegisterNeutralStrings(new ResourceManager("iconres.resx", exe));
        
        
        LoggingService.Info(
"查找 AddIns...");
        
//注意::::::::::::这里一定要保证目录的存在
        
// Searches for ".addin" files in the application directory.
        
//查找AddIns目录下边的以.addin为扩展名的文件
        coreStartup.AddAddInsFromDirectory(Path.Combine(FileUtility.ApplicationRootPath, "AddIns"));
        
        
//在用户配置文件目录下的查找"AddIns.xml"文件,然后从里边指出用户禁用的插件,或者外置的插件
        coreStartup.ConfigureExternalAddIns(Path.Combine(PropertyService.ConfigDirectory, "AddIns.xml"));
        
        LoggingService.Info(
"PropertyService configDirecotry is :"+PropertyService.ConfigDirectory);
        
        
        
//配置用户的插件,同样这也用来安装,卸载,及升级,用户的插件
        coreStartup.ConfigureUserAddIns(Path.Combine(PropertyService.ConfigDirectory, "AddInInstallTemp"),
                                        Path.Combine(PropertyService.ConfigDirectory, 
"AddIns"));
        
        
//加载插件树
        LoggingService.Info("加载插件树...");                
        
//最后初始化程序,这将分析.addin文件,并创建插件树,同时,这些运行WorkSpace中的自动开始
        coreStartup.RunInitialization();
        
        
//初始化工作台
        LoggingService.Info("初始化工作台...");
        
        
//这将创建一个Form的实例
        
//Workbench.InitializeWorkbench();
        DemoBase.WorkBench.InitializeWorkBench();

         
        LoggingService.Info(
"程序开始运行......");
        
// 在这里进入消息循环.
        Application.Run(DemoBase.WorkBench.Instance); 
        
    }

    
catch(Exception ex)
    
{
        MessageService.ShowError(ex,
"");
    }

    
finally
    
{
        
try
        

            
//保存更改的属性
            PropertyService.Save();
        }

        
catch (Exception ex)
        
{
            MessageService.ShowError(ex,
"保存配置失败");
        }

    }

     
}
 

Form中的代码

 

public   class  WorkBench:Form
{
    
static WorkBench m_instance;
    
    
public static  WorkBench Instance
    
{
        
get
        
{
            
return m_instance;
        }
 
    }

    
    
public static void InitializeWorkBench()
    
{
        m_instance
=new WorkBench();
         
    }

    
    
    
private MenuStrip m_menu;
    
private ToolStrip m_toolbar; 
    
    
    
    
private WorkBench()
    
{
        
this.Text="这是我的窗体";
        
        
        m_toolbar
=new ToolStrip();
        ToolStripButton item 
= m_toolbar.Items.Add("保存"as ToolStripButton;
        item.CheckOnClick
=true;
        item.Click
+=OnToolBarClick;
        
this.Controls.Add(m_toolbar);

        m_menu
=new MenuStrip(); 
        m_menu.Items.Add(
"exit");
        m_menu.Click
+=OnExit;
        
this.Controls.Add(m_menu);

        
this.IsMdiContainer=true;            
        Form test
=new Form();
        test.Text
="这是一个子窗体";
        test.MdiParent
=this;
        test.Show(); 
        
        Application.Idle
+=new EventHandler(OnApplicationIdle);
        
    }

    
public void OnExit(object sender,System.EventArgs e)
    
{
        Application.Exit();
    }

    
    
public void OnToolBarClick(object sender,System.EventArgs e)
    
{
        MessageBox.Show(
"I was a tool bar i was clicked");
    }
 
 
    
public void OnApplicationIdle(object sender,System.EventArgs e)
    
{
        UpdateMenuItemStatus();
    }

    
    
public void UpdateMenuItemStatus()
    
{
        
    }

}
http://dl2.csdn.net/down4/20070717/17192502963.rar
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值