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形式的地图展示,可以自行绘制图形,高亮区 ...
随机推荐
- 直接选择排序(java)
直接选择排序的逻辑非常简单,数组{A1.......An} 先在{A1........An}去获取最小的 与A1交换位置 然后在{A2..........An}中取出最小的 与A2交换位置. ...
- Php中常见的4种随机密码生成方法详解
使用PHP开发应用程序,尤其是网站程序,常常需要生成随机密码,如用户注册生成随机密码,用户重置密码也需要生成一个随机的密码.随机密码也就是一串固定长度的字符串,这里我收集整理了几种生成随机字符串的方法 ...
- 前端构建工具gulpjs的使用介绍及技巧(转)
http://www.cnblogs.com/2050/p/4198792.html gulpjs是一个前端构建工具,与gruntjs相比,gulpjs无需写一大堆繁杂的配置参数,API也非常简单,学 ...
- POJ 3686 The Windy's(思维+费用流好题)
The Windy's Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5362 Accepted: 2249 Descr ...
- vue使用stylus
在package.json中添加 stylus-loader "css-loader": "^0.28.0", "stylus-loader&quo ...
- 几个实用的 jQuery 插件
1. owl.carousel -- 强大实用的jQuery幻灯片插件 2. jquery.nicescroll.min.js -- 自定义滚动条样式,支持 div,iframe,html 等. 3. ...
- hdu 1503 最长公共子序列
/* 给两个串a,b.输出一个最短的串(含等于a的子序列且含等于b的子序列) */ #include <iostream> #include <cstdio> #include ...
- BZOJ 3513: [MUTC2013]idiots
3513: [MUTC2013]idiots Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 476 Solved: 162[Submit][Stat ...
- BZOJ 3897: Power
3897: Power Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 218 Solved: 83[Submit][Status][Discuss] ...
- 【HDOJ5976】Detachment(贪心)
题意:给定n,要求构造若干个各不相同且和为n的正整数使得它们的乘积最大 T<=1e6,1<=n<=1e9 思路:From https://blog.csdn.net/qq_34374 ...