개발 노트

폼닫을시 설정 저장하고 재실행하면 저장된값 가져오기 본문

프로그래밍/C#

폼닫을시 설정 저장하고 재실행하면 저장된값 가져오기

알 수 없는 사용자 2022. 3. 4. 17:25

폼닫기 이벤트 지정

	/// <summary>

		/// 폼 닫기 이벤트 핸들러 선언

		/// </summary>

		/// <param name="sender"></param>

		/// <param name="e"></param>

		public void Form_Closing(object sender, FormClosedEventArgs e)
		{
			propertyCloseMethod();
		}

 

닫기이벤트지정

		private void propertyCloseMethod()
		{
			Properties.Settings.Default.host = textBoxHost.Text;
			Properties.Settings.Default.port = textBoxPort.Text;
			Properties.Settings.Default.qos = comboBoxQos.Text;
			Properties.Settings.Default.topicSub = textBoxSubTopic.Text;
			Properties.Settings.Default.topicPub1 = textBoxPubTopic.Text;
			Properties.Settings.Default.topicPm1 = textBoxMessage.Text;
			Properties.Settings.Default.topicPub2 = textBoxPT2.Text;
			Properties.Settings.Default.topicPm2 = textBoxM2.Text;
			Properties.Settings.Default.topicPub3 = textBoxPT3.Text;
			Properties.Settings.Default.topicPm3 = textBoxM3.Text;
			Properties.Settings.Default.topicPub4 = textBoxPT4.Text;
			Properties.Settings.Default.topicPm4 = textBoxM4.Text;
			Properties.Settings.Default.red = textBoxRed.Text;
			Properties.Settings.Default.green = textBoxGreen.Text;
			Properties.Settings.Default.yellow = textBoxYellow.Text;
			Properties.Settings.Default.gray = textBoxGray.Text;
			Properties.Settings.Default.navy = textBoxNavy.Text;
			Properties.Settings.Default.purple = textBoxPurple.Text;
			Properties.Settings.Default.lime = textBoxLime.Text;
			Properties.Settings.Default.Save(); ;
		}

폼로드시 저장된값 불러오기 지정

		private void propertyCloseMethod()
		{
			Properties.Settings.Default.host = textBoxHost.Text;
			Properties.Settings.Default.port = textBoxPort.Text;
			Properties.Settings.Default.qos = comboBoxQos.Text;
			Properties.Settings.Default.topicSub = textBoxSubTopic.Text;
			Properties.Settings.Default.topicPub1 = textBoxPubTopic.Text;
			Properties.Settings.Default.topicPm1 = textBoxMessage.Text;
			Properties.Settings.Default.topicPub2 = textBoxPT2.Text;
			Properties.Settings.Default.topicPm2 = textBoxM2.Text;
			Properties.Settings.Default.topicPub3 = textBoxPT3.Text;
			Properties.Settings.Default.topicPm3 = textBoxM3.Text;
			Properties.Settings.Default.topicPub4 = textBoxPT4.Text;
			Properties.Settings.Default.topicPm4 = textBoxM4.Text;
			Properties.Settings.Default.red = textBoxRed.Text;
			Properties.Settings.Default.green = textBoxGreen.Text;
			Properties.Settings.Default.yellow = textBoxYellow.Text;
			Properties.Settings.Default.gray = textBoxGray.Text;
			Properties.Settings.Default.navy = textBoxNavy.Text;
			Properties.Settings.Default.purple = textBoxPurple.Text;
			Properties.Settings.Default.lime = textBoxLime.Text;
			Properties.Settings.Default.Save(); ;
		}

폼로드에

propertyload()추가

 

 

참고링크

https://afsdzvcx123.tistory.com/entry/C-%EC%9C%88%ED%8F%BC-%EC%9C%88%ED%8F%BC-%ED%8F%BC-%EB%8B%AB%EA%B8%B0-%EC%9D%B4%EB%B2%A4%ED%8A%B8-Form-Closed-Event-%EC%84%A0%EC%96%B8%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95

https://diy-dev-design.tistory.com/137

https://generaljju.tistory.com/131

'프로그래밍 > C#' 카테고리의 다른 글

C# ini 저장해서 재실행시 불러오기  (0) 2022.03.07
mosquitto conf  (0) 2022.03.07
C# 폴더열기  (0) 2022.03.04
데이터그리드뷰 특정값 열 색상채우기  (0) 2022.03.04
C# 데이터그리드뷰 focus 맞추기  (0) 2022.03.04