문제

멀티 라인 문자열에 대한 내장 편집기가 있습니까? PropertyGrid.

도움이 되었습니까?

해결책

나는 그것을 발견했다 System.Design.dll 가지다 System.ComponentModel.Design.MultilineStringEditor 다음과 같이 사용할 수 있습니다.

public class Stuff
{
    [Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
    public string MultiLineProperty { get; set; }
}

다른 팁

아니요, Modal UI 유형 편집기를 만들어야합니다. UityPeeditor에서 상속되는 클래스를 만들어야합니다. 이것은 기본적으로 편집중인 속성의 오른쪽에있는 Ellipsis 버튼을 클릭하면 표시되는 양식입니다.

내가 찾은 유일한 단점은 특정 문자열 속성을 특정 속성으로 장식해야한다는 것입니다. 내가 그렇게해야했던 지 오래되었습니다. Chris Sells의 책에서 "C#의 Windows Forms Programming"이라는 책 에서이 정보를 얻었습니다.

상업용 부동산 그리드가 호출됩니다 Smart PropertyGrid.net VisualHint에 의해.

예. 나는 그것이 어떻게 호출되는지 기억하지 못하지만 Combobox와 같은 항목 속성 편집기를보십시오.

편집 : @fryguybob의 기준으로 combobox.items는 system.windows.forms.design.listControlStringCollectionEditor를 사용합니다.

Property Grid에서 멀티 라인 지원을 받으려면 사용자 정의 편집기를 작성해야합니다.

다음은 구현 된 고객 텍스트 편집기 클래스입니다 uitypeeditor

public class MultiLineTextEditor : UITypeEditor
{
    private IWindowsFormsEditorService _editorService;

    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.DropDown;
    }

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        _editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

        TextBox textEditorBox = new TextBox();
        textEditorBox.Multiline = true;
        textEditorBox.ScrollBars = ScrollBars.Vertical;
        textEditorBox.Width = 250;
        textEditorBox.Height = 150;
        textEditorBox.BorderStyle = BorderStyle.None;
        textEditorBox.AcceptsReturn = true;
        textEditorBox.Text = value as string;

        _editorService.DropDownControl(textEditorBox);

        return textEditorBox.Text;
    }
}

사용자 정의 속성 그리드를 작성 하고이 편집기 속성을 속성에 적용하십시오.

class CustomPropertyGrid
{
    private string multiLineStr = string.Empty;

    [Editor(typeof(MultiLineTextEditor), typeof(UITypeEditor))]
    public string MultiLineStr
    {
        get { return multiLineStr; }
        set { multiLineStr = value; }
    }
}

기본 형태 로이 개체를 할당하십시오

 propertyGrid1.SelectedObject = new CustomPropertyGrid();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top