본문 바로가기
  • Tried. Failed. Logged.
728x90

C#26

C# - CookieContainer 쿠키 값 가져오기 CookieContainer cookies = new CookieContainer(); cookies.Add(new Cookie("name1", "value1", "/", "www.domain1.com")); cookies.Add(new Cookie("name2", "value2", "/", "www.domain2.com")); Hashtable table = (Hashtable)cookies.GetType().InvokeMember("m_domainTable", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, cookies, new object[] { }); foreach (var key in table.Keys.. 2022. 10. 3.
C# - RichTextBox 색깔 지정 void AppendRichText(RichTextBox box, string text, Color color) { box.SelectionStart = box.TextLength; box.SelectionLength = 0; box.SelectionColor = color; box.AppendText(text + "\n"); box.SelectionColor = box.ForeColor; } 출처: https://stackoverflow.com/questions/1926264/color-different-parts-of-a-richtextbox-string Color different parts of a RichTextBox string I'm trying to color parts of a strin.. 2022. 9. 29.
C# - 설정 값 저장하고 불러오기 프로젝트 -> 프로젝트.속성 -> 설정에서 사진 처럼 저장 하고자 하는 변수를 만든다. private void Form1_Load(object sender, EventArgs e) { tbIpAdress.Text = Properties.Settings.Default.tbIpAdress_Value; tbCarWashSerial.Text = Properties.Settings.Default.tbCarWashSerial_Value; } 위에 코드처럼 읽어 오기만 하면 된다. private void btnSave_Click(object sender, EventArgs e) { Properties.Settings.Default.tbIpAdress_Value = tbIpAdress.Text; Properties.S.. 2022. 9. 26.
C# - Application.Exit() 명령어 안될 경우 (Environment.Exit(Environment.ExitCode)) Environment.Exit(Environment.ExitCode); 출처: https://stackoverflow.com/questions/25050341/application-is-still-running-in-memory-after-application-exit-is-called Application is still running in memory after Application.Exit() is called The application I am building is still running in memory (checked in Task Manager) after it is closed using Application.Exit(). Because of this when I am running i.. 2022. 9. 26.
C# - .NET 디컴파일러 및 어셈블리 브라우저(dotPeek) https://www.jetbrains.com/ko-kr/decompiler/ dotPeek: JetBrains가 만든 무료 .NET 디컴파일러 및 어셈블리 브라우저 www.jetbrains.com 2022. 9. 4.
C# - setTimeout 구현 방법 1. Task.Delay(delay).ContinueWith((task) => { /* Code */ }); 방법 2. public void setTimeout(Action TheAction, int Timeout) { Thread t = new Thread( () => { Thread.Sleep(Timeout); TheAction.Invoke(); } ); t.Start(); } 출처: https://stackoverflow.com/questions/4331149/winforms-equivalent-of-javascript-settimeout Winforms equivalent of javascript setTimeout Is there a simple solution/idea/strategy t.. 2022. 8. 28.
C# - 프로세스 이름으로 프로세스 죽이기(Process) 코드 public void killPorcesses(string pname) { Process[] processList = Process.GetProcessesByName(pname); if(processList.Length > 0) { for(int i=0; i < processList.Length; i++) { processList[i].Kill(); } } } killPorcesses("notepad"); 출처: https://infodbbase.tistory.com/92 C# Process 사용하기 #3 ( 특정 프로세스 종료(Kill) ) 안녕하세요, 이번 포스팅은 C# 에서 Process 를 이용하여 특정 프로세스를 종료시키는 방법을 정리하였습니다. 1. 특정 프로세스 가 실행 되어 있을 경우.. 2022. 8. 28.
C# - 다른 프로그램 실행 시키기(Porcess.Start) with 시작 경로 지정 예제 한 줄로 프로그램 실행시키기 System.Diagnostics.Process.Start(".\\Agents\\MCROAgent" + idx.ToString() + "\\clicker.exe"); 프로그램 시작 경로 등 다양한 옵션 설정 Process process = new Process(); process.StartInfo.WorkingDirectory = "Agents\\MCROAgent" + idx.ToString(); // 시작 경로 process.StartInfo.FileName = "clicker.exe"; // 파일 이름 process.Start(); * 프로그램의 폴더 내에서 실행시켜야만 할 경우 출처: https://heon-dev.tistory.com/7 Process.Start(.. 2022. 8. 28.
C# - 프로그램 중복 실행 방지하기 방법 1. 프로세스 이름 중복 감지 //이미 프로그램이 실행 중 일때... System.Diagnostics.Process[] processes = null; string strCurrentProcess = System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToUpper(); processes = System.Diagnostics.Process.GetProcessesByName(strCurrentProcess); if (processes.Length > 1) { MessageBox.Show(string.Format("'{0}' 프로그램이 이미 실행 중입니다.", System.Diagnostics.Process.GetCurrentProcess().Pr.. 2022. 8. 26.
C# - 다른 프로세스끼리 메시지(string) 전달하기(SendMessage) 수신 const int WM_COPYDATA = 0x4A; public struct COPYDATASTRUCT { public IntPtr dwData; public int cbData; [MarshalAs(UnmanagedType.LPStr)] public string lpData; } protected override void WndProc(ref Message m) { try { switch (m.Msg) { case WM_COPYDATA: COPYDATASTRUCT cds = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT)); MessageBox.Show(cds.lpData); break; default: base.WndProc(ref m); break;.. 2022. 8. 24.
C# - 다른 응용프로그램을 제어해 보자. feat.SPY++ 간혹 개발을 하다보면 외부 응용프로그램을 연계하거나 제어해야할 일이 있다. 일반적으로 본인이 만든(소스가 있는) 프로그램이라면 손쉽겠지만 아닌경우가 대부분이다. 그럴때는 Window Message를 이용하여 다른 응용프로그램을 제어할 수 있다. 모든 윈도우 응용프로그램은 윈도우즈 안에서 동작하기때문에 공통된 메시지를 이용하여 제어하는 방법이다. 예제 다음은 계산기 응용프로그램의 핸들을 찾아서 해당 핸들에 메시지를 보내는 예제이다. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windo.. 2022. 8. 24.
C# - 스레드에서 위젯 조작하기 private void AggiornaContatore() { if(this.lblCounter.InvokeRequired) { this.lblCounter.BeginInvoke((MethodInvoker) delegate() {this.lblCounter.Text = this.index.ToString(); ;}); } else { this.lblCounter.Text = this.index.ToString(); ; } } Invoker 사용 출처: https://stackoverflow.com/questions/14890295/update-label-from-another-thread Update label from another thread I use a thread writing in anothe.. 2022. 8. 23.
728x90