* 형변환
    - 숫자 -> 문자
        int num = 100; 
        string str = num.ToString();//Exception 발생
        str = Convert.ToString( num );//Exception 발생
        int.TryParse(str, out num);//Exception 없음, 추천
        
    - 문자 -> 숫자    
        string str = "100";
        int num = int.Parse( str ); 
        num = Convert.ToInt32( str );
        
//===========
* 문자열 배열
    List<string> as1 = new List<string>();
as1.Clear();//RemoveAll 대신 사용
as1.Add("qwe");
//===========
* UI 다루기
            //탭 변경
            //tabMain.SelectTab(1);
            //폼 보이기
            //frmCalc form2 = new frmCalc();            form2.Visible = true;
//================
* 이벤트 수동 추가
    - 폼 Load 함수에 추가
private void frmMain_Load(object sender, EventArgs e)
{
    ...
    textAnswer.KeyDown += new KeyEventHandler(textAnswer_KeyDown);
    ...
}
private void textAnswer_KeyDown(object sender, KeyEventArgs e)
{
     if (e.KeyCode == Keys.Enter) {
        //enter key is down
        ...
     }
}
//===============================
* 창 크기 설정 저장, 부르기(복원)
    Solution Explorer -> Properties -> Settings.settings
    - 이름 추가, 형식 지정
    - 폼 이벤트 추가: Load,  FormClosing
private void Form1_Load(object sender, EventArgs e)
{
    //설정 부르기
    if (Properties.Settings.Default.Size.Width > 0) {
        Location = Properties.Settings.Default.Location;
        Size = Properties.Settings.Default.Size;
    }
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    //설정 저장       
    if (this.WindowState == FormWindowState.Normal) {
        Properties.Settings.Default.Location = this.Location;
        Properties.Settings.Default.Size = this.Size;
        Properties.Settings.Default.Save();
     }    
}
//===============================
* 글자 읽기(TTS)
using System.Speech.Synthesis;
SpeechSynthesizer m_synth;
       private int VoiceInit(int nMode)
        {
            //음성 초기화
            m_synth = new SpeechSynthesizer();
            m_synth.Volume = 100;  // 0...100
            m_synth.Rate = 0;     // -10...10
//목소리 국적(국가 언어) 선택
            VoiceInfo info = null;
            int i = 0;
            foreach (InstalledVoice voice in m_synth.GetInstalledVoices()) {
                info = voice.VoiceInfo;
                i++;
                if (info.Culture.ToString() == "en-US") { //"ko-KR"
                    break;
                }
            }
            if (info != null) {
                m_synth.SelectVoice(info.Name);
            }
            ////읽기
            //m_synth.Speak("Hello World");
            // Asynchronous
            //m_synth.SpeakAsync("Hello World");
            return 1;
        }
'Code > C#' 카테고리의 다른 글
| [C#] System.Management.ManagementException: Access denied 에러 해결 방법 (0) | 2020.02.10 | 
|---|---|
| C# 크롬 브라우저 내장하기 (0) | 2020.02.01 | 
| [C#] 에러 해결 An object reference is required for the non-static field, method, or property Dispatcher.BeginInvoke (0) | 2020.02.01 | 
| C# 과 Java 성능 비교 (0) | 2016.07.05 | 
| [C# tips] 디버깅 시작 과 끝에서 딜레이가 길고 느릴때 해결 방법 (0) | 2016.06.19 | 










