public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OnClose(this);
}
public event EventHandler Close;
protected virtual void OnClose(object s)
{
Close?.Invoke(s, new EventArgs());
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
userControl11.Close += UserControl11_Close;
}
private void UserControl11_Close(object sender, EventArgs e)
{
flowLayoutPanel1.Controls.Remove(sender as Control);
}
}
c:\Temp>cl m.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27043 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
m.cpp
Microsoft (R) Incremental Linker Version 14.16.27043.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:m.exe
m.obj
c:\Temp>m
0.333333
c:\Temp>