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)
Contents
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."); }
转载于:https://www.cnblogs.com/code1992/p/10170358.html
DesignSurface简介相关推荐
- etcd 笔记(01)— etcd 简介、特点、应用场景、常用术语、分布式 CAP 理论、分布式原理
1. etcd 简介 etcd 官网定义: A highly-available key value store for shared configuration and service discov ...
- Docker学习(一)-----Docker简介与安装
一.Docker介绍 1.1什么是docker Docker是一个开源的应用容器引擎,基于Go语言并遵从Apache2.0协议开源 Docker可以让开发者打包他们的应用以及依赖包到一个轻量级,可移植 ...
- 【Spring】框架简介
[Spring]框架简介 Spring是什么 Spring是分层的Java SE/EE应用full-stack轻量级开源框架,以IOC(Inverse Of Control:反转控制)和AOP(Asp ...
- TensorRT简介
TensorRT 介绍 引用:https://arleyzhang.github.io/articles/7f4b25ce/ 1 简介 TensorRT是一个高性能的深度学习推理(Inference) ...
- 谷粒商城学习笔记——第一期:项目简介
一.项目简介 1. 项目背景 市面上有5种常见的电商模式 B2B.B2C.C2B.C2C.O2O B2B 模式(Business to Business),是指商家和商家建立的商业关系.如阿里巴巴 B ...
- 通俗易懂的Go协程的引入及GMP模型简介
本文根据Golang深入理解GPM模型加之自己的理解整理而来 Go协程的引入及GMP模型 一.协程的由来 1. 单进程操作系统 2. 多线程/多进程操作系统 3. 引入协程 二.golang对协程的处 ...
- Linux 交叉编译简介
Linux 交叉编译简介 主机,目标,交叉编译器 主机与目标 编译器是将源代码转换为可执行代码的程序.像所有程序一样,编译器运行在特定类型的计算机上,输出的新程序也运行在特定类型的计算机上. 运行编译 ...
- TVM Operator Inventory (TOPI)简介
TOPI简介 这是 TVM Operator Inventory (TOPI) 的介绍.TOPI 提供了比 TVM 具有更高抽象的 numpy 风格的,通用操作和调度.TOPI 如何在 TVM 中,编 ...
- 计算机视觉系列最新论文(附简介)
计算机视觉系列最新论文(附简介) 目标检测 1. 综述:深度域适应目标检测标题:Deep Domain Adaptive Object Detection: a Survey作者:Wanyi Li, ...
- 2021年大数据ELK(二十三):Kibana简介
全网最详细的大数据ELK文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. Kibana简介 通过上面的这张图就可以看到,Kibana可以用来展示丰富的图表. ...
最新文章
- python可视化窗口制作一个摇骰子游戏_使用python制作一个抽奖小游戏——骰子游戏...
- IO: BIO ? NIO ? AIO?
- AI:人工智能概念之机器学习中常用算法的思维导图集合(非常经典、建议收藏)之详细攻略
- php中的全局异常,PHP的全局错误处理详解
- 关于部署传统的Dynamic Web项目
- int默认值为0,Integer默认值为null
- html5自动打印图片,html2canvas生成清晰的图片实现打印代码示例
- Lesson6 how to use HTML QT Widgets
- webbench之编译安装(一)
- delphi三层架构中注册服务器
- [Everyday Mathematics]20150112
- 可能是最全的java架构师面试题
- Unity LitJson的教程
- 【软件】一个好用的QQ截图工具(百度云免费下载链接)
- 创新大赛成就创业梦想 超30%入榜应用获投资意向
- 各种css文字样式效果——多个行内元素居中,三点,缩进,阴影等
- 性能测试的价值、全链路压测了解
- java json 合并_java json 合并
- 《论语》原文及其全文翻译 学而篇11
- storm mysql trident_Storm Trident状态
热门文章
- python环境变量设置失败
- python闭包和函数调用区别_对python闭包(内嵌函数)的理解
- php unix时间戳单位,PHP对于Unix时间戳的转换
- 怎么使用systemctl启动rabbitmq_光纤激光切割机已经很久没有使用了。再次重新启动它,该怎么办?...
- 从java库学设计模式_java I/O库的设计模式
- 5.Hbase API 操作开发
- MySQL主从数据同步延时分析
- bash脚本基础概念注意点
- C# 传递给C++函数的结构体没有对齐的问题
- Net设计模式实例之桥接模式( Bridge Pattern)(1)