您的位置:首页 > 大数据 > 人工智能

DevExpress PopupContainerEdit 可编辑 多行文本

2014-10-16 10:05 267 查看
先上效果图:



1. 可编辑:设置Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;

2. 多行显示,需要重写PopupContainerEdit控件:

public partial class YnPopupModuleEdit : PopupContainerEdit
{
static YnPopupModuleEdit() { RepositoryItemCustomContainerEdit.RegisterCustomEdit(); }

public YnPopupModuleEdit()
{
InitializeComponent();
}
protected override bool AcceptsReturn { get { return true; } }
protected override bool AcceptsTab { get { return true; } }
//Return the unique name
public override string EditorTypeName { get { return RepositoryItemCustomContainerEdit.CustomEditName; } }

//Override the Properties property
//Simply type-cast the object to the custom repository item type
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemCustomContainerEdit Properties
{
get { return base.Properties as RepositoryItemCustomContainerEdit; }
}

protected override void UpdateMaskBox(bool always)
{
base.UpdateMaskBox(always);
if (MaskBox == null) return;
MaskBox.Multiline = true;
MaskBox.WordWrap = true;
MaskBox.ScrollBars = System.Windows.Forms.ScrollBars.None;
}
}

//The attribute that points to the registration method
[UserRepositoryItem("RegisterCustomEdit")]
public class RepositoryItemCustomContainerEdit : RepositoryItemPopupContainerEdit
{

//The static constructor which calls the registration method
//static RepositoryItemCustomComboBoxEdit() { RegisterCustomEdit(); }

//Initialize new properties
public RepositoryItemCustomContainerEdit()
{
}

//The unique name for the custom editor
public const string CustomEditName = "CustomComboBoxEdit";

//Return the unique name
public override string EditorTypeName { get { return CustomEditName; } }

//Register the editor
public static void RegisterCustomEdit()
{
//Icon representing the editor within a container editor's Designer
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(
CustomEditName, typeof(YnPopupModuleEdit),
typeof(RepositoryItemCustomContainerEdit), typeof(CustomContainerViewInfo),
new ButtonEditPainter(), true, null, typeof(DevExpress.Accessibility.PopupEditAccessible)
));
}

//Override the Assign method
public override void Assign(RepositoryItem item)
{
BeginUpdate();
try
{
base.Assign(item);
}
finally
{
EndUpdate();
}
}

protected override bool NeededKeysContains(Keys key)
{
if (key == Keys.Enter)
return true;
if (key == Keys.Tab)
return true;
if (key == Keys.Up)
return true;
if (key == Keys.Down)
return true;
return base.NeededKeysContains(key);
}
public override bool IsNeededKey(Keys keyData)
{
if (keyData == (Keys.Enter | Keys.Control)) return false;
bool res = base.IsNeededKey(keyData);
if (res) return true;
if (keyData == Keys.PageUp || keyData == Keys.PageDown) return true;
return false;
}

protected override bool UseMaskBox { get { return false; } }

}

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

protected override void CalcContentRect(Rectangle bounds) {
base.CalcContentRect(bounds);
this.fMaskBoxRect = ContentRect;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: