Место общения программистов C#
Anonymous
Как определить по коду закрытие приложения с помощью кнопки остановки красного квадрата в Visual Studio?
Сообщение
Anonymous » 22 окт 2025, 21:09
с помощью c£ winforms .net 8.0
я отметил на этом снимке экрана красную квадратную кнопку зеленым кружком.
код.
Код: Выделить всё
public Form1()
{
InitializeComponent();
InitializeToolTips();
EnableFormDragging();
InitializeTimer();
AddTitlePanel();
SetReadOnlyTextboxes();
ValidateRecordingReady();
LoadUserSettings();
AppDomain.CurrentDomain.ProcessExit += (s, e) =>
{
SaveSettingsOnExit();
};
}
private void LoadUserSettings()
{
ffmpegTextbox.Text = Properties.Settings.Default.FfmpegFolder;
phiolaTextbox.Text = Properties.Settings.Default.PhiolaFolder;
outputFolderTextBox.Text = Properties.Settings.Default.OutputFolder;
musicFileTextBox.Text = Properties.Settings.Default.MusicFile;
chkAddMusic.Checked = Properties.Settings.Default.AddMusic;
toggleButton2.Checked = Properties.Settings.Default.MicEnabled;
toggleButtonSpeakers.Checked = Properties.Settings.Default.SpeakersEnabled;
toggleButton3.Checked = Properties.Settings.Default.MouseEnabled;
// Update labels according to loaded toggles
labelMicOnOff.Text = toggleButton2.Checked ? "ON" : "OFF";
labelSpeakersOnOff.Text = toggleButtonSpeakers.Checked ? "ON" : "OFF";
labelMouseOnOff.Text = toggleButton3.Checked ? "ON" : "OFF";
// Update static fields used elsewhere
ffmpegFolder = ffmpegTextbox.Text;
phiolaFolder = phiolaTextbox.Text;
outputFolder = outputFolderTextBox.Text;
}
private void SaveSettingsOnExit()
{
Properties.Settings.Default.Save();
Console.WriteLine("Settings saved on process exit.");
}
Я пытался использовать это в конструкторе form1:
Код: Выделить всё
AppDomain.CurrentDomain.ProcessExit += (s, e) =>
{
SaveSettingsOnExit();
};
но он никогда не достигает метода SaveSettingsOnExit(). я использовал точку останова.
Подробнее здесь:
https://stackoverflow.com/questions/797 ... re-stop-bu
1761156543
Anonymous
с помощью c£ winforms .net 8.0 я отметил на этом снимке экрана красную квадратную кнопку зеленым кружком. [img]https://i.sstatic.net/TeIAGrJj.jpg[/img] код. [code]public Form1() { InitializeComponent(); InitializeToolTips(); EnableFormDragging(); InitializeTimer(); AddTitlePanel(); SetReadOnlyTextboxes(); ValidateRecordingReady(); LoadUserSettings(); AppDomain.CurrentDomain.ProcessExit += (s, e) => { SaveSettingsOnExit(); }; } private void LoadUserSettings() { ffmpegTextbox.Text = Properties.Settings.Default.FfmpegFolder; phiolaTextbox.Text = Properties.Settings.Default.PhiolaFolder; outputFolderTextBox.Text = Properties.Settings.Default.OutputFolder; musicFileTextBox.Text = Properties.Settings.Default.MusicFile; chkAddMusic.Checked = Properties.Settings.Default.AddMusic; toggleButton2.Checked = Properties.Settings.Default.MicEnabled; toggleButtonSpeakers.Checked = Properties.Settings.Default.SpeakersEnabled; toggleButton3.Checked = Properties.Settings.Default.MouseEnabled; // Update labels according to loaded toggles labelMicOnOff.Text = toggleButton2.Checked ? "ON" : "OFF"; labelSpeakersOnOff.Text = toggleButtonSpeakers.Checked ? "ON" : "OFF"; labelMouseOnOff.Text = toggleButton3.Checked ? "ON" : "OFF"; // Update static fields used elsewhere ffmpegFolder = ffmpegTextbox.Text; phiolaFolder = phiolaTextbox.Text; outputFolder = outputFolderTextBox.Text; } private void SaveSettingsOnExit() { Properties.Settings.Default.Save(); Console.WriteLine("Settings saved on process exit."); } [/code] Я пытался использовать это в конструкторе form1: [code]AppDomain.CurrentDomain.ProcessExit += (s, e) => { SaveSettingsOnExit(); }; [/code] но он никогда не достигает метода SaveSettingsOnExit(). я использовал точку останова. Подробнее здесь: [url]https://stackoverflow.com/questions/79797111/how-to-detect-by-code-when-shutting-down-application-with-the-red-square-stop-bu[/url]