I was recently asked how to remove the Editor Parts (Appearance, Layout, Advanced, etc) from custom Web Parts.
One strategy is to implement your own Editor Part and mark the built-in ones as not Visible.
Firstly, we need to create our Editor Part class:
class MyEditorPart : EditorPart { protected override void CreateChildControls() {
// this line hides the default EditorParts Parent.Controls[2].Visible = false; base.CreateChildControls(); } public override bool ApplyChanges() { // do stuff here return true; } public override void SyncChanges() { // do stuff here } }
And here’s how we invoke our Editor Part from our Web Part:
public class MyWebPart : WebPart { public override EditorPartCollection CreateEditorParts() { ArrayList aryParts = new ArrayList(); MyEditorPart myEditor = new MyEditorPart(); myEditor.ID = this.ID + "_myEditorPart"; aryParts.Add(myEditor); return new EditorPartCollection(aryParts); } // do more stuff here... }
Hopefully, when you edit the Web Part it should look something like this:
The next step would be to extend CreateChildControls(), ApplyChanges() and SyncChanges() to get and set any properties you’d like to allow users to edit.