Prevent Adding Component More than once
Question: I'm developing a C# component, I want to prevent the user from adding this component to the Form if the Form already has an instance of the component.
[Designer(typeof(myComponentDesigner))]
class myComponent : Component
{
public myComponent(IContainer container)
{
// Add object to container's list so that
// we get notified when the container goes away
container.Add(this);
}
} class myComponentDesigner : ComponentDesigner
{
public override void InitializeNewComponent(System.Collections.IDictionary defaultValues)
{
IDesignerHost service = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
if (service == null) return;
ComponentCollection cc = service.Container.Components; int count = ;
foreach (Component c in cc)
{
if (c.GetType() == this.Component.GetType() )
{
count++;
if (count > )
{
service.Container.Remove(this.Component);
MessageBox.Show(
"You cannot add more than one instance of the myComponet!");
return;
}
}
} base.InitializeNewComponent(defaultValues);
}
}
Prevent Adding Component More than once的更多相关文章
- Blazor组件自做五 : 使用JS隔离封装Google地图
Blazor组件自做五: 使用JS隔离封装Google地图 运行截图 演示地址 正式开始 1. 谷歌地图API 谷歌开发文档 开始学习 Maps JavaScript API 的最简单方法是查看一个简 ...
- GroupLayout 布局
文档说明: 以下引自:Java™ PlatformStandard Ed. 7 public class GroupLayout extends Object implements LayoutMan ...
- [SinGuLaRiTy] COCI 2011~2012 #2
[SinGuLaRiTy-1008] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 测试题目 对于所有的题目:Time Limit:1s ...
- gitlab通过api创建组、项目、成员
前戏 获取gitlab中admin用户的private_token Groups API 获取某个组的详细 curl --header "PRIVATE-TOKEN: *********&q ...
- 基于vue实现上下滑动翻页效果
18年年底的时候,一直在做年度报告的H5页面,因为项目需要,需要实现上下滑动翻页,并且上滑的页面比正常页面的比例要缩小一定比例. 效果类似于http://www.17sucai.com/pins/de ...
- Vickers Vane Pump - Hydraulic Vane Pump Failure: Cavitation, Mechanical Damage
One of our readers recently wrote to me about the following questions: “Recently, we purchased a sec ...
- hexo next主题深度优化(一),加入pjax功能。
文章目录 背景: 进入正题 pjax初体验--instantclick 真正的pjax 第一步 第二步 第三步 第四步 专门基于hexo next主题的pjax(将丢失的js效果重现) 将下面讲到的提 ...
- Blazor组件自做八 : 使用JS隔离封装屏幕键盘kioskboard.js组件
1. 运行截图 演示地址 2. 在文件夹wwwroot/lib,添加kioskboard子文件夹,添加kioskboards.js文件 2.1 常规操作,懒加载js库, export function ...
- [Angular] Adding keyboard events to our control value accessor component
One of the most important thing when building custom form component is adding accessbility support. ...
随机推荐
- 九度OJ题目1387斐波那契数列
/*斐波那契数列,又称黄金分割数列,指的是这样一个数列: 0.1.1.2.3.5.8.13.21.…… 在数学上,斐波纳契数列被定义如下: F0=0,F1=1, Fn=F(n-1)+F(n-2)(n& ...
- net上传图片重命名
string FileName = File.FileName;//获取上传文件的名称 string Str = FileName.Split('.')[1];//获取上传文件的后缀 string N ...
- ContentProvider 使用示例(转载)
ContentProvider 使用示例(转载) 当数据需要在应用程序间共享时,我们就可以利用ContentProvider为数据定义一个URI.之后其他应用程序对数据进行查询或者修改时,只需要从当前 ...
- 用Filter解决乱码和jsp缓存问题
1) 乱码Filter: 新建一个:CharSetFilter package com.my.filter; import java.io.*; import javax.servlet.*; imp ...
- 【转】Linux 的启动流程
半年前,我写了<计算机是如何启动的?>,探讨BIOS和主引导记录的作用. 那篇文章不涉及操作系统,只与主板的板载程序有关.今天,我想接着往下写,探讨操作系统接管硬件以后发生的事情,也就是操 ...
- DNS查询指令nslookup
描述: Nslookup指令是一个查询internet域名服务的程序.Nslookup指令有两个模式:交互式和非交互式. 交互式模式允许用户查询不同种类的主机和域名或在一个域名里输出主机列表,目的是查 ...
- 验证视图状态 MAC 失败
起因: 最近在做一个项目需要用到生成多个Html页,采用一下方法动态生成. WebRequest request = WebRequest.Create(pageurl); WebResponse r ...
- 嵌入式设计模式:有限状态自动机的C语言实现
转自:http://www.cnblogs.com/autosar/archive/2012/06/22/2558604.html 状态机模式是一种行为模式,在<设计模式>这本书中对其有详 ...
- Android SDK的docs访问速度很慢(新)
#设置环境变量 名称:ANDROID_SDK_HOME 值:我的为-->E:\android\android-sdk #代码编译及运行 1.把下面的代码保存为:AndroidDocRepair. ...
- C# DEBUG 调试信息打印及输出详解
转载自: http://blog.csdn.net/aaaaatiger/article/details/5583301 1.debug只在[debug模式下才执行](运行按钮后面的下拉框可选) 2. ...