어떤 마술은 무엇입니까? +1! 마우스와 키보드를 잡는 다른 솔루션을 보았습니다. 이것은 지금까지 가장 쉽고 쉬운 해결책입니다. 다음은 상속 된 읽기 전용 컨트롤의 스 니펫입니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
namespace MyCustomControls
{
public sealed class ReadOnlyPropertyGrid : System.Windows.Forms.PropertyGrid
{
#region Non-greyed read only support
public ReadOnlyPropertyGrid()
{
this.ViewForeColor = Color.FromArgb(1, 0, 0);
}
//---
private bool _readOnly;
public bool ReadOnly
{
get { return _readOnly; }
set
{
_readOnly = value;
this.SetObjectAsReadOnly(this.SelectedObject, _readOnly);
}
}
//---
protected override void OnSelectedObjectsChanged(EventArgs e)
{
this.SetObjectAsReadOnly(this.SelectedObject, this._readOnly);
base.OnSelectedObjectsChanged(e);
}
//---
private void SetObjectAsReadOnly(object selectedObject, bool isReadOnly)
{
if (this.SelectedObject != null)
{
TypeDescriptor.AddAttributes(this.SelectedObject, new Attribute[] { new ReadOnlyAttribute(_readOnly) });
this.Refresh();
}
}
//---
#endregion
}
}
+1. 이 작품! – Ben
대체 어떻게 작동합니까? 그것은 hackish이지만, 원하는 결과를 주었다. 이것이 실패하고 어떻게 될 것인가? –