管理你的Visual Studio Toolbox

本文档详尽介绍了如何将WPF或WinForms控件集成到Visual Studio Toolbox,包括手动安装、使用Toolbox Control Installer (TCI)、DTE对象模型、VSPackage和VSI包等方法。每种方法的安装、更新、卸载和多版本支持进行了详细阐述,帮助开发者选择最适合的集成方式。
摘要由CSDN通过智能技术生成

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

原文链接

The Most Complete Guide to Visual Studio Toolbox Control Integration

Libor Tinka, Lead Developer, ComponentOwl.com

Contents

1. Introduction
2. Prerequisites
3. Creating a Sample Control
4. Manual Toolbox Integration
5. Toolbox Integration using TCI
6. Toolbox Integration using DTE
7. Toolbox Integration using VSI Packages
8. Toolbox Integration using VSPackages
9. Toolbox Integration using VSIX Packages
10. Supporting Multiple Version of .NET Framework
11. Sample Source Code

1. Introduction

This tutorial is intended for developers who would like to distribute their WPF or WinForms controls and automatically put them into Visual Studio Toolbox during installation.

I struggled with Toolbox integration earlier because there are several possible approaches (harder to decide between them). Each approach have its own pros and cons and no overall comparison is provided. I wrote this tutorial to shed some light on the topic and spare you hours, maybe days of research and experimenting with aspects of Visual Studio (Toolbox) extensibility.

We will first take a look on Toolbox control integration in general to get a big picture. Each approach will be then discussed in detail and the following question will be answered:

  • How to install control in Visual Studio Toolbox?
  • How to update the control?
  • How to uninstall/remove the control?
  • How to support multiple Visual Studio versions?

There are several options on how to integrate your controls with Visual Studio Toolbox:

  • Manual installation
  • Toolbox Control Installer (TCI)
  • Visual Studio Automation Object Model (DTE)
  • VSPackage
  • VSI package
  • VSIX package

Manual installation

The simplest way of adding control into Visual Studio Toolbox is from within the IDE.

This approach have one crucial drawback, which is that you leave Toolbox integration to the user. Many developers are not that experienced with Visual Studio and when your component is shipped, even if you provide appropriate step-by-step guide, they may find it too complicated and rather try another component which "just works". I thought that every developer using Visual Studio is experienced enough to know how to add new items in VS Toolbox, but I received few e-mails from users who uninstalled the product just because the component have not appeared in the Toolbox and they thought it is broken (without reading our documentation, of course). On the other hand, there is a group of users who are not experienced developers, but are in charge of trying some products in a given company (e.g. project managers). These people can install the component, play with it and they would really appreciate if it just works. This increases chance they will actually purchase your product.

Advantages: zero effort
Disadvantages: require experienced users, slows user producitivity, updating controls is not intuitive

Toolbox Control Installer (TCI)

Visual Studio 2005 SDK contained a VSPackage called Toolbox Control Installer. This package comes pre-installed with Visual Studio 2008 and newer. Its job is to simplify the specific task of extending Visual Studio Toolbox. This approach requires you to install your assembly in GAC (Global Assembly Cache) and create a key in Windows Registry.

Advantages: simple and fast component installation, updating and removing
Disadvantages: requires installation in GAC (not always wanted), VS 2005 supported with SDK only

Visual Studio Automation Object Model (DTE)

If you are not afraid of COM, you can try DTE (Development Tools Environment) approach. There is already a project on CodePlex called Visual Studio Toolbox Manager, which solves the toolbox integration problem using a simple command-line application. The project is outdated since it does not support Visual Studio 2010 and newer. I made a project called DteToolboxInstaller, which is also a command-line application and does support Visual Studio 2013, 2012, 2010, 2008 and 2005. You can use the project as you like. The main disadvantage of DTE approach is the speed. The installer have to run devenv.exe using the automation interface, create a fake VS Solution, open Toolbox, add the stuff and then close the Solution. The whole process take no less than 10 seconds. If you want to integrate with two or three versions of Visual Studio, it can take well over a minute.

Advantages: does not require updating registry or GAC, full control over Toolbox
Disadvantages: very slow, separate installation required for every version of Visual Studio

VSPackage

A VSPackage seems to be a natural option. VSPackages allow any type of Visual Studio extension and you can manipulate Toolbox as well. There was a trouble with VSPackages in providing a Package Load Key (PLK) which can be generated only manually using web form. The requirement for PLK vanished with Visual Studio 2010 (hooray!). The nice thing about VSPackage approcach is that it does not slow down the installation process. The package is loaded and the controls are installed on-demand (when the Toolbox is opened for the first time after installation). After trying all the approaches, using VSPackage seems to be fastest and most universal one.

Advantages: quick installation, appearance in About box and other extensibility features
Disadvantages: cmplicated setup, each component requires its own package if shipped separately

VSI Package

VSI packages are quite old but you can use them for integration with Visual Studio 2005 and newer. It have very simple structure and you can create one even without Visual Studio. The only trouble with VSI compared to other approaches is invoking a wizard form which cannot be suppressed. The installation just cannot run in "quiet" mode. Another trouble with VSI is that a digital signature is required in order to get rid of a warning dialog. Your control will be always installed under "My Controls" tab in the To

VS风格的ToolBox和QQ的界面很相似,都是有多个栏目,并且这些栏目可以展开和折叠,当鼠标在某个子栏目上时,可以高亮显示,另外在VS风格的ToolBox中,点击选中项目的时候,要用特殊的颜色标识出来。 1. 创建控件的边框,我在前边的文章也讲过(),直接将代码复制过来,稍做修改即可。 2. 添加滚动条,因为我们的控件只需要垂直的滚动,所以我只只加入一个垂直的滚动条。 3. ToolBox包含多个Category,我们不但要创建Category类,还要创建这个类的集合。 4. 每一个Category包含多个Item,我们不但要创建ToolBoxItem类,还要创建这个类的集合。 5. 重载OnPaint方法,绘制控件的内容,在绘制的时候要注意滚动条的当前值,由于采用了双缓冲机制,所以每次总是将所有的内容重绘一次,不考虑ClipRect。 6. 写一个方法,根据鼠标的坐标计算出鼠标指向的Item或者Category,这个方法是这个控件的核心。 7. 重载OnMouseMove方法,当鼠标指向某个Item的时候,高亮显示出来。 8. 重载 OnMouseDown方法,当鼠标在某个Item上按下的时候,用指定的颜色标识出来,如果鼠标按下的地方是一个Category,根据当前的情况展开或者时折叠这个category。 9. 计算控件当前状态的内容的总的高度,用于设置滚动条的可见与不可见。 10. 暴露一个属性,用于为用户提供当前选中的Item。 11. 声明一个ItemChanged事件,便于用户在选择另一个Item时添加处理的代码。 实现了上述的内容,这个控件也就基本完成了。由于代码并不复杂,我就不将代码列出来讲解了,我将提供代码的下载,大家在看代码的时候,如有不明白的地方,可以参考我前面的控件教程。因为只花了几个小时写的这个控件,难免还有一些问题,请大家指出。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值