방명록은 여기로 by 김윤정

메인 블로그를 티스토리로 옮길까 하는 마음에 슬슬 준비하고 있습니다 :)
기능 차이가 아주 크군요 ... 이글루스는 점점 개판이 되어 가고 있는데...
역시 SK가 손대다 보니 그런가 봅니다.
일단은 티스토리에 써도 여기에 옮겨적기는 하겠습니다만, 방명록은 
http://chulin28ho.tistory.com/guestbook
을 이용해 주시기 바라겠습니다 :) 

 ... 근데 옮기려니까 엄두가 안나서 일단 연기..

오늘의 C# 공부 :server / client by 김윤정

/////////// server


using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace EchoServer
{
    class MainApp
    {
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("사용법 :{0} <Bind IP>", Process.GetCurrentProcess().ProcessName);
                return;
            }

            string bindIp = args[0];
            const int bindfort = 5425;
            TcpListener server = null;

            try
            {
                IPEndPoint localAddress =
                    new IPEndPoint(IPAddress.Parse(bindIp), bindfort);

                server = new TcpListener(localAddress);

                server.Start();

                Console.WriteLine("메아리 서버 시작...");


                while (true)
                {
                    TcpClient client = server.AcceptTcpClient();
                    Console.WriteLine("클라이언트 접속 :{0}", ((IPEndPoint)client.Client.RemoteEndPoint).ToString());

                    NetworkStream stream = client.GetStream();

                    int length;
                    string data = null;
                    byte[] bytes = new byte[256];

                        while ((length = stream.Read(bytes,0,bytes.Length)) != 0)
                        {
                            data = Encoding.Default.GetString(bytes, 0, length);
                            Console.WriteLine (String.Format("수신{0}",data)) ;
                            byte[] msg = Encoding.Default.GetBytes(data);
                            stream.Write(msg, 0, msg.Length);

                            Console.WriteLine(String.Format("송신: {0}", data));
                        }

                        stream.Close();
                        client.Close();
                }

 


            }

            catch (SocketException e)
            {
                Console.WriteLine(e);
            }

            finally
            {
                server.Stop();
            }

            Console.WriteLine("서버를 종료합니다");

        }
    }
}











//////Client

using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace jpClient
{
    class MainApp
    {
        static void Main(string[] args)
        {
             Console.WriteLine("args={0}",args.Length);
            if (args.Length < 4)
            {
                Console.WriteLine(
                    "사용법 : {0} <Bind IP> <Bind Port><Server IP> <Message>", Process.GetCurrentProcess().ProcessName);
                return;
            }

            string bindIP = args[0];
            int bindPort = Convert.ToInt32(args[1]);
            string serverIP = args[2];
            const int serverPort = 5425;
            string message = args[3];

            try
            {
                IPEndPoint clientAddress =
                    new IPEndPoint(IPAddress.Parse(bindIP), bindPort);
                IPEndPoint serverAddress =
                    new IPEndPoint(IPAddress.Parse(serverIP), serverPort);

                Console.WriteLine("클라이언트 : {0} , 서버 : {1}", clientAddress.ToString(), serverAddress.ToString());

                TcpClient client = new TcpClient(clientAddress);

                client.Connect(serverAddress);


                byte[] data = System.Text.Encoding.Default.GetBytes(message);

                NetworkStream stream = client.GetStream();

                stream.Write(data, 0, data.Length);

                Console.WriteLine("송신 :{0}", message);

                data = new byte[256];

                string responseData = "";

                int bytes = stream.Read(data, 0, data.Length);

                responseData = Encoding.Default.GetString(data, 0, bytes);

                Console.WriteLine("수신 :{0}", responseData);

                stream.Close();
                client.Close();
            }

            catch (SocketException e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("클라이언트를 종료합니다");


        }
    }
}


오늘의 C# 공부 : winform by 김윤정




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

namespace WindowsFormsApplication1
{
    public partial class Mainform : Form
    {

        Random random = new Random(37);

        public Mainform()
        {
            InitializeComponent();

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

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

        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 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.Show();
        }

        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# 공부 : WinForm by 김윤정

////simpleWindow

//using System;

//namespace SimpleWindow
//{
//    class MainApp : System.Windows.Forms.Form
//    {
//        static void Main(string[] args)
//        {
//            System.Windows.Forms.Application.Run(new MainApp());
//        }
//    }
//}

////SimpleWindowClose
//using System;
//using System.Windows.Forms;

//namespace UsingApplication
//{
//    class MainApp : Form
//    {
//        static void Main(string[] args)
//        {
//            MainApp form = new MainApp();

 


//            form.Click += new EventHandler((sender, eventargs) =>
//            {
//                Console.WriteLine("closing Window,,,");
//                Application.Exit();
//            });


//            Console.WriteLine("Starting Window Application...");
//            Application.Run(form);


//            Console.WriteLine("Exiting Window Application....");

           

//        }

//    }
//}

 


////메시지 필터
//using System;
//using System.Windows.Forms;

//namespace MessageFilter
//{
//    class MessageFilter : IMessageFilter
//    {
//        public bool PreFilterMessage(ref Message m)
//        {
//            if (m.Msg == 0x0F || m.Msg == 0x200 || m.Msg == 0x113)
//                return false;

//            Console.WriteLine("{0} : {1} ", m.ToString(), m.Msg);

//            if (m.Msg == 0x201)
//                Application.Exit();

//            return true;
//        }
//    }

 

//    class MainApp : Form
//    {
//        static void Main(string[] args)
//        {
//            Application.AddMessageFilter(new MessageFilter());
//            Application.Run(new MainApp());
//        }
//    }
//}


////form Event

//using System;
//using System.Windows.Forms;

//namespace Formevent
//{

//    class MainApp : Form
//    {
//        public void MyMouseHandler(object sender, MouseEventArgs e)
//        {
//            Console.WriteLine("Sender : {0} ", ((Form)sender).Text);
//            Console.WriteLine("X:{0} , Y:{1}", e.X, e.Y);
//            Console.WriteLine("Button : {0} , Click : {1}", e.Button, e.Clicks);
//            Console.WriteLine();
//        }

//        public MainApp(string title)
//        {
//            this.Text = title;
//            this.MouseDown +=new MouseEventHandler(MyMouseHandler);
//        }

//        static void Main(string[] args)
//        {
//            Application.Run(new MainApp("Mouse Event Test"));
//        }
//    }

//}

 


////Form Size

//using System;
//using System.Windows.Forms;

//namespace FormSize
//{
//    class MainApp : Form
//    {
//        static void Main(string[] args)
//        {
//            MainApp form = new MainApp();
//            form.Width = 300;
//            form.Height = 200;


//            form.MouseDown += new MouseEventHandler(form_MouseDown);

//            Application.Run(form);
//        }

 

//        static void form_MouseDown(object sender, MouseEventArgs e)
//        {
//            Form form = (Form)sender;
//            int oldWidth = form.Width;
//            int oldHeigth = form.Height;

//            if (e.Button == MouseButtons.Left)
//            {
//                if (oldWidth < oldHeigth)
//                {
//                    form.Width = oldHeigth;
//                    form.Height = oldWidth;
//                }
//            }

//            else if (e.Button == MouseButtons.Right)
//            {
//                if (oldHeigth < oldWidth)
//                {
//                    form.Width = oldHeigth;
//                    form.Height = oldWidth;
                   
//                }
//            }

//            Console.WriteLine("윈도우의 크기가 변경되었습니다");
//            Console.WriteLine("Width : {0} , Height {1} ", form.Width, form.Height);
//        }
//    }
//}

 

 

////백그라운드 이미지조절하기

//using System;
//using System.Drawing;
//using System.Windows.Forms;

//namespace FormBackground
//{
//    class MainApp : Form
//    {
//        Random rand;
//        public MainApp()
//        {
//            rand = new Random();

//            this.MouseWheel += new MouseEventHandler(MainApp_MouseWheel);
//            this.MouseDown += new MouseEventHandler(MainApp_MouseDown);
//        }


//        void MainApp_MouseDown(object sender, MouseEventArgs e)
//        {
//            if (e.Button == MouseButtons.Left)
//            {
//                Color oldcolor = this.BackColor;
//                //this.BackColor = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
//                this.BackColor = Color.FromArgb(255, 255, 0, 0);
               
//            }

//            else if (e.Button == MouseButtons.Right)
//            {
//                if (this.BackgroundImage != null)
//                {
//                    this.BackgroundImage = null;
//                    return;
//                }

//                string file = "sample.jpg";

//                if (System.IO.File.Exists(file) == false)
//                    MessageBox.Show("파일이 없ㅋ엉ㅋ");
//                else
//                    this.BackgroundImage = Image.FromFile(file);
//            }
//        }

//        void MainApp_MouseWheel(object sender, MouseEventArgs e)
//        {
//            this.Opacity = this.Opacity + (e.Delta > 0 ? 0.1 : -0.1);
//            Console.WriteLine("Opacity : {0}", this.Opacity);
//        }

//        static void Main(string[] args)
//        {
//            Application.Run(new MainApp());
//        }
//    }
//}


////폼 스타일
//using System;
//using System.Windows.Forms;

//namespace FormStyle
//{
//    class MainApp : Form
//    {
//        static void Main(string[] args)
//        {
//            MainApp form = new MainApp();

//            form.Width = 400;
//            form.MouseDown += new MouseEventHandler(form_MouseDown);

//            Application.Run(form);
//        }

//        static void form_MouseDown(object sender, MouseEventArgs e)
//        {
//            Form form = (Form)sender;

//            if (e.Button == MouseButtons.Left)
//            {
//                form.MaximizeBox = true;
//                form.MinimizeBox = true;
//                form.Text = "최소 최대 오케이";
//            }

//            else if (e.Button == MouseButtons.Right)
//            {
//                form.MaximizeBox = false;
//                form.MinimizeBox = false;
//                form.Text = "최소 최대 끔";
//            }
//        }
//    }
//}


//폼과 컨트롤
using System;
using System.Windows.Forms;

namespace FormAndControl
{
    class MainApp : Form
    {
        static void Main(string[] args)
        {
            Button button = new Button();


            button.Text = "Click Me!";
            button.Left = 100;
            button.Top = 50;

            button.Click += (object sender, EventArgs e) =>
                {
                    MessageBox.Show("딸깍");
                };

            MainApp form = new MainApp();
            form.Text = "Form & Control";
            form.Height = 150;

            form.Controls.Add(button);

            Application.Run(form);
        }
    }
}


1 2 3 4 5 6 7 8 9 10 다음


Twitter