如何在组件(Component中)模拟用户控件(UserControl)中FindForm()?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms; namespace Samples
{
public partial class Controller : Component
{
public Controller()
{
InitializeComponent();
} public Controller(IContainer container)
{
container.Add(this); InitializeComponent();
} [Browsable(false)]
public virtual Form OwnerForm
{
get { return _ownerForm; }
set { _ownerForm = value; }
}
Form _ownerForm = null; public override ISite Site
{
get { return base.Site; }
set
{
base.Site = value;
this.OwnerForm = FindForm();
}
} Form FindForm()
{
IReferenceService referenceService = (IReferenceService)GetService(typeof(IReferenceService));
if (referenceService != null)
{
// 取得组件所在的窗体对象
object[] parent = referenceService.GetReferences(typeof(Form));
Form form = parent[] as Form;
return form;
} return null;
}
}
}
如何在组件(Component中)模拟用户控件(UserControl)中FindForm()?的更多相关文章
- C#中,用户控件UserControl里面用Panl加载UserControl,并实现利用委托互相传值
用户控件主窗体结构:左侧树形菜单,右侧Panl: 根据点击的菜单节点,panl里面选择性加载某一个子窗体用户控件,并传值给子窗体: 反之,在子窗体进行相应的操作之后,传值给主窗体,触发主窗体的刷新. ...
- ASP.NET MVC 中使用用户控件——转
讲讲怎么在 ASP.NET MVC2中使用用户控件.首先我们新建一个用户控件, 我们命名为SelectGroup.ascx,代码如下 <%@ Control Language="C ...
- 在VisualStudio 工具箱中隐藏用户控件
当我们创建一个用户控件后,VisualStudio会自动将其添加到工具箱中,本来这是一个比较贴心的设计.但是,有的时候,我们并不想将用户控件放到工具箱中. 例如:在WPF中,为了避免一个页面的控件过多 ...
- WindowsXamlHost:在 WPF 中使用 UWP 控件库中的控件
在 WindowsXamlHost:在 WPF 中使用 UWP 的控件(Windows Community Toolkit) 一文中,我们说到了在 WPF 中引入简单的 UWP 控件以及相关的注意事项 ...
- 用户控件(UserControl)
简介 "用户控件"继承自UserControl,而UserControl继承自ContentControl,也就是内容控件UserControl和Window是一个层次上的,都有x ...
- C# WinForm中添加用户控件
转:https://blog.csdn.net/haelang/article/details/40681003 有的时候我们需要频繁使用一些系统默认工具的组合,那么就可以使用自定义用户控件. 起一个 ...
- 如何在Web.config中注册用户控件和自定义控件
问题: 在ASP.NET 的早先版本里,开发人员通过在页面的顶部添加 指令来引入和使用自定义服务器控件和用户控件时,象这样: <%@ Register TagPrefix="scott ...
- C# winform中自定义用户控件 然后在页面中调用用户控件的事件
下面是用户控件的代码: using System; using System.Collections.Generic; using System.ComponentModel; using Syste ...
- Web页面获取用户控件页面中服务器控件的值
用户控件页面后台: public string P_Name{get { return txt_P_name.Value; }set { txt_P_name.Value = value; }} We ...
随机推荐
- eclipse luna maven搭建spring mvc
1. 环境配置 a) Java 1.7 b) Eclipse luna c) Maven3.2.5 d) Spring 4.1.4 2. ...
- Servlet程序访问的流程
方式一: jsp: <font color="red">${ msg }</font> <form action="/personal/re ...
- 10 程序员必备:Linux日常维护命令
一.服务器硬件配置 1.查看硬盘及分区情况 # fdisk -l 2.查看分区空间使用情况 可以查看各分区大小.已使用.可用.已使用百分比.挂载情况 1)默认单位为K # df 2)可读性更好的显示, ...
- c++中引用和指针的区别
1.指针和引用的主要区别. 引用是为变量起另一个名字(小名),一般在变量初始化时,初始值直接拷贝给变量,定义引用时,把引用(小名)和初始值“绑定”在一起,而不是将初始值拷贝给引用.因为 无法将引用重新 ...
- 调用Newtonsoft.Json 报FileNotFoundException 错误
具体如下: Exception StackTrace at Newtonsoft.Json.Converters.BinaryConverter.CanConvert(Type objectType) ...
- LitDB文章
阅读目录 1.LiteDB初步介绍 2.LiteDB使用基本案例 3.LiteDB的技术细节 4.资源其他 今天给大家介绍一个不错的小巧轻量级的NoSQL文件数据库LiteDB.本博客在2013年也介 ...
- 查看CentOS版本方法
查看内核版本 这个命令适用于所有的linux,包括Redhat.SuSE.Debian.Centos等发行版. root@MyMail ~ # uname Linux root@MyMail ~ # ...
- [platform]新旧内核的device设备注册对比
转自:http://blog.chinaunix.net/uid-7332782-id-3268801.html 1. Version2.6内核启动过程 start_kernel( ) //板子上电启 ...
- ScalaTour 2.函数
/** * 1. case class与模式匹配 */ object TestFunction extends App{ def value(expr:Expr): Int = expr match ...
- iphone Dev 开发实例10:How To Add a Slide-out Sidebar Menu in Your Apps
Creating the Xcode Project With a basic idea about what we’ll build, let’s move on. You can create t ...