달력

42025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
반응형
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void textBox1_Validated(object sender, EventArgs e)
        {
            this.label1.Text = Regex.IsMatch(this.textBox1.Text, @"[ㄱ-ㅎ가-힣]").ToString();
        }

        private void textBox2_Validated(object sender, EventArgs e)
        {
            this.label2.Text = Regex.IsMatch(this.textBox2.Text, @"[ㄱ-ㅎ가-힣]").ToString();
        }
    }
}

 

실행화면

 

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

[C#]string에 여러공백을 한개의 공백으로 바꾸기  (0) 2017.11.05
[C#]DateTime간에 간격 구하기  (0) 2017.11.02
[C#] Loading Form  (0) 2017.05.19
[C#]SendKeys.Send  (0) 2017.05.16
[C#]픽셀의 RGB정보 가져오기  (0) 2017.05.05
Posted by 유령회사
|
반응형
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            int sum = 0;

            new LoadingForm(() => {
                                    for (int i = 0; i < 1000; i++)
                                    {
                                        sum += i;
                                    }

                                    Thread.Sleep(3000);

                                    Action act = () => this.label1.Text = sum.ToString();

                                    if (this.InvokeRequired)
                                        this.BeginInvoke(act);
                                    else
                                        act();
                                  }).ShowDialog();
        }
    }
}

 

 



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class LoadingForm : Form
    {
        private readonly MethodInvoker method;

        public LoadingForm(MethodInvoker action)
        {
            InitializeComponent();
            this.Load += LoadingForm_Load;

            this.method = action;

            this.TopMost = true;
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void LoadingForm_Load(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                method.Invoke();
                InvokeAction(this, Dispose);
            }).Start();
        }

        private void InvokeAction(LoadingForm control, MethodInvoker action)
        {
            if (control.InvokeRequired)
                control.BeginInvoke(action);
            else
                action();
        }
    }
}

 

실행화면

 

 

 

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

[C#]DateTime간에 간격 구하기  (0) 2017.11.02
[C#]정규식 한글체크  (2) 2017.05.23
[C#]SendKeys.Send  (0) 2017.05.16
[C#]픽셀의 RGB정보 가져오기  (0) 2017.05.05
[C#]폼 중복 실행 방지  (0) 2017.05.03
Posted by 유령회사
|
반응형
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            this.textBox1.Focus();
            SendKeys.Send("ABCDE");
        }
    }
}

 

    실행화면

 

    더블클릭 전                                                 더블클릭 후

 

SendKeys.Send함수에 들어가는 키값은 아래와 같고

 

Key

코드

백스페이스

{BACKSPACE} {BS} 또는 {BKSP}

BREAK

{BREAK}

CAPS LOCK

{CAPSLOCK}

DEL 또는 삭제

{DELETE} 또는 {DEL}

아래쪽 화살표

{DOWN}

END

{END}

ENTER

{ENTER} 또는 ~

Esc 키

{ESC}

도움말

{HELP}

{HOME}

INS 또는 INSERT

{INSERT} or {INS}

왼쪽 화살표

{LEFT}

NUM LOCK

{NUMLOCK}

Page Down

{PGDN}

Page Up

{PGUP}

화면 인쇄

{PRTSC} (나중에 사용할 예약 됨).

오른쪽 화살표

{RIGHT}

스크롤 잠금

{SCROLLLOCK}

Tab 키

{탭}

위쪽 화살표

{UP}

F1

{F1}

F2

{F2}

F3

{F3}

F4

{F4}

F5

{F5}

F6

{F6}

F7

{F7}

F8

{F8}

F9

{F9}

F10

{F10}

F11

{F11}

F12

{F12}

F13

{F13}

F14

{F14}

F15

{F15}

F16

{F16}

키패드 추가

{ADD}

키패드 빼기

{SUBTRACT}

키패드 곱하기

{MULTIPLY}

키패드 나누기

{DIVIDE}

SHIFT, CTRL 및 ALT 키의 조합이와 결합 된 키를 지정 하려면 다음 코드 중 하나 이상과 키 코드를 앞에 있습니다.

Key

코드

SHIFT 키

+

CTRL

^

ALT 키

%

 

특문과 합쳐서 쓸때는

Ctrl + C = "^C"

Ctrl + V = "^V"

Ctrl + Alt + Enter = "^%{ENTER}"

 

이런 식으로 사용 하면 된다. 

 


 

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

[C#]정규식 한글체크  (2) 2017.05.23
[C#] Loading Form  (0) 2017.05.19
[C#]픽셀의 RGB정보 가져오기  (0) 2017.05.05
[C#]폼 중복 실행 방지  (0) 2017.05.03
[C#]드래그앤드롭  (0) 2017.05.01
Posted by 유령회사
|
반응형
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if(this.pictureBox1.Image != null)
            {
                try
                {
                    Bitmap bitmap = new Bitmap(this.pictureBox1.Image);
                    Color color = bitmap.GetPixel(e.X, e.Y);
                    this.label1.Text = $"RED : {color.R} GREEN : {color.G} BLUE : {color.B}";
                }
                catch (Exception)
                {
                }
            }
        }
    }
}

 

실행화면

 

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

[C#] Loading Form  (0) 2017.05.19
[C#]SendKeys.Send  (0) 2017.05.16
[C#]폼 중복 실행 방지  (0) 2017.05.03
[C#]드래그앤드롭  (0) 2017.05.01
[C#]PictureBox안에 있는 이미지 드래그로 이동시키기  (7) 2017.04.28
Posted by 유령회사
|
반응형
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 WindowsFormsApp5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (Form frm in Application.OpenForms)
            {
                if(frm.Name == "PopUp")
                {
                    frm.Activate();
                    return;
                }
            }

            PopUp sfrm = new PopUp();
            sfrm.Show();
        }
    }
}

 

 

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

[C#]SendKeys.Send  (0) 2017.05.16
[C#]픽셀의 RGB정보 가져오기  (0) 2017.05.05
[C#]드래그앤드롭  (0) 2017.05.01
[C#]PictureBox안에 있는 이미지 드래그로 이동시키기  (7) 2017.04.28
[C#] 화면스크린 갭쳐  (0) 2017.04.25
Posted by 유령회사
|
반응형
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 WindowsFormsApp4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.AllowDrop = true;
            this.DragDrop += Form1_DragDrop;
            this.DragEnter += Form1_DragEnter;
        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy | DragDropEffects.Scroll;
            }
        }

        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
                foreach (string str in file)
                {
                    this.textBox1.Text += str + "\r" + "\n";
                }
            }
        }
    }
}

 

DragDropEffects 를 사용하여 끌어서 놓기 작업마다 서로 다른 마우스 포인터 표시

(마우스 포인터의 모양이 바뀌는거 같다)

 

멤버 이름 설명
All

데이터 복사는, 끌기 소스에서 제거 되 고 놓기 대상에서 스크롤됩니다.

Copy

데이터는 놓기 대상에 복사 됩니다.

Link

끌기 소스에서 데이터를 놓기 대상에 연결 됩니다.

Move

끌기 소스에서 데이터를 놓기 대상으로 이동 됩니다.

None

놓기 대상에서 데이터를 허용 하지 않습니다.

Scroll

스크롤을 시작 또는 놓기 대상에서 현재 진행 중입니다.

 

실행화면

 

Posted by 유령회사
|
반응형
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        private Point startPoint = Point.Empty;
        private Point movePoint  = Point.Empty;
        bool isClick = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isClick = true;
                this.startPoint = new Point(e.Location.X - movePoint.X, e.Location.Y - movePoint.Y);
            }
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isClick)
            {
                this.movePoint = new Point(e.Location.X - startPoint.X, e.Location.Y - startPoint.Y);
                this.pictureBox1.Invalidate();
            }
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (isClick) isClick = false;
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.White);

            if (this.pictureBox1.Image != null)
                e.Graphics.DrawImage(this.pictureBox1.Image, movePoint);
        }
    }
}

 

실행화면

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

[C#]폼 중복 실행 방지  (0) 2017.05.03
[C#]드래그앤드롭  (0) 2017.05.01
[C#] 화면스크린 갭쳐  (0) 2017.04.25
[C#]소켓으로 이미지 전송하기  (2) 2017.04.23
[C#]as is  (0) 2017.04.22
Posted by 유령회사
|
반응형
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 WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap screenCaptureBitmap 
                = new Bitmap(Screen.PrimaryScreen.Bounds.Width
                           , Screen.PrimaryScreen.Bounds.Height);

            Graphics g = Graphics.FromImage(screenCaptureBitmap);
            Size sz = new Size(Screen.PrimaryScreen.Bounds.Width
                             , Screen.PrimaryScreen.Bounds.Height);
            g.CopyFromScreen(0, 0, 0, 0, sz);

            this.pictureBox1.Image = screenCaptureBitmap;
        }
    }
}

 

 

 

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

[C#]드래그앤드롭  (0) 2017.05.01
[C#]PictureBox안에 있는 이미지 드래그로 이동시키기  (7) 2017.04.28
[C#]소켓으로 이미지 전송하기  (2) 2017.04.23
[C#]as is  (0) 2017.04.22
[C#]마지막 일자 구하기  (0) 2017.04.20
Posted by 유령회사
|
반응형
서버 쪽
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        /// <summary>
        /// 이미지 읽어오기(하드)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dia = new OpenFileDialog();
            dia.Multiselect = false;
            dia.Filter = "jpg files|*.jpg";

            if (dia.ShowDialog() == DialogResult.OK)
            {
                this.pictureBox1.ImageLocation = dia.FileName;
            }
        }

        /// <summary>
        /// 이미지를 바이트로
        /// https://www.codeproject.com/Articles/15460/C-Image-to-Byte-Array-and-Byte-Array-to-Image-Conv
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public byte[] ImageToByteArray(System.Drawing.Image image)
        {
            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            return ms.ToArray();
        }

        /// <summary>
        /// 서버 대기
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            this.button3.Enabled = false;

            Socket sListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 8081);

            sListener.Bind(ipEndPoint);
            sListener.Listen(20);

            Console.WriteLine("클라이언트 연결을 대기합니다.");

            Socket sClient = sListener.Accept();
            IPEndPoint ip = (IPEndPoint)sClient.RemoteEndPoint;
            Console.WriteLine("주소 {0} 에서 접속", ip.Address);

            Byte[] _data = ImageToByteArray(this.pictureBox1.Image);
            sClient.Send(BitConverter.GetBytes(_data.Length));
            sClient.Send(_data);

            sListener.Close();
        }
    }
}

 

 

클라이언트 쪽

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

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

        /// <summary>
        /// 소켓으로 읽어오기
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            Socket sClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8081);
            sClient.Connect(ipEndPoint);
            Byte[] _data = new byte[256];
            sClient.Receive(_data);
            int iLength = BitConverter.ToInt32(_data, 0);

            Byte[] _data2 = new byte[iLength];
            sClient.Receive(_data2);

            this.pictureBox1.Image = byteArrayToImage(_data2);

            sClient.Close();
        }

        /// <summary>
        /// 바이트를 image로
        /// https://www.codeproject.com/Articles/15460/C-Image-to-Byte-Array-and-Byte-Array-to-Image-Conv
        /// </summary>
        /// <param name="byteArrayIn"></param>
        /// <returns></returns>
        public Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }
    }
}

  

 

서버 가동

   이미지 읽어오기

   소켓서버 대기

 

클라이언트

   소켓연결 후 이미지 가져오기

 

순으로 동작시켜보면 됨

 

실행화면

 

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

[C#]PictureBox안에 있는 이미지 드래그로 이동시키기  (7) 2017.04.28
[C#] 화면스크린 갭쳐  (0) 2017.04.25
[C#]as is  (0) 2017.04.22
[C#]마지막 일자 구하기  (0) 2017.04.20
[C#]엑셀 컬럼 숫자 문자로 변환  (0) 2017.04.18
Posted by 유령회사
|

[C#]as is

프로그래밍/C# 2017. 4. 22. 00:35
반응형
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            object[] obj = new object[2];
            obj[0] = 1;
            obj[1] = "strValue";

            // is는 특정 객체 형변환이 가능한지 여부 확인         
            Console.WriteLine("Test  : " + (obj[0] is int));
            Console.WriteLine("Test  : " + (obj[0] is string));

            // as는 특정 객체 형변환이 가능하면 형변환객체를 불가능 하면 null을 반환한다.
            Console.WriteLine("Test  : " + ((obj[0] as string) == null ? "null" : obj[0]));
            Console.WriteLine("Test  : " + ((obj[1] as string) == null ? "null" : obj[1]));

            Console.Read();
        }
    }    
}

 

실행화면

 

Posted by 유령회사
|