如何限制自制Control的使用权限?

sarmoo 2003-08-22 12:16:54
1.自制控件 MyControl:Control
2.自制Form MyForm:Form

问题:
当MyControl被加到一个Form或容器中时,想判断是否此容器类型为MyForm,
是的话则允许加入,正常运行,
不是的话则MyControl自动Dispose,并发出警告信息。

请问该如何实现?
或者有没有其他方式?

...全文
173 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
angelior 2003-09-15
  • 打赏
  • 举报
回复
:)
sarmoo 2003-09-12
  • 打赏
  • 举报
回复
OK,搞定! 方法是:
protected override void OnParentChanged(EventArgs e)
{
if( this.TopLevelControl != null && !(this.TopLevelControl is MyForm) )
{
this.Dispose();
throw new Exception();
}

base.OnParentChanged (e);
}

谢谢各位!结贴!!
wolve 2003-09-11
  • 打赏
  • 举报
回复
建议在onParentChanged中处理,如果在设计时处理,可能用户会在运行时动态添加。
sarmoo 2003-09-02
  • 打赏
  • 举报
回复
楼上:
请问这段代码应放在何处?
另:你给的MSDN地址我打不开,能否给出个关键字?

谢谢!
colin666 2003-09-02
  • 打赏
  • 举报
回复
if(this is MyForm)
{

}
else
{
}

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/csref/html/vclrfIsPG.htm
维她奶 2003-08-27
  • 打赏
  • 举报
回复
gz
saucer 2003-08-22
  • 打赏
  • 举报
回复
if you mean to do this at design-time, consider to write a custom ControlDesigner for your MyControl, override Initialize method to make sure the passed in component is of MyForm type

see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdesigncontroldesignerclasstopic.asp

http://www.tripleasp.net/KBAlertz.aspx?NavID=34
顾君彦 2003-08-22
  • 打赏
  • 举报
回复
if(DesignMode)
{
//判断
//MessageBox.Show(...);
}
sarmoo 2003-08-22
  • 打赏
  • 举报
回复
Yeah, it's in design time.
摘 要 在生活中有些场合并不是任人自由进出的,而只允许有进出权限者通行,这时,就得 使用出入口管理系统即门禁系统。传统的门锁是最古老、最简单的门禁方式,一把锁配 一把钥匙,几把锁就要配几把钥匙,使用不便。为了适应信息时代的需要,保证建筑内 部的安全性,满足用户当时的各种需求,智能门禁系统应运而生。 根据市场需求设计一款基于RFID的门禁系统。本设计采用AT89C52作为主控芯片,用 北京易火眼公司的YHY502ATG专用读卡器模块用来读射频卡的信息,当有卡进入到读卡器 读卡的范围内时就会读取到相应的卡序列号,并根据得到的卡序列号做出相应的操作。 在扩展时采用Delphi软件做上位机,并建立一个Access数据库用来存储用户信息。上位 机与下位机之间的通信采用串口通信,选用MAX232CPE芯片完成上、下位机之间的通信。 按键部分采用的是自制的3*4按键矩阵,采用线反转法来判断是哪个按键按下。本设计实 现了自动、准确的识别卡序列号,对门禁系统起着重要的作用。 关键词 门禁系统;射频识别;读卡器 Abstract Some occasions in life is not a fancy free access, while access privileges are allowed only to those who pass this time, you have to use the import and export management system for the access control system. The traditional hardware is the oldest, the easiest access mode, a lock with a key lock is necessary with a few a few keys, use the inconvenience. In order to meet the information needs of the times to ensure the safety of inside the building to meet the diverse needs of the user at that time, intelligent access control system came into being. According to market demand to design a RFID-based access control system. This design uses AT89C52 as the master chip, with eyes of fire the company's Beijing Yi YHY502ATG dedicated RF card reader module for reading the information, when there are card into the reader within the reader, it reads to the appropriate card serial number, and in accordance with the card serial number to be made by the appropriate action. Delphi software used in the expansion do host computer, and the establishment of an Access database used to store user information. Upper plane and lower-bit-machine communication using serial communication, use MAX232CPE chip to complete the upper and lower-bit-machine communication. Key part is the self-made 3 * 4 keypad matrix, using linear inversion method to determine which button is pressed. This design enables automatic, and accurate identification card serial number of the access control system plays an important role. Keywords Access Control System R

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧