创建自定义 winforms 容器

Create custom winforms container(创建自定义 winforms 容器)

本文介绍了创建自定义 winforms 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 winforms 中创建一个与容器控件具有相同行为的控件.我的意思是:在设计模式下,当我将控件放入其中时,它会分组,就像一个组合框.

I want to create a control in winforms with same behavior as the container controls. I mean: in design mode, when I drop controls in it, it will group then, just like a groupbox.

我正在创建的这个控件包含一些其他控件和一个 GroupBox.我所需要的只是:当一个控件在我的自定义控件上以设计模式放置时,我只需将它放在嵌套的 GroupBox 中.

This control I'm creating contains some other controls AND a GroupBox. All I need is: when a control is droped in design mode over my custom control, I'll just put it inside the nested GroupBox.

但我不知道如何让我的控件在设计模式下响应这种操作.

But I can't figure out how make my control respond to that kind of action in design mode.

推荐答案

也许 这个 是你需要的,我前段时间在 CodeProject 找到的:

Maybe this is what you need, I found it at CodeProject a time ago:

设计嵌套控件:

本文演示了如何允许一个 Control,它是另一个控件接受在设计时将控件放到它上面时间.篇幅不大,代码不多,而且这可能不是官方"或最佳方式.它确实,但是,工作,并且就我能够测试它而言是稳定的.

This article demonstrates how to allow a Control, which is a child of another Control to accept having controls dropped onto it at design time. It is not a large article, there is not much by way of code, and this may not be either the 'official' or best way to do this. It does, however, work, and is stable as far as I have been able to test it.

这篇关于创建自定义 winforms 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:创建自定义 winforms 容器

基础教程推荐