John Evans Solachuk
John Evans Solachuk

Reputation: 2085

.NET - Replace existing control with custom control while maintaining the original controls' Properties/Events

In a windows form, I want to replace all this forms' buttons with a custom button, CustomNamespace.controls.customButton, which as you guess, extends the Button class from system.windows.controls.button.

Currently, the only proper way I can think of doing it is deleting the original button, adding in the customized one and manually changing the properties one-by-one. However, this becomes a hassle when you need to replace more than one button with different properties or events.

Another way that I can think of doing while keeping its properties intact is replacing ... = new system.windows.controls.button() to ... = new CustomNamespace.controls.customButton() in the .designer.cs file. As much as possible, I would prefer not to go that way unless there are no other better solutions.

Upvotes: 2

Views: 636

Answers (1)

John Evans Solachuk
John Evans Solachuk

Reputation: 2085

After advised by @Peter Duniho, the best option I have is to just find and replace the existing component in .desginer.cs files because it will have the same effect of deleting the existing and adding the customized component.

Thanks also to others in the questions' comments section above for their input.

Upvotes: 2

Related Questions