I need to have all the new forms created based on a custom config that determines how many forms are needed to have the same features (icon and custom menu actions). I get CS1540 error on form.WndProc += (ref Message m) => line.
<code> private void SetupSystemMenu(Form form)
{
// Add your icon to the form (if applicable)
form.Icon = this.Icon;
// Hook into the form's HandleCreated event to set up the system menu
form.HandleCreated += (sender, e) =>
{
IntPtr systemMenuHandle = GetSystemMenu(form.Handle, false);
// Add a separator and then our custom items
AppendMenu(systemMenuHandle, MF_SEPARATOR, 0, string.Empty);
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_CUSTOM_ITEM_ID, "Erase Config");
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_PAUSE_TIMER_ID, "Pause Timer");
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_REFRESH_NOW_ID, "Refresh Now");
};
// Hook into the WndProc of the form to handle menu item clicks
form.WndProc += (ref Message m) =>
{
if (m.Msg == WM_SYSCOMMAND)
{
switch (m.WParam.ToInt32())
{
case SYSMENU_CUSTOM_ITEM_ID:
EraseConfig();
break;
case SYSMENU_PAUSE_TIMER_ID:
ToggleTimerPause();
break;
case SYSMENU_REFRESH_NOW_ID:
Program.refreshRequested = true;
refreshTimer.Stop();
form.Close();
break;
}
}
form.WndProc(ref m);
};
}
</code>
<code> private void SetupSystemMenu(Form form)
{
// Add your icon to the form (if applicable)
form.Icon = this.Icon;
// Hook into the form's HandleCreated event to set up the system menu
form.HandleCreated += (sender, e) =>
{
IntPtr systemMenuHandle = GetSystemMenu(form.Handle, false);
// Add a separator and then our custom items
AppendMenu(systemMenuHandle, MF_SEPARATOR, 0, string.Empty);
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_CUSTOM_ITEM_ID, "Erase Config");
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_PAUSE_TIMER_ID, "Pause Timer");
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_REFRESH_NOW_ID, "Refresh Now");
};
// Hook into the WndProc of the form to handle menu item clicks
form.WndProc += (ref Message m) =>
{
if (m.Msg == WM_SYSCOMMAND)
{
switch (m.WParam.ToInt32())
{
case SYSMENU_CUSTOM_ITEM_ID:
EraseConfig();
break;
case SYSMENU_PAUSE_TIMER_ID:
ToggleTimerPause();
break;
case SYSMENU_REFRESH_NOW_ID:
Program.refreshRequested = true;
refreshTimer.Stop();
form.Close();
break;
}
}
form.WndProc(ref m);
};
}
</code>
private void SetupSystemMenu(Form form)
{
// Add your icon to the form (if applicable)
form.Icon = this.Icon;
// Hook into the form's HandleCreated event to set up the system menu
form.HandleCreated += (sender, e) =>
{
IntPtr systemMenuHandle = GetSystemMenu(form.Handle, false);
// Add a separator and then our custom items
AppendMenu(systemMenuHandle, MF_SEPARATOR, 0, string.Empty);
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_CUSTOM_ITEM_ID, "Erase Config");
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_PAUSE_TIMER_ID, "Pause Timer");
AppendMenu(systemMenuHandle, MF_STRING, SYSMENU_REFRESH_NOW_ID, "Refresh Now");
};
// Hook into the WndProc of the form to handle menu item clicks
form.WndProc += (ref Message m) =>
{
if (m.Msg == WM_SYSCOMMAND)
{
switch (m.WParam.ToInt32())
{
case SYSMENU_CUSTOM_ITEM_ID:
EraseConfig();
break;
case SYSMENU_PAUSE_TIMER_ID:
ToggleTimerPause();
break;
case SYSMENU_REFRESH_NOW_ID:
Program.refreshRequested = true;
refreshTimer.Stop();
form.Close();
break;
}
}
form.WndProc(ref m);
};
}
3