달력

52024  이전 다음

  • 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
반응형


https://youtu.be/BmuS-XGP120


유튜브에 올린걸 참조해서 만듬


Form의 속성중 TransparencyKey가 있는데 이걸 설정해두면 해당 색상은 투명이 된다.


영상 링크 처럼 Panel추가 해서 색상을 설정한 뒤에 그 색상을 Form의 TransparencyKey에 설정한 뒤 



실행하면


이런 식으로 투명이 설정된다.

Posted by 유령회사
|
반응형

 

http://phantom00.tistory.com/14 

 

뎃글에 대한 답글입니다. 간단히 만든 소스코드라 오류가 많을듯 합니다. 프로그램 닫을때 오류가 존재합니다.


서버 

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace SendImage
{
    public partial class Form1 : Form
    {
        Socket sListener = null;
        List<Socket> clientList = new List<Socket>();
        Thread thread = null;
 
        public Form1()
        {
            InitializeComponent();
        }
 
        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;
 
                if (pictureBox1.InvokeRequired)
                {
                    pictureBox1.BeginInvoke(new Action(() => this.pictureBox1.ImageLocation = dia.FileName));
                }
                else
                {                 
                    this.pictureBox1.ImageLocation = dia.FileName;
                }
 
                foreach (var item in clientList)
                {
                    Byte[] _data = ImageToByteArray(this.pictureBox1.Image);
                    item.Send(BitConverter.GetBytes(_data.Length));
                    item.Send(_data);
                }
 
            }
        }
 
        /// <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();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            sListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 8081);
 
            sListener.Bind(ipEndPoint);
            sListener.Listen(20);
 
            thread = new Thread(() => {
                while (true)
                {
                    Socket sClient = sListener.Accept();
                    IPEndPoint ip = (IPEndPoint)sClient.RemoteEndPoint;
                    Console.WriteLine("주소 {0}에서 접속", ip.Address);
 
                    clientList.Add(sClient);
                }
            });
 
            thread.Start();
        }
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            sListener.Close();
        }
    }
}
 
cs


클라이언트

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace SendImage2
{
    public partial class Form1 : Form
    {
        Socket sClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);        
        List<Socket> clientList = new List<Socket>();
        Thread thread = null;
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8081);
            sClient.Connect(ipEndPoint);
 
            thread = new Thread(() => {
                while (true)
                {
                    Byte[] _data = new byte[256];
                    sClient.Receive(_data);
                    int iLength = BitConverter.ToInt32(_data, 0);
 
                    Byte[] _data2 = new byte[iLength];
                    sClient.Receive(_data2);
 
                    if (pictureBox1.InvokeRequired)
                    {
                        pictureBox1.BeginInvoke(new Action(() => pictureBox1.Image = byteArrayToImage(_data2)));
                    }
                    else
                    {
                        pictureBox1.Image = byteArrayToImage(_data2);
                    }
                }
            });
 
            thread.Start();
        }
 
        /// <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;
        }
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if(sClient != null) sClient.Close();
        }
    }
}
 
cs


저도 소켓을 잘쓰는 편이 아니라 100프로 정답이라고 하긴 그렇치만 대충 이런식으로 전송하면 될꺼 같아서 

소스 남겨드립니다.


클라이언트로 접속 후에 서버에서 파일하나씩 선택해보세요.

 

실행화면




 


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
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 LineComboBox : ComboBox
    {
        public LineComboBox()
        {
            InitializeComponent();
 
            this.DropDownStyle = ComboBoxStyle.DropDownList;
            this.DrawMode = DrawMode.OwnerDrawFixed;
        }
 
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if(e.Index < 0return;
            int startX = e.Bounds.Left + 5;
            int startY = (e.Bounds.Y + e.Bounds.Height / 2);
            int endX   = e.Bounds.Right - 5;
            int endY   = (e.Bounds.Y + e.Bounds.Height / 2);
            
            using (Pen p = new Pen(Color.Blue, (Int32)this.Items[e.Index]))
            {
                e.Graphics.DrawLine(p, new Point(startX, startY)
                                     , new Point(endX, endY));
            }
            
            base.OnDrawItem(e);
        }
 
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
        }
    }
}
 
cs


콤보박스를 상속받아서 코딩




이제 윈폼디자인 화면에서 컴파일을 하면 LineComboBox라는 컨트롤이 생성된다.



마지막으로 필요한 선두께를 넣어주면 끝~


Posted by 유령회사
|
반응형





Nuget에서 fontwesome을 검색해서 추가누르면 폰트를 넣어준다. 

웹에서 구해서 넣어도 상관은 없다 어차피 폰트 파일이니까...



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
56
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace shutdown
{
    public partial class Form1 : Form
    {
        PrivateFontCollection privateFonts;
 
        public Form1()
        {
            InitializeComponent();
            loadFont();
            setButton();
        }
 
        private void setButton()
        {
            this.button1.FlatStyle = FlatStyle.Flat;
            this.button1.FlatAppearance.BorderSize = 0;
 
            this.button1.Font = new Font(privateFonts.Families[0], 10f);
            this.button1.Text = UnicodeToChar("f011");
        }
 
        /// <summary>
        /// 폰트 로드
        /// </summary>
        private void loadFont()
        {
            privateFonts = new PrivateFontCollection();
            privateFonts.AddFontFile("./fonts/fontawesome-webfont.ttf"); // 폰트파일
        }
 
        /// <summary>
        /// 코드값 변환
        /// </summary>
        /// <param name="hex"></param>
        /// <returns></returns>
        private string UnicodeToChar(string hex)
        {
            int code = int.Parse(hex, System.Globalization.NumberStyles.HexNumber);
            string unicodeString = char.ConvertFromUtf32(code);
            return unicodeString;
        }
    }
}
 
cs



웹폰트는 벡터로 되어 있어서 확대하거나 축소해도 이미지보다 변형이 적다. 

요즘은 사용자들이 원캉 다양한 디바이스를 쓰니 이런거도 알아두면 좋을듯

머 현실은 저런 웹폰트 안쓰고 "닫기" 이런식으로 때우지만 ㅋ


https://fontawesome.com/icons?d=gallery&q=po

위 사이트에 가보면 여러 아이콘의 유니코드을 찾을수 있다. 

(위에서 사용한 f011 <-- 이런 아이콘마다 유니코드가 있다)

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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
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 Form1_Paint(object sender, PaintEventArgs e)
        {
            LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle
, Color.Green
, Color.GreenYellow
, 90f);
            e.Graphics.FillRectangle(brush, this.ClientRectangle);
        }
    }
}
 

cs


그라디에션을 적용할려면 

Graphics이걸 얻어와야 하기 때문에 각 컨트롤에 있는 Paint이벤트에서 가져오면 된다.

(여기서는 Form을 이용했지만 )


실행화면


Posted by 유령회사
|
반응형

일단은 System.Speech를 참조 추가하다.


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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace TextToSpeech
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            SpeechSynthesizer speechSynth = new SpeechSynthesizer();
            PromptBuilder builder = new PromptBuilder();
            builder.ClearContent();
            builder.AppendText(textBox1.Text);
            speechSynth.Speak(builder);
        }
    }
}
cs

실행화면

이건 소리로 출력되는거라 실행은 각자 자신의 윈도우에서 컴파일해보세요.

Posted by 유령회사
|
반응형

친애하시는 마소느님께서 닷넷플래임워크 4.5에 zip파일 생성하는 함수를 넣어주셨다.


https://msdn.microsoft.com/en-us/library/system.io.compression.zipfile_methods(v=vs.110).aspx


참조에 System.IO.Compression.FileSystem (in System.IO.Compression.FileSystem.dll) 파일을 넣으시고 


ZipFile을 사용하시면 됩니다. 마소링크를 따라가면 예제파일이 존재하므로 



Posted by 유령회사
|
반응형
1
2
3
4
5
6
7
8
9
        private bool RemoveDir(string sDirPath)
        {
            DirectoryInfo directory = new DirectoryInfo(sDirPath);
            directory.EnumerateFiles().ToList().ForEach(f => f.Delete());
            directory.EnumerateDirectories().ToList().ForEach(d => d.Delete(true));
            Directory.Delete(sDirPath, true);
 
            return true;
        }
cs


하위 파일 삭제하고 하위 디렉토리 삭제하고 현재 경로 삭제 처리해서 오류를 회피한다.

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

[C#] Text를 읽기  (0) 2018.03.01
[C#] zip파일 생성  (0) 2018.02.11
[C#]폼명(string)으로 화면 열기  (0) 2018.01.31
[C#]QR Code 생성, 읽기  (0) 2018.01.21
[C#]string에 여러공백을 한개의 공백으로 바꾸기  (0) 2017.11.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
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 WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            var form = Activator.CreateInstance(Type.GetType("WindowsFormsApp2.Form2")) as Form;
            form.ShowDialog();
        }
    }
}
 // Form2의 코딩은 아무것도 안해서 생략
cs


실행화면


Posted by 유령회사
|
반응형

Nuget에서 ZXing.Net를 가지고 만들었습니다.


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
56
57
58
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace QRCode
{
    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)
        {
            ZXing.BarcodeWriter barcodeWriter = new ZXing.BarcodeWriter();
            barcodeWriter.Format = ZXing.BarcodeFormat.QR_CODE;
            
            barcodeWriter.Options.Width  = this.pictureBox1.Width;
            barcodeWriter.Options.Height = this.pictureBox1.Height;
            
            string strQRCode = "QRCODE TEST"// 한글은 안되더라 ㅠ
                        
            this.pictureBox1.Image = barcodeWriter.Write(strQRCode);
            string deskPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);            
            barcodeWriter.Write(strQRCode).Save(deskPath + @"\test.jpg", ImageFormat.Jpeg);
        }
 
        /// <summary>
        /// 읽기
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            ZXing.BarcodeReader barcodeReader = new ZXing.BarcodeReader();            
            string deskPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
 
            var barcodeBitmap = (Bitmap)Image.FromFile(deskPath + @"\test.jpg");
            var result = barcodeReader.Decode(barcodeBitmap);
 
            this.textBox1.Text = result.Text;
        }
    }
}
 



cs
 실행화면



Posted by 유령회사
|