반응형

* C# String 을 이진수로 이진수를 String 으로 변환 예제...

 

 

- 사용한 컨트롤 : Button 2개, Label 2개, TextBox 1개

 

전체 소스 코드

Form1.cs

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 CSharp_StringTo2진수
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "") return;
            //String To 2진수
            byte[] btBytes = UnicodeEncoding.Unicode.GetBytes(textBox1.Text );
            string strbinary = string.Empty;

            foreach (byte b in btBytes)
            {
                // byte를 2진수 문자열로 변경
                string strTmp = Convert.ToString(b, 2);
                strbinary += strTmp.PadLeft(8, '0');
            }

            label1.Text = strbinary; 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //2진수 To String
            if (label1.Text == "") return;

            int ibytes = label1.Text.Length  / 8;
            byte[] btOutBytes = new byte[ibytes];

            for (int i = 0; i < ibytes; i++)
            {
                // 8자리 숫자 즉 1바이트 문자열 얻기
                string strBin = label1.Text.Substring(i * 8, 8);
                // 2진수 문자열을 숫자로 변경
                btOutBytes[i] = (byte)Convert.ToInt32(strBin, 2);
            }

            // Unicode 인코딩으로 바이트를 문자열로
            string strResult = UnicodeEncoding.Unicode.GetString(btOutBytes);
            label2.Text = strResult;
        }
    }
}

 

 

* 예제 결과

 

반응형
반응형

* VBNET Encoding Class 를 이용한 유니코드(한글) 문자열 존재 여부 예제...

 

Main

 

 

- 사용한 컨트롤 : Button 1개, TextBox 1개, Label 1개

 

전체 소스 코드

Form1.vb

 


Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        If textBox1.Text = "" Then
            Return
        End If

        Dim iAscii As Integer = System.Text.Encoding.ASCII.GetByteCount(textBox1.Text)
        Dim iUnicode As Integer = System.Text.Encoding.UTF8.GetByteCount(textBox1.Text)

        '같지 않으면...
        If iAscii <> iUnicode Then
            label1.Text = "Unicode 가 존재 합니다."
        Else
            label1.Text = "Unicode 가 존재 하지 않습니다."
        End If
    End Sub

End Class

 

 

*예제 결과

 

 

 

https://kdsoft-zeros.tistory.com/198

 

[C#] Encoding Class - 유니코드 문자열 존재 여부

* C# Encoding Class 를 이용한 유니코드(한글) 문자열 존재 여부 예제... - 사용한 컨트롤 : Button 1개, TextBox 1개, Label 1개 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; us..

kdsoft-zeros.tistory.com

 

반응형
반응형

* C# Encoding Class 를 이용한 유니코드(한글) 문자열 존재 여부 예제...

 

Main

 

- 사용한 컨트롤 : Button 1개, TextBox 1개, Label 1개

 

전체 소스 코드

Form1.cs

 

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 CSharp_IsUnicode
{
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "") return;

            int iAscii = Encoding.ASCII.GetByteCount(textBox1.Text );
            int iUnicode = Encoding.UTF8.GetByteCount(textBox1.Text );

            //같지 않으면...
            if (iAscii != iUnicode)
            {
                label1.Text = "Unicode 가 존재 합니다.";
            }
            else
            {
                label1.Text = "Unicode 가 존재 하지 않습니다.";
            }

        }
    }
}

 

 

*예제 결과

 

 

 

 

https://kdsoft-zeros.tistory.com/199

 

[VBNET] Encoding Class - 유니코드 문자열 존재 여부

* VBNET Encoding Class 를 이용한 유니코드(한글) 문자열 존재 여부 예제... - 사용한 컨트롤 : Button 1개, TextBox 1개, Label 1개 전체 소스 코드 Form1.vb Public Class Form1 Private Sub button1_Click(By..

kdsoft-zeros.tistory.com

 

반응형
반응형

* C# API 를 이용한 Form 애니메이션 효과 예제...

 

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;

using System.Runtime.InteropServices;

namespace CSharp_Animate
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        public static extern int AnimateWindow(IntPtr windowHandle, int animationTime, int animateWindowType);

 
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            //CENTER
            Form2 frm = new Form2();
            int AW_CENTER = 0x10;
            AnimateWindow(frm.Handle, 1000, AW_CENTER);

        }

        private void Button2_Click(object sender, EventArgs e)
        {
            //HOR_POSITIVE
            Form2 frm = new Form2();
            int AW_HOR_POSITIVE = 0x01;
            AnimateWindow(frm.Handle, 1000, AW_HOR_POSITIVE);
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            //VER_POSITIVE
            Form2 frm = new Form2();
            int AW_VER_POSITIVE = 0x04;
            AnimateWindow(frm.Handle, 1000, AW_VER_POSITIVE);
        }
    }
}

 

반응형
반응형

 

* VBNET API 를 이용한 Form 생성 시 효과 나타 내기

 

 

Public Class Form1
    Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Integer, ByVal dwTime As Integer, ByVal dwFlags As Integer) As Boolean
    Const AW_HOR_POSITIVE = &H1 'Animates the window from left to right. This flag can be used with roll or slide animation.
    Const AW_HOR_NEGATIVE = &H2 'Animates the window from right to left. This flag can be used with roll or slide animation.
    Const AW_VER_POSITIVE = &H4 'Animates the window from top to bottom. This flag can be used with roll or slide animation.
    Const AW_VER_NEGATIVE = &H8 'Animates the window from bottom to top. This flag can be used with roll or slide animation.
    Const AW_CENTER = &H10 'Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
    Const AW_HIDE = &H10000 'Hides the window. By default, the window is shown.
    Const AW_ACTIVATE = &H20000 'Activates the window.
    Const AW_SLIDE = &H40000 'Uses slide animation. By default, roll animation is used.
    Const AW_BLEND = &H80000


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Center
        Dim frm As Form2 = New Form2()
        AnimateWindow(frm.Handle.ToInt32, 1000, AW_CENTER)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'AW_HOR_POSITIVE
        Dim frm As Form2 = New Form2()
        AnimateWindow(frm.Handle.ToInt32, 1000, AW_HOR_POSITIVE)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'AW_VER_POSITIVE
        Dim frm As Form2 = New Form2()
        AnimateWindow(frm.Handle.ToInt32, 1000, AW_VER_POSITIVE)
    End Sub
End Class
반응형
반응형

*C# PC 사용 시간 얻어 오기 예제...

 

Main

 

- 사용한 컨트롤 : Button 1개, Label 1개

 

전체 소스 코드 

From1.cs


Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        Try

            Using pc As PerformanceCounter = New PerformanceCounter("System", "System Up Time")
                pc.NextValue()
                label1.Text = TimeSpan.FromSeconds(pc.NextValue()).ToString()
            End Using

        Catch ex As Exception
            label1.Text = "00:00:00"
        End Try
    End Sub
End Class

 

*예제 결과

 

 

 

https://kdsoft-zeros.tistory.com/194

 

[C#] PC 사용 시간 얻어 오기 (PC Use Time)

*C# PC 사용 시간 얻어 오기 예제... - 사용한 컨트롤 : Button 1개, Label 1개 전체 소스 코드 From1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; us..

kdsoft-zeros.tistory.com

 

반응형
반응형

*C# PC 사용 시간 얻어 오기 예제...

 

Main

 

- 사용한 컨트롤 : Button 1개, Label 1개

 

전체 소스 코드 

From1.cs

 

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;

using System.Diagnostics;

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

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                using (PerformanceCounter pc = new PerformanceCounter("System", "System Up Time"))
                {
                    pc.NextValue();
                    label1.Text = TimeSpan.FromSeconds(pc.NextValue()).ToString();
                }

            }

            catch
            {
                label1.Text = "00:00:00";
            }

        }
    }
}

 

 

 

*예제 결과

 

 

https://kdsoft-zeros.tistory.com/195

 

[VBNET] PC 사용 시간 얻어 오기 (PC Use Time)

*C# PC 사용 시간 얻어 오기 예제... - 사용한 컨트롤 : Button 1개, Label 1개 전체 소스 코드 From1.cs Public Class Form1 Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.Even..

kdsoft-zeros.tistory.com

 

반응형
반응형

*VBNET API 를 이용한 Wav 파일 재생 예제...

 

 

- 사용한 컨트롤 : Button 3개, Label 1개

 

전체 소스 코드

Form1.vb

 

Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1

    <DllImport("winmm.dll")> _
    Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
    End Function

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'File Open
        Dim ofd As OpenFileDialog = New OpenFileDialog

        ofd.Filter = "WAV File(*.wav) | *.wav"

        If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            label1.Text = ofd.FileName
        End If

    End Sub



    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        'Play
        If Not System.IO.File.Exists(label1.Text) Then
            Return
        End If

        mciSendString("open """ + label1.Text + """ type mpegvideo alias MediaFile", Nothing, 0, IntPtr.Zero)
        mciSendString("play MediaFile", Nothing, 0, IntPtr.Zero)

    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
        'Stop
        mciSendString("Close MediaFile", Nothing, 0, IntPtr.Zero)
    End Sub
End Class

 

 

*예제 결과

 

 

 

https://kdsoft-zeros.tistory.com/192

 

[C#] API mciSendString - WAV 파일 재생

*C# API 를 이용한 Wav 파일 재생 예제... - 사용한 컨트롤 : Button 3개, Label 1개 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Dat..

kdsoft-zeros.tistory.com

 

반응형

+ Recent posts