Smart Client Software Factory 加上Hello world

来源:互联网 发布:韩服fifaonline3数据库 编辑:程序博客网 时间:2024/05/16 14:30

好久没有搞Smart Client Software Factory了,记得上次用这个做项目是在两年前,现在又需要用到它了,再重新拾起吧。

先把一个完整的创建一个新的窗体的过程做一遍,复习一下。

创建项目的时候

 Guidance Packages Project ->  Smart Client Software Factory 2010 -> Smart Client Application

解决方案起名叫SmartClient

然后会自动生成如下结构的项目

文件夹Source

         ---- 文件夹Infrastructure

                      ---- Infrastructure.Interface

                      ---- Infrastructure.Layout

                      ---- Infrastructure.Library

                      ---- Infrastructure.Module

                      ---- Shell

这个时候,项目只有一个窗体,就是Shell,它是这个项目的入口

下一步,在文件夹Infrastructure上右键 Smart Client Software Factory -> Bussiness Module ,然后让你建一个新项目,起名叫 Module,默认还会为这个项目生成一个接口项目,Module.Interface,然后这两个项目就是我们的业务逻辑模块了.

再下一步,要在Module中添加一个新的窗体,在Module项目上右键 -> Smart Client Software Factory -> Add View 其间会问你要不要创建一个新文件夹用来包含view的文件,最后选是,这样项目结构更清晰一些。

这样,一个窗体算是创建成功了,但这还不算完,我们需要把View嵌进Shell里面去显示,这又得分几步。

1)在刚刚创建的Module项目中,找到ModuleController类,引用

     using SmartClient.Module.Interface.Constants;

 2)找到AddViews 方法

 // Add the HelloWorld view (smart part) to the WorkItem and show // the view through the RightWorkspace on the shell. View view = ShowViewInWorkspace<View>(WorkspaceNames.RightWorkspace);

      到这一步,View已经加到Shell里面去了,但是我们还想做的更好一些,下面在View里面加一个菜单,最终效果就像这样,View里面也加入了一个菜单项,名         为"Hello World"

     

3)下面为了加上菜单,先在Module项目文件夹中的CommandNames类加入如下代码

 // A command is an abstraction of UI elements events, // such as the click of a button.  public const string ShowModelMessage = "ShowModelMessage";

4)然后再打开之前的ModuleController类,在方法ExtendToolStrip中加入如下代码,其功能主要是设置按钮上的文字

AddToolStripButton(Constants.CommandNames.ShowModelMessage, "Hello World");
5)在ModuleController类中再加入AddToolStripButton这个方法的方法体,其功能主要是加入菜单按钮

 // This method creates a ToolStripButton and adds it to the // MainToolbar using the UIExtensionSites. Then it associates // the Click event of the button to a command. // UIExtensionSites are points of extension where modules can // add UI elements, such as items in a toolbar. private void AddToolStripButton(string commandName, string text) {    ToolStripButton button = new ToolStripButton();    button.Text = text;    button.ToolTipText = text;     // Add the button to the MainToolBar.    WorkItem.UIExtensionSites[UIExtensionSiteNames.MainToolbar].Add(button);     // Associate the Click event of the button to a command    WorkItem.Commands[commandName].AddInvoker(button, "Click"); }

这个过程就是在WorkItem中加上菜单按钮,并注册Click事件

6)最后加入OnShowModelMessage来响应Command命令

 // A Command Handler is used to handle the firing of a command.  [CommandHandler(Constants.CommandNames.ShowModelMessage)] public void OnShowModelMessage(object sender, EventArgs e) {    // Add the HelloWorld view (smart part) to the WorkItem and    // show the view through the RightWorkspace on the shell.    View view = ShowViewInWorkspace< View >(WorkspaceNames.RightWorkspace); }
0 0
原创粉丝点击