gpt4 book ai didi

c# - 将另一个下拉按钮添加到具有相同样式行为的 devexpress PopupContainerEdit

转载 作者:行者123 更新时间:2023-11-30 21:54:16 26 4
gpt4 key购买 nike

我们有自定义的 PopupContainerEdit 继承自 DevExpress 的 PopupContainerEdit。我们的自定义功能之一是另一个下拉按钮(EditorButton with kind = ButtonPredefines.Glyph),除了打开不同的 PopupContainerControl 外,它的行为类似于默认按钮>。除了按钮的样式着色外,一切都按预期工作。该按钮的作用类似于默认按钮 - 这意味着当下拉菜单可见/隐藏时,它不支持状态着色(选中/未选中)。我找不到 EditorButton 的任何自定义绘制事件/方法。

是否有可能实现这种行为?如果是,怎么办?

@编辑

Example

上述情况的简单例子。

  • 默认 PopupContainerEdit 看起来像图像 A。当您单击按钮(类似三角形),下拉菜单显示并且按钮进入选中状态状态。
  • 我们的 PopupContainerEdit(继承自默认值)看起来像B.
  • C、D 是鼠标悬停按钮时的着色示例。<​​/li>
  • E 是默认按钮的选中状态着色(它的工作原理是DevExpress 的设计)。
  • F 是我们的按钮行为 - 就像普通按钮一样。
  • G 是我们想要的 - 为我们的按钮勾选状态着色

我们创建自定义按钮的方法:

string TheToolTipText = "The text";
string OurButtonTag = "TheButton";
Image TheIcon = new Image(); // just example ...

EditorButton customButton = new EditorButton();
customButton.Width = 16;
customButton.Image = TheIcon;
customButton.ToolTip = TheToolTipText;
customButton.Tag = OurButtonTag;
customButton.Kind = ButtonPredefines.Glyph;
this.Properties.Buttons.Add(customButton);

老实说,没有什么可以展示的了。我们不知道有任何自定义 Draw 事件或类似事件。

最佳答案

RepositoryItemPopupContainerEdit 中有两个属性负责此行为。第一个是 RepositoryItemPopupBase.ActionButtonIndex属性(property)。指定哪个编辑器按钮将打开编辑器的下拉窗口是有值(value)的。第二个是RepositoryItemPopupContainerEdit.PopupControl它将控件设置为在弹出窗口中显示。因此,通过操纵这两个属性,您可以实现所需的行为。

例子如下:

<强>0。 RepositoryItemPopupContainerEdit 后代

因为你需要显示两个不同的PopupContainerControl您可以在自定义 RepositoryItem 中为每个控件创建其他属性。

public class RepositoryItemCustomEdit1 : RepositoryItemPopupContainerEdit
{
#region Some default stuff for custom repository item (constructors, registration, etc).
static RepositoryItemCustomEdit1() { RegisterCustomEdit1(); }
public const string CustomEditName = "CustomEdit1";
public RepositoryItemCustomEdit1() { }
public override string EditorTypeName { get { return CustomEditName; } }
public static void RegisterCustomEdit1()
{
Image img = null;
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(
CustomEditName,
typeof(CustomEdit1),
typeof(RepositoryItemCustomEdit1),
//For v13.2 you need to use custom ViewInfo class. So, here is CustomEdit1ViewInfo.
//For v15.1 you can use the base PopupContainerEditViewInfo.
typeof(CustomEdit1ViewInfo),
new ButtonEditPainter(),
true,
img));
}
#endregion

#region Hide base PopupContainerControl properties in designer.
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override PopupContainerControl PopupControl
{
get { return base.PopupControl; }
set { base.PopupControl = value; }
}

[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override int ActionButtonIndex
{
get { return base.ActionButtonIndex; }
set { base.ActionButtonIndex = value; }
}
#region

#region First PopupContainerControl properties
public int DefaultActionButtonIndex { get; set; }
public PopupContainerControl DefaultPopupControl { get; set; }
#endregion

#region Another PopupContainerControl properties
public int DifferentActionButtonIndex { get; set; }
public PopupContainerControl DifferentPopupControl { get; set; }
#endregion

public override void Assign(RepositoryItem item)
{
BeginUpdate();
try
{
base.Assign(item);
RepositoryItemCustomEdit1 source = item as RepositoryItemCustomEdit1;
if (source == null) return;

DefaultActionButtonIndex = source.DefaultActionButtonIndex;
DefaultPopupControl = source.DefaultPopupControl;

DifferentPopupControl = source.DifferentPopupControl;
DifferentActionButtonIndex = source.DifferentActionButtonIndex;
}
finally
{
EndUpdate();
}
}
}

您可以在设计器中看到新属性:
Designer

<强>1。 PopupContainerEdit 后代

现在您可以在自定义 Edit 类中使用此属性。

public class CustomEdit1 : PopupContainerEdit
{
#region Some default stuff for custom edit (constructors, registration, etc).
static CustomEdit1() { RepositoryItemCustomEdit1.RegisterCustomEdit1(); }
public CustomEdit1() { }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemCustomEdit1 Properties { get { return base.Properties as RepositoryItemCustomEdit1; } }
public override string EditorTypeName { get { return RepositoryItemCustomEdit1.CustomEditName; } }
#endregion

protected override bool IsActionButton(EditorButtonObjectInfoArgs buttonInfo)
{
int buttonIndex = Properties.Buttons.IndexOf(buttonInfo.Button);

if (buttonIndex == Properties.DefaultActionButtonIndex ||
buttonIndex == Properties.DifferentActionButtonIndex)
{
//Set the Properties.ActionButtonIndex value according to which button is pressed:
Properties.ActionButtonIndex = buttonIndex;

//Set the Properties.PopupControl according to which button is pressed:
if (buttonIndex == Properties.DefaultActionButtonIndex)
Properties.PopupControl = Properties.DefaultPopupControl;
else
Properties.PopupControl = Properties.DifferentPopupControl;

return true;
}

return false;
}
}

<强>2。 PopupContainerEditViewInfo 后代

对于 v13.2,您需要为您的编辑器使用自定义 ViewInfo 类:

public class CustomEdit1ViewInfo : PopupContainerEditViewInfo
{
public CustomEdit1ViewInfo(RepositoryItem item) : base(item) { }

public new RepositoryItemPopupBase Item { get { return base.Item as RepositoryItemCustomEdit1; } }

//Show the pressed state when button is pressed or when popup is open.
protected override bool IsButtonPressed(EditorButtonObjectInfoArgs info)
{
var hitObject = PressedInfo.HitObject as EditorButtonObjectInfoArgs;

return
(hitObject != null && hitObject.Button == info.Button) ||
(IsPopupOpen && Item.ActionButtonIndex == info.Button.Index);
}
}

结果

在结果中你会得到这样的东西:

DefaultPopupControlDifferentPopupControl

关于c# - 将另一个下拉按钮添加到具有相同样式行为的 devexpress PopupContainerEdit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33214517/

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