==========================================================================================

C#

==========================================================================================


<C#>


-p617

=CONSOL APP

-consol에서 window form 띄우기/버튼추가/이벤트추가







=상속 받기

     class MainApp:Form //:System.Windows.Forms.Form 상속(window form) - 길어서 using 추가
    {
        
static void Main(string[] args)
        {

        }
    }



=windows form 생성/ 구동


     class MainApp:Form //:System.Windows.Forms.Form 상속(window form) - 길어서 using 추가
    {
        
static void Main(string[] args)
        {
            MainApp form 
= new MainApp();

            Application.Run(form); 
//
            //Application.Run(new MainApp()); // book p 617

        }
    }


=버튼1 생성 -  버튼1 text 입력 / 버튼1 추가

     class MainApp:Form //:System.Windows.Forms.Form 상속(window form) - 길어서 using 추가
    {
        
static void Main(string[] args)
        {
            MainApp form 
= new MainApp();

            Button button1 
= new Button();
            button1.Text 
= "button1"
;
            form.Controls.Add(button1);


            Application.Run(form); 
//
            //Application.Run(new MainApp()); // book p 617

        }
    }





=버튼2 생성 - 버튼2 text 입력 / 버튼2위치 변경 / 버튼2 text 추가

     class MainApp:Form //:System.Windows.Forms.Form 상속(window form) - 길어서 using 추가
    {
        
static void Main(string[] args)
        {
            MainApp form 
= new MainApp();

            Button button1 
= new Button();
            button1.Text 
= "button1";
            form.Controls.Add(button1);

            Button button2 
= new Button();
            button2.Text 
= "button2";
            button2.Left 
= 200
;
            form.Controls.Add(button2);


            Application.Run(form); 
//
            //Application.Run(new MainApp()); // book p 617

        }
    }








=이벤트 핸들러 -

-선택시 자동 코드 생성됨





-동작할 내용 코딩





         private static void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(sender.ToString());
            MessageBox.Show(e.ToString());

        }







        static void button2_Click(object sender, EventArgs e)
        {
            
throw new NotImplementedException();
        }


-ALT-F5


-CTRL-F5




==============================================================================================

=WINDOWS FORM APP


=델리게이트 => 이벤트객체에 메소드객체(메소드 객체의 위임 객체)를 붙임





=원래 한곳에 모여 있었으나 코딩 라인이 길어 목적에 맞게 나눔 => partial class














=종료






=OS가 APP메세지 전달 = 메시지 가로채기( 내용 바꿀수 있음 )

-우클릭 => 좌클릭 / NULL


=메세지 필터

: IMessageFilter // 인터페이스 상속



=예제 P643













        private void Form1_Load(object sender, EventArgs e)
        {

        }

        
private void cboFont_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        
private void chkBold_CheckedChanged(object sender, EventArgs e)
        {

        }

        
private void chkItalic_CheckedChanged(object sender, EventArgs e)
        {

        }


=

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace wintest1
{
    
public partial class Form1 : Form
    {
        
public Form1()
        {
            InitializeComponent();
        }

        
void ChangeFont()
        {
            
if (cboFont.SelectedIndex < 0)
                
return;

            FontStyle style 
= FontStyle.Regular;

            
if (chkBold.Checked)
                style 
|= FontStyle.Bold;

            
if (chkItalic.Checked)
                style 
|= FontStyle.Italic;

            txtSampleText.Font 
= new Font((string)cboFont.SelectedItem, 10, style);
        }

        
private void Form1_Load(object sender, EventArgs e)
        {
            var Fonts 
= FontFamily.Families;
            foreach (FontFamily font in Fonts)
                cboFont.Items.Add(font.Name);
        }

        
private void cboFont_SelectedIndexChanged(object sender, EventArgs e)
        {
            ChangeFont();
        }

        
private void chkBold_CheckedChanged(object sender, EventArgs e)
        {
            ChangeFont();
        }

        
private void chkItalic_CheckedChanged(object sender, EventArgs e)
        {
            ChangeFont();
        }
        
    }
}







=이벤트구동형 ( Event Driven Pro...)

:순서 의미 없음





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace wintest1
{
    
public partial class Form1 : Form
    {
        Random random 
= new Random(37);
        
public Form1()
        {
            InitializeComponent();

            lvDummy.Columns.Add(
"Name");
            lvDummy.Columns.Add(
"Depth");
        }

        
void ChangeFont()
        {
            
if (cboFont.SelectedIndex < 0)
                
return;

            FontStyle style 
= FontStyle.Regular;

            
if (chkBold.Checked)
                style 
|= FontStyle.Bold;

            
if (chkItalic.Checked)
                style 
|= FontStyle.Italic;

            txtSampleText.Font 
= new Font((string)cboFont.SelectedItem, 10, style);
        }

        
private void Form1_Load(object sender, EventArgs e) // Font 가져옴
        {
            var Fonts 
= FontFamily.Families;
            foreach (FontFamily font in Fonts)
                cboFont.Items.Add(font.Name);
        }

        
private void cboFont_SelectedIndexChanged(object sender, EventArgs e) // 
        {
            ChangeFont();
        }

        
private void chkBold_CheckedChanged(object sender, EventArgs e)
        {
            ChangeFont();
        }

        
private void chkItalic_CheckedChanged(object sender, EventArgs e)
        {
            ChangeFont();
        }

        
private void tbDummy_Scroll(object sender, EventArgs e)
        {
            pgDummy.Value 
= tbDummy.Value;
        }

        
private void btnModal_Click(object sender, EventArgs e)
        {
            Form frm 
= new Form();
            frm.Text 
= "Modal Form";
            frm.Width 
= 300;
            frm.Height 
= 100;
            frm.BackColor 
= Color.Red;
            frm.ShowDialog();
        }

        
private void btnModaless_Click(object sender, EventArgs e)
        {
            Form frm 
= new Form();
            frm.Text 
= "Modaless Form";
            frm.Width 
= 300;
            frm.Height 
= 300;
            frm.BackColor 
= Color.Green;
            frm.ShowDialog();
        }

        
private void btnMsgBox_Click(object sender, EventArgs e)
        {
            MessageBox.Show(txtSampleText.Text, 
"MessageBox Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
        
        
void TreeToList()
        {
            lvDummy.Items.Clear();
            foreach (TreeNode node in tvDummy.Nodes)
                TreeToList(node);
        }

        
void TreeToList(TreeNode Node)
        {
            lvDummy.Items.Add(
                
new ListViewItem(new string[] { Node.Text, Node.FullPath.Count(f => f == '\\').ToString() }));

            foreach(TreeNode node in Node.Nodes)
            {
                TreeToList(node);
            }
        }

        
private void btnAddRoot_Click(object sender, EventArgs e)
        {
            tvDummy.Nodes.Add(random.Next().ToString());
            TreeToList();
        }

        
private void btnAddChild_Click(object sender, EventArgs e)
        {
            
if(tvDummy.SelectedNode == null)
            {
                MessageBox.Show(
"선택된 노드가 없습니다.",
                    
"TreeView Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
                
return;
            }
            tvDummy.SelectedNode.Nodes.Add(random.Next().ToString());
            tvDummy.SelectedNode.Expand();
            TreeToList();
        }
        
    }
}
















==========================================================================================

C++

==========================================================================================

<C++>


=

C책 P387

http://itsmart333.tistory.com/186


int *A = new int[3];

delete []A;

int **B = new int*[3];

delete []B;

int *A = &B;


int (*C)[3] = new int[2][3]

delete []C;



#include <iostream>
using namespace std;

int main(void)
{
  
int arr[2][2][2=  { 
              {  { 
12 },
                { 
34 } },

              {  { 
56 },
                { 
78 } }
            };
  printf(
"%d \n", arr[0][0][1]);
  printf(
"%d \n", *(*(*(arr + 1) + 0) + 1));
  printf(
"%d \n", (*(arr + 1))[0][1]);
  printf(
"%d \n", (*(*(arr + 1) + 0))[1]);
  printf(
"%d \n", *(*(arr[1] + 0) + 1));
  printf(
"%d \n", (*(arr[1] + 0))[1]);
  printf(
"%d \n", *(arr[1][0] + 1));

  
int *A = new int[3];
  
int **B = new int*[3];
  
int(*C)[3= new int[2][3];

  cout 
<< C << endl;
  cout 
<< C + 1 << endl;
  cout 
<< ((C + 1) - C) / 0x04 << endl;
  cout 
<< sizeof(int<< endl;
  cout 
<< sizeof(*C) << endl;
  cout 
<< sizeof(C) << endl;
  cout 
<< sizeof(**C) << endl;
  cout 
<< sizeof((*C)[3]) << endl;

  cout 
<< sizeof(C[0][0]) << endl;

  
for (int i = 0; i < 2; ++i) //sizeof(*(C[3]))
    for (int j = 0; j < sizeof(*C)/sizeof(**C); ++j)
      C[i][j] 
= (i + 1)*(j + 1);

  
for (int i = 0; i < 2; ++i)
    
for (int j = 0; j < sizeof(*C)/sizeof(**C); ++j)
      cout 
<< C[i][j] << endl;

  
delete[]C;


  
return 0;
}






=car class 코딩하기




=car class


#include <iostream>
#include <string.h>
using namespace std;

class CAR
{

    
private:
        
int iColor;
        
int iSpeed;
        
char *cName;
        
void CarName(const char *);
    
public:
        CAR();
        CAR(
const char *);
        CAR(
const CAR &);
        ~CAR();
        
void SetColor(const int);
        
void SetSpeed(const int);
        
void SetName(const char *);
        
void Print(ostream *IN);
         void 
CAR operator (CAR &); // 연산자 재정의
        void operator+=(CAR &IN);        
};


void CAR::CarName(const char * T)
{
    iColor 
= 0;
    iSpeed 
= 0;
    cName 
= new char[strlen(T)+1];
    strcpy(cName, T);

    cout << cName << "이 생성 되었습니다\n";

}

CAR::CAR()
{
    CarName(
"car");
    
/*
    iColor 
= 0;
    iSpeed 
= 0;
    cName 
= new char[strlen("car")+1];
    strcpy(cName,"car");
    cout 
<< cName << "이 생성 되었습니다\n";*/
}

CAR::CAR(
const char * T)
{
    CarName(T);
    
/*
    iColor 
= 0;
    iSpeed 
= 0;
    cName 
= new char[strlen(T)+1];
    strcpy(cName, T);
    cout 
<< cName << "이 생성 되었습니다\n";*/
}

CAR::CAR(
const CAR & A)
{
    iColor 
= A.iColor;
    iSpeed 
= A.iSpeed;
    cName 
= new char[strlen(A.cName)+1];
    strcpy(cName, A.cName);


    cout << cName << "이 복사 생성 되었습니다\n";

}

CAR::~CAR()
{

    cout << cName << "이 소멸 되었습니다\n";

    delete [] cName;
}

void CAR::SetColor(const int ic)
{
    iColor 
= ic;

    cout << cName << " Color : " << iColor << " 로 변경 되었습니다\n";

}

void CAR::SetSpeed(const int is)
{
    iSpeed 
= is;

    cout << cName << " Speed : " << iSpeed << " 로 변경 되었습니다\n";

}

void CAR::SetName(const char * cn)
{

    cout << cName << " Name  : ";

    delete [] cName;
    cName 
= new char[strlen(cn)+1];
    strcpy(cName, cn);    

    cout << cName << " 로 변경 되었습니다\n";

}

//void Print(ostream *IN);
void CAR::operator=(const CAR & T) // 연산자 재정의
{
    
//iColor = T.iColor;
    //iSpeed = T.Speed;

    cout << "operator=\n";

    SetColor(T.iColor); // 인라인으로 하면 좋음
    SetSpeed(T.iColor);
    SetName(T.cName);
    
}
//void operator+=(CAR &IN);        

int main()
{
    CAR obj1;
    CAR obj2
=obj1;

    obj1.SetName(
"ca1");
    obj1.SetColor(
1);
    obj1.SetSpeed(
10);

    obj2.SetName(
"ca2");
    obj2.SetColor(
2);
    obj2.SetSpeed(
20);

    
return 0;
}









=CAR3 = CAR2 = CAR1

CAR2 = CAR1 ====> void형 남음

CAR3 = void  ====> ERROR


void CAR::operator=(const CAR & T) // 연산자 재정의
{
    
//iColor = T.iColor;
    //iSpeed = T.Speed;

    cout << "operator=\n";

    SetColor(T.iColor); // 인라인으로 하면 좋음
    SetSpeed(T.iColor);
    SetName(T.cName);

    cout << "====================\n";


}


===============>> const CAR 반환하도록 변경필요









=void => const CAR로 변경

CAR2 = CAR1



CAR3 = CAR2 = CAR1 => return *this시 임시객체 생성 : 복사생성자 호출 ( = 연산자 2번 호출 되므로 복사생성 2번 됨)


const CAR CAR::operator=(const CAR & T) // 연산자 재정의
{
    
//iColor = T.iColor;
    //iSpeed = T.Speed;

    cout << "operator=\n";

    SetColor(T.iColor); // 인라인으로 하면 좋음
    SetSpeed(T.iColor);
    SetName(T.cName);

    cout << "====================\n";

    return *this;
}











= C개념 추가(출력 ON/OFF)

#define DEBUG

cout << ...

#endif


-DDUBUG



#include <iostream>
#include <string.h>
using namespace std;

class CAR
{
    
private:
        
int iColor;
        
int iSpeed;
        
char *cName;
        
void CarName(const char *);
    
public:
        CAR();
        CAR(
const char *);
        CAR(
const CAR &);
        ~CAR();
        
void SetColor(const int);
        
void SetSpeed(const int);
        
void SetName(const char *);
        
void Print(ostream *IN);
        
const CAR operator=(const CAR &); // 연산자 재정의
        void operator+=(CAR &IN);        
};


void CAR::CarName(const char * T)
{
    iColor 
= 0;
    iSpeed 
= 0;
    cName 
= new char[strlen(T)+1];
    strcpy(cName, T);
#ifdef DEBUG // DEBUG
    cout << cName << "이 생성 되었습니다\n";
#endif
}

CAR::CAR()
{
    CarName(
"car");
    
/*
    iColor 
= 0;
    iSpeed 
= 0;
    cName 
= new char[strlen("car")+1];
    strcpy(cName,"car");
    cout 
<< cName << "이 생성 되었습니다\n";*/
}

CAR::CAR(
const char * T)
{
    CarName(T);
    
/*
    iColor 
= 0;
    iSpeed 
= 0;
    cName 
= new char[strlen(T)+1];
    strcpy(cName, T);
    cout 
<< cName << "이 생성 되었습니다\n";*/
}

CAR::CAR(
const CAR & A)
{
    iColor 
= A.iColor;
    iSpeed 
= A.iSpeed;
    cName 
= new char[strlen(A.cName)+1];
    strcpy(cName, A.cName);

#ifdef DEBUG // DEBUG
    cout << cName << "이 복사 생성 되었습니다\n";
#endif
}

CAR::~CAR()
{
#ifdef DEBUG // DEBUG
    cout << cName << "이 소멸 되었습니다\n";
#endif
    delete [] cName;
}

void CAR::SetColor(const int ic)
{
    iColor 
= ic;
#ifdef DEBUG // DEBUG
    cout << cName << " Color : " << iColor << " 로 변경 되었습니다\n";
#endif
}

void CAR::SetSpeed(const int is)
{
    iSpeed 
= is;
#ifdef DEBUG // DEBUG
    cout << cName << " Speed : " << iSpeed << " 로 변경 되었습니다\n";
#endif
}

void CAR::SetName(const char * cn)
{
#ifdef DEBUG // DEBUG
    cout << cName << " Name  : ";
#endif
    delete [] cName;
    cName 
= new char[strlen(cn)+1];
    strcpy(cName, cn);    
#ifdef DEBUG // DEBUG
    cout << cName << " 로 변경 되었습니다\n";
#endif
}

//void Print(ostream *IN);
const CAR CAR::operator=(const CAR & T) // 연산자 재정의
{
    
//iColor = T.iColor;
    //iSpeed = T.Speed;
#ifdef DEBUG // DEBUG
    cout << "operator=\n";
#endif
    SetColor(T.iColor); // 인라인으로 하면 좋음
    SetSpeed(T.iColor);
    SetName(T.cName);
#ifdef DEBUG // DEBUG
    cout << "====================\n";
#endif
    return *this;
}
//void operator+=(CAR &IN);        
int main()
{
    CAR car1;
    CAR car2(
"BMW");
    CAR car3(
"내꺼");
    car3 
= car2 = car1;
    
return 0;
}
/*
int main()
{
    CAR obj1;
    CAR obj2
=obj1;

    obj1.SetName("ca1");
    obj1.SetColor(1);
    obj1.SetSpeed(10);

    obj2.SetName("ca2");
    obj2.SetColor(2);
    obj2.SetSpeed(20);

    return 0;
}*/






'2015 스마트 콘트롤러 > 업무일지' 카테고리의 다른 글

20150615  (0) 2015.06.16
20150612  (0) 2015.06.14
20150610  (0) 2015.06.10
20150609  (0) 2015.06.09
20150608  (0) 2015.06.09
Posted by ahj333
,