DesignSurface简介
Dinesh Chandnani - 三月 2006 (MSDN Magazine: C#)
- Understanding designers and services
- Creating a hosting form
- Building and using a toolbox
- Loading and managing designers
Code download available at: DesignerHosting.exe (官网VS2005) (VS2010)
DesignSurface and DesignSurfaceManager
The Hosting Form
The Toolbox
Multiple DesignSurfaces
DesignerLoaders
CodeDomDesignerLoader
Conclusion
Figure 5 DesignSurfaceManager Design-Time Services
Service | Description |
---|---|
IUIService | Provides a way for components to show a UI such as error messages and dialog boxes |
IDesignerEventService | Provides a global eventing mechanism for designer events |
// Create the DesignSurface and load it with a form
DesignSurface ds = new DesignSurface();
ds.BeginLoad(typeof(Form)); // Get the View of the DesignSurface, host it in a form, and show it
Control c = ds.View as Control;
Form f = new Form();
c.Parent = f;
c.Dock = DockStyle.Fill;
f.Show();
// Add a Button to the Form
IDesignerHost idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));
Button b = (Button)idh.CreateComponent(typeof(Button)); // Set the Parent of this Button to the RootComponent (the Form)
b.Parent = (Form)idh.RootComponent; // Use ComponentChangeService to announce changing of the
// Form's Controls collection */
IComponentChangeService icc = (IComponentChangeService)
idh.GetService(typeof(IComponentChangeService));
icc.OnComponentChanging(idh.RootComponent,
TypeDescriptor.GetProperties(idh.RootComponent)["Controls");
/* Add a Button to the Form using IToolboxUser */
IDesignerHost idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));
IToolboxUser itu = (IToolboxUser)idh.GetDesigner(idh.RootComponent);
itu.ToolPicked(new ToolboxItem(typeof(Button)));
Method or Property | Description |
---|---|
GetSelectedToolboxItem | Returns the selected toolbox item |
SerializeToolboxItem | Creates a binary serialized object (DataObject) from ToolboxItem |
DeserializeToolboxItem | Returns the ToolboxItem from a binary serialized object (DataObject) |
protected override DesignSurface CreateDesignSurfaceCore(
IServiceProvider parentProvider)
{
return new HostSurface(parentProvider);
}
void HostSurfaceManager_ActiveDesignSurfaceChanged(
object sender, ActiveDesignSurfaceChangedEventArgs e)
{
ToolWindows.OutputWindow o =
this.GetService(typeof(ToolWindows.OutputWindow)) as
ToolWindows.OutputWindow;
o.RichTextBox.Text += "New host added./n";
}
// Load it using a Loader
ds.BeginLoad(new MyLoader());
<Object type="System.Windows.Forms.Form, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="Form1" children="Controls">
<Property name="Name">Form1</Property>
<Property name="DataBindings">
<Property name="DefaultDataSourceUpdateMode">OnValidation</Property>
</Property>
<Property name="ClientSize">292, 273</Property>
</Object>
CompilerParameters cp = new CompilerParameters();
AssemblyName[] assemblyNames =
Assembly.GetExecutingAssembly().GetReferencedAssemblies(); foreach (AssemblyName an in assemblyNames)
{
Assembly assembly = Assembly.Load(an);
cp.ReferencedAssemblies.Add(assembly.Location);
} cp.GenerateExecutable = true;
cp.OutputAssembly = executable; cp.MainClass = "DesignerHostSample." +
this.LoaderHost.RootComponent.Site.Name; // Compile CodeCompileUnit using CodeProvider
CSharpCodeProvider cc = new CSharpCodeProvider();
CompilerResults cr = cc.CompileAssemblyFromDom(cp, codeCompileUnit); if (cr.Errors.HasErrors)
{
string errors = string.Empty;
foreach (CompilerError error in cr.Errors)
{
errors += error.ErrorText + "/n";
}
MessageBox.Show(errors, "Errors during compile.");
}
DesignSurface简介的更多相关文章
- ASP.NET Core 1.1 简介
ASP.NET Core 1.1 于2016年11月16日发布.这个版本包括许多伟大的新功能以及许多错误修复和一般的增强.这个版本包含了多个新的中间件组件.针对Windows的WebListener服 ...
- MVVM模式和在WPF中的实现(一)MVVM模式简介
MVVM模式解析和在WPF中的实现(一) MVVM模式简介 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在 ...
- Cassandra简介
在前面的一篇文章<图形数据库Neo4J简介>中,我们介绍了一种非常流行的图形数据库Neo4J的使用方法.而在本文中,我们将对另外一种类型的NoSQL数据库——Cassandra进行简单地介 ...
- REST简介
一说到REST,我想大家的第一反应就是“啊,就是那种前后台通信方式.”但是在要求详细讲述它所提出的各个约束,以及如何开始搭建REST服务时,却很少有人能够清晰地说出它到底是什么,需要遵守什么样的准则. ...
- Microservice架构模式简介
在2014年,Sam Newman,Martin Fowler在ThoughtWorks的一位同事,出版了一本新书<Building Microservices>.该书描述了如何按照Mic ...
- const,static,extern 简介
const,static,extern 简介 一.const与宏的区别: const简介:之前常用的字符串常量,一般是抽成宏,但是苹果不推荐我们抽成宏,推荐我们使用const常量. 执行时刻:宏是预编 ...
- HTTPS简介
一.简单总结 1.HTTPS概念总结 HTTPS 就是对HTTP进行了TLS或SSL加密. 应用层的HTTP协议通过传输层的TCP协议来传输,HTTPS 在 HTTP和 TCP中间加了一层TLS/SS ...
- 【Machine Learning】机器学习及其基础概念简介
机器学习及其基础概念简介 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...
- Cesium简介以及离线部署运行
Cesium简介 cesium是国外一个基于JavaScript编写的使用WebGL的地图引擎,一款开源3DGIS的js库.cesium支持3D,2D,2.5D形式的地图展示,可以自行绘制图形,高亮区 ...
随机推荐
- [oldboy-django][2深入django]Form总结
1 form总结 # Form数据格式验证 - 原理: - 流程 a.写类LoginForm(Form): 字段名 = fields.xxFields() # 验证规则,本质是正则表达式(fields ...
- stdlib.h中自带的两个算法qsort,bsearch
http://zh.cppreference.com/w/c/algorithm ========== void qsort( void *ptr, size_t count, size_t size ...
- 【转】Unity3D研究院之DontDestroyOnLoad的坑
http://www.xuanyusong.com/archives/2938 Unity中的一个方法DontDestroyOnLoad可以让某些游戏对象在切换场景的时候不是施放,听起来是一个非常好的 ...
- Spring4.0实战 rest相关
package com.paic.pay.merchant.web; import com.paic.pay.merchant.entity.MerchantUser; import com.paic ...
- SOCK5代理服务器
SOCK5代理服务器 简单介绍下比较好用的代理服务器,在部署过程中在内外网访问,需要切网比较麻烦,所以可以在互联网区部署sock5代理,通过配置代理切换服务器, 比较方便配置,节省时间. 官网: ht ...
- hihoCoder #1809 : 本题数据范围五千
Analysis (一) 猜想:答案跟 $q_1, q_2, q_3$ 无关:考虑排列 $q$ 是 $1, 2, 3$ 的情况,此时符合要求的排列 $p$ 实际上满足: 对于任意 $i < j ...
- html执行.NET函数 html操作数据库 html与ashx结合
原文发布时间为:2009-09-30 -- 来源于本人的百度文章 [由搬家工具导入] html页面执行.NET函数 html与ashx的结合 1、添加一般应用程序Handler.ashx <%@ ...
- WebStorm使用JetBrains IDE Support调试
1.安装WebStorm 2.安装谷歌的chome浏览器,并切换到开发者模式 3.下载并安装 JetBrains IDE Support(将2.0.7_0.crx文件直接拖到谷歌浏览器中就会自动安装) ...
- android中提示&对话框----AlertDialog
AlertDialog(对话框) 一.对话框的基本使用流程 step1:创建AlertDialog.Buider; step2:调用setIcon()设置图标,setTitle()或者setCusto ...
- mybatis hashmap 输入键值对为空时,key 丢失
参考文档:https://blog.csdn.net/lulidaitian/article/details/70941769 springMVC+mybatis查询数据,返回resultType=” ...