gpt4 book ai didi

.net - 自定义 Winforms 控件中的基线对齐线

转载 作者:行者123 更新时间:2023-12-02 04:23:58 25 4
gpt4 key购买 nike

我有一个带有文本框的自定义用户控件,我想在自定义控件之外公开(文本框中文本的)对齐线的基线。我知道您创建了一个设计器(继承自 ControlDesigner)并重写 SnapLines 以访问对齐线,但我想知道如何获取我通过自定义用户控件公开的控件的文本基线。

最佳答案

作为 Miral 答案的更新.. 对于正在寻找如何执行此操作的新人,这里有一些“缺失的步骤”。 :) 除了更改一些值以引用将要修改的 UserControl 之外,上面的 C# 代码几乎已“插入”就绪。

可能需要的引用资料:
系统设计 (@robyaw)

所需用途:

using System.Windows.Forms.Design;
using System.Windows.Forms.Design.Behavior;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;

在您的用户控件上,您需要以下属性:

[Designer(typeof(MyCustomDesigner))]

然后您需要一个“设计器”类来覆盖 SnapLines:

private class MyCustomerDesigner : ControlDesigner {
public override IList SnapLines {
get {
/* Code from above */
IList snapLines = base.SnapLines;

// *** This will need to be modified to match your user control
MyControl control = Control as MyControl;
if (control == null) { return snapLines; }

// *** This will need to be modified to match the item in your user control
// This is the control in your UC that you want SnapLines for the entire UC
IDesigner designer = TypeDescriptor.CreateDesigner(
control.textBoxValue, typeof(IDesigner));
if (designer == null) { return snapLines; }

// *** This will need to be modified to match the item in your user control
designer.Initialize(control.textBoxValue);

using (designer)
{
ControlDesigner boxDesigner = designer as ControlDesigner;
if (boxDesigner == null) { return snapLines; }

foreach (SnapLine line in boxDesigner.SnapLines)
{
if (line.SnapLineType == SnapLineType.Baseline)
{
// *** This will need to be modified to match the item in your user control
snapLines.Add(new SnapLine(SnapLineType.Baseline,
line.Offset + control.textBoxValue.Top,
line.Filter, line.Priority));
break;
}
}
}

return snapLines;
}

}
}
}

关于.net - 自定义 Winforms 控件中的基线对齐线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/93541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com