- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 TableLayoutPanel Windows 窗体控件自定义现有的智能标记内容,以便在 Windows 窗体设计器中使用(我实现了一个设计器,该设计器利用了 System.ComponentModel.Design 和 System.Windows 公开的 WinForms 设计器功能。 Forms.Design 命名空间)。无论提供何种方法作为解决方案,当我的控件被添加到 Visual Studio 工具箱时,以及当我的控件在 Visual Studio IDE 中以设计模式放置在 WinForm 图面上时,它也必须起作用。
这是我正在尝试做的事情:在设属性网格——我知道如何修改这些动词:我的问题只与智能标记操作列表有关。)
我想做的是用我自己的一些项目修改 TableLayoutPanel 控件的设计时智能标记操作列表。
不幸的是,似乎要做到这一点,您必须将控件与自定义设计器相关联。但是,我不想使用自定义设计器或派生自 ControlDesigner 的设计器。我发现当我这样做时,我失去了 TableLayoutPanel 控件提供的所有设计器功能——例如查看新行、新列以及能够将控件拖放到其客户端表面上。我必须保留 TableLayoutPanel 的此类视觉设计时功能。
如果我使用 Designer 属性将 TableLayoutPanelDesigner 类指定为设计器,那么我就不走运了,因为该类被标记为内部 (https://referencesource.microsoft.com/#System.Design/System/Windows/Forms/Design/TableLayoutPanelDesigner.cs)。
如何利用 WinForm TableLayoutPanel 控件的现有设计器同时自定义其智能标记的操作列表?当然这必须可以使用反射访问(但我不知道如何)。
最佳答案
TableLayoutPanelDesiner
是内部的并且依赖于其他内部类,您不能从它继承。此外,从头开始为 TableLayoutPanel
创建一个新的控件设计器也不是一个好主意,因为您将失去所有当前的设计器功能。
一个非常好的技巧 是在设计时找到设计器并操纵设计器。看看 Do something! 和 Back Color 新项目:
为此,您可以在设计时找到 TableLayoutPanel
的设计器并对其进行操作。 OnHandleCreated
方法中的一个好点。您可以从控件的 Site
获取 IDesignerHost
的实例,然后获取设计器。
然后您可以获得控件的当前操作列表并创建一个包含所有这些操作项的新操作列表,并向列表中添加一些新的操作项。
我的表格布局面板
using System;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
public class MyTableLayoutPanel : TableLayoutPanel
{
private IDesignerHost designerHost;
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (DesignMode && Site != null)
{
designerHost = Site.GetService(typeof(IDesignerHost)) as IDesignerHost;
if (designerHost != null)
{
var designer = (ControlDesigner)designerHost.GetDesigner(this);
if (designer != null)
{
var actions = designer.ActionLists[0];
designer.ActionLists.Clear();
designer.ActionLists.Add(
new MyTableLayoutPanelActionList(designer, actions));
}
}
}
}
}
MyTableLayoutPanelActionList
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows;
using System.Windows.Forms.Design;
public class MyTableLayoutPanelActionList : DesignerActionList
{
MyTableLayoutPanel control;
ControlDesigner designer;
DesignerActionList actionList;
public MyTableLayoutPanelActionList(ControlDesigner designer,
DesignerActionList actionList) : base(designer.Component)
{
this.designer = designer;
this.actionList = actionList;
control = (MyTableLayoutPanel)designer.Control;
}
public Color BackColor
{
get { return control.BackColor; }
set
{
TypeDescriptor.GetProperties(Component)["BackColor"]
.SetValue(Component, value);
}
}
private void DoSomething()
{
MessageBox.Show("My Custom Verb added!");
}
public override DesignerActionItemCollection GetSortedActionItems()
{
var items = new DesignerActionItemCollection();
foreach (DesignerActionItem item in actionList.GetSortedActionItems())
items.Add(item);
var category = "New Actions";
items.Add(new DesignerActionMethodItem(this, "DoSomething",
"Do something!", category, true));
items.Add(new DesignerActionPropertyItem("BackColor", "Back Color",
category));
return items;
}
}
关于c# - WinForms Designer 和 TableLayoutPanel SmartTag 自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52215265/
我有一个名为 tlpMaster 的 tableLayoutPanel。它有 4 列和 8 行。在 3 列和每一行中,它都有另一个 tableLayoutPanel。所以这就是 3 个内部的。在那些里
我有一些 TableLayoutPanel,其中第一个“层”有 1 列和 10 行,其中一些行包含 UserControl 或另一个具有 2 或 3 列和一些行的 TableLayoutPanel。其
我正在使用 TableLayoutPanel 将客户区域分为 3 行(只有 1 列)。顶排和底排设计为固定高度;它们将包含一个页眉和一个页脚,最初每个页脚都包含一个包含静态文本的子标签控件(只是开始)
有了 TableLayoutPanel 的所有属性,我不知道为什么这不能简单。 我有一个包含两列的 tableLayoutPanel。我试图在第一列内放置一个标签以将其用作标题。我想将它放置在相对于该
我有一个 WinForms 应用程序,它正在从 BackgroundWorker 更新 TableLayoutPanel。根据设备输入是打开 (1) 还是关闭 (0),颜色和一些文本会相应地更改。 t
如果内容高于面板本身,我希望能够在 TableLayoutPanel 内滚动。 我试过: 将 AutoScroll 设置为 true(添加 unnecessary horizontal scrollb
我有一个 TableLayoutPanel,它具有由用户确定的动态数量的列和行。我希望里面的按钮是方形的并且大小相同,但是每当我使用循环来设置列/行样式时,它们永远不会变成我想要的大小。 如何获取列/
在我的应用程序中,我有一个名为“Dashboard.cs”的 WindowsForm,其中有一个名为 dashboardTableItemsWrapper 的 TableLayoutPanel。现在,
我有几个 TableLayoutPanel,每个都在两列中显示一类名称/值信息 - 一列带有信息标签,一列带有数据标签。 在每一个中,我都将第一列设置为自动调整大小并右对齐所有标签,效果很好。但是,它
我有一个 TableLayoutPanel,它在运行时使用文本文件填充行(从文本文件中获取每一行,并将其放入新行中包含的单元格中)。代码看起来像这样: public static string Url
我想在 GUI 的固定区域中的 TableLayoutPanel 中动态添加行。所以,如果记录数量增加,那么我想要一个垂直滚动条来帮助用户查看更多记录。为此,我设置了 PropertyAutoScro
我有一个 TableLayoutPanel,我可以向其中动态添加行。 每行都有一个绝对大小。 我将 AutoScroll 设置为“true”,但是当我添加超出 TableLayoutPanel 显示范
我有一个 TableLayoutPanel,每次我将标签放入其中一个单元格时,它都会捕捉到左上角。我怎样才能到达它而不是这样做或改变它捕捉的位置。 此外,是否可以更改特定单元格的背景颜色? 谢谢! 最
我正在创建一个表格布局面板来显示字典中的值,但表格布局面板一直将我放入单元格中的标签控件截断为 14 个字符。我试图摆弄我的表格布局面板的 ColumnStyles,但没有任何选项会使 Label 控
我在 C#(窗体)中使用 TableLayoutPanel。我的表格很大,有 33 列和 8 行。所有单元格都包含 Label 对象。 我已经通过创建一个新的子类设置了我的 TableLayoutPa
是否可以让 System.Windows.Forms.TableLayoutPanel 在移动到下一列之前填充一列?无论我如何设置 RowCount、ColumnCount 和 GrowStyle,表
我正在使用 TableLayoutPanel 和 anchor 属性来制作一个独立于屏幕分辨率或窗体大小调整而看起来不错的窗口应用程序。我提到了 this article为了设计winform。 我的
我向我的用户控件添加了一个 tableLayoutPanel。 It is not docked or anchored. It has 4 columns and 4 rows. The items
我有 TableLayoutPanel 用于通过 AutoScroll = true 动态创建控件。当我添加新控件时它工作正常。但是当我删除并且所有控件都可见时,垂直滚动是可见的。这里有一些截图: 预
我可能没有使用我想要的正确控件。我正在用控件填充表格,我希望每一列的大小自动适应其中包含的控件。例如,一列文本框将比一列复选框宽。由于不同操作系统、不同 DPI、不同字体等的复杂性,我不想摆弄测量,如
我是一名优秀的程序员,十分优秀!