There is some control:
public partial class UserControl1 : UserControl { public Button buttonExit; public UserControl1() { InitializeComponent(); Controls.Add(buttonExit = new Button() { Text = "Exit" }); buttonExit.Click += (s, e) => { (s as Control).FindForm().DialogResult = DialogResult.Cancel; }; } protected override void OnParentChanged(EventArgs e) { base.OnParentChanged(e); Form f = FindForm(); if (f!= null) f.CancelButton = buttonExit; } } Those. the form must receive buttonExit as a close button by Esc
In the designer I throw UserControl1 on the form. CancelButton of this form still remains (none)
Tell me where to dig