public static string GetMyIP()
        {
            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
            string myip = string.Empty;
            foreach (IPAddress ia in host.AddressList)
            {
                if (ia.AddressFamily == AddressFamily.InterNetwork)
                {
                    myip = ia.ToString();break; 
                }
            }
            return myip;
        }

 

private static string GetMacAddress(string ip) { string macAddress = null; System.Management.ObjectQuery query = new System.Management.ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'"); System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query); foreach (System.Management.ManagementObject obj in searcher.Get()) { string[] ipAddress = (string[])obj["IPAddress"]; if (ipAddress[0] == ip && obj["MACAddress"] != null) { macAddress = obj["MACAddress"].ToString(); break; } } return macAddress; }


 

'.Net > Winform' 카테고리의 다른 글

C# MS Chart  (2) 2012.08.30
C# ListView LargeIcon을 이용하여 Windows탐색기 효과내기  (2) 2012.08.29
C# Ping 확인  (0) 2012.08.28
C# 계정을 이용한 Directory Lock & Unlock  (0) 2012.08.28
C# ListView Headr Column Size 변경 막기  (0) 2012.08.28
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;

namespace Examples.System.Net.NetworkInformation.PingTest
{
    public class PingExample
    {
        // args[0] can be an IPaddress or host name.
        public static void Main (string[] args)
        {
            Ping pingSender = new Ping ();
            PingOptions options = new PingOptions ();

            // Use the default Ttl value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes (data);
            int timeout = 120;
            PingReply reply = pingSender.Send (args[0], timeout, buffer, options);
            if (reply.Status == IPStatus.Success)
            {
                Console.WriteLine ("Address: {0}", reply.Address.ToString ());
                Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
                Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
                Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
                Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
            }
        }
    }
}


 

 

 

http://msdn.microsoft.com/ko-kr/library/system.net.networkinformation.ping(v=VS.85).aspx

        /// <summary>
        /// Directory의 잠금을 해제합니다.
        /// </summary>
        /// <param name="folderPath"></param>
        private static void UnLock(string folderPath)
        {
            try
            {
                string adminUserName = Environment.UserName;// getting your adminUserName
                System.Security.AccessControl.DirectorySecurity ds = System.IO.Directory.GetAccessControl(folderPath);
                System.Security.AccessControl.FileSystemAccessRule fsa = new System.Security.AccessControl.FileSystemAccessRule(adminUserName,
                    System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Deny);

                ds.RemoveAccessRule(fsa);
                System.IO.Directory.SetAccessControl(folderPath, ds);
            }
            catch (Exception ex)
            {
            }

        }

        /// <summary>
        /// Directory를 잠급니다.
        /// </summary>
        /// <param name="folderPath"></param>
        private static void Lock(string folderPath)
        {
            try
            {
                string adminUserName = Environment.UserName;// getting your adminUserName
                System.Security.AccessControl.DirectorySecurity ds = System.IO.Directory.GetAccessControl(folderPath);
                System.Security.AccessControl.FileSystemAccessRule fsa = new System.Security.AccessControl.FileSystemAccessRule(adminUserName,
                    System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Deny);

                ds.AddAccessRule(fsa);
                System.IO.Directory.SetAccessControl(folderPath, ds);

            }
            catch (Exception ex)
            {
            }
        }


 

'.Net > Winform' 카테고리의 다른 글

C# 자신의 IP 및 MAC ADRESS 확인하기  (0) 2012.08.29
C# Ping 확인  (0) 2012.08.28
C# ListView Headr Column Size 변경 막기  (0) 2012.08.28
C# Excel 작성  (0) 2012.08.28
C# 리소스 언어 설정  (0) 2012.08.22
        public Form1()
        {
            InitializeComponent();
            this.listView1.ColumnWidthChanging+=new ColumnWidthChangingEventHandler(listView1_ColumnWidthChanging);
        }

        void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
        {
            ListView listView = sender as ListView;
            if (listView != null)
            {
                e.NewWidth = listView.Columns[e.ColumnIndex].Width;
                e.Cancel = true;
            }
        }

 

'.Net > Winform' 카테고리의 다른 글

C# Ping 확인  (0) 2012.08.28
C# 계정을 이용한 Directory Lock & Unlock  (0) 2012.08.28
C# Excel 작성  (0) 2012.08.28
C# 리소스 언어 설정  (0) 2012.08.22
C# DirectX.AudioVideoPlayback 을 이용한 동영상 재생  (11) 2012.08.21

Visual Studio 2008, 닷넷프레임워크 2.0 기반에서 작성하였습니다.

 

 

테스트 용 콘솔  프로젝트 하나 생성하였습니다.

 

닷넷 프레임워크의 VSTO를 사용하기 위해선

 Microsoft.Office.Interop.Excel

참조 추가해주어야합니다.

 

[이미지 1]  Microsoft.Office.Interop.Excel 참조 추가

 


코드 부분입니다.

간단히 엑셀의 [1,1]에 테스트라는 문자열을 입력하였습니다.

엑셀은 배열로 접근 할 때, 0부터 시작이 아닌 1부터 시작입니다.

작업을 하신 후에는 꼭 메모리를 해제 시켜주셔야

Excel이 정상적으로 종료됩니다.

이 작업을 하지 않으실 경우에 작업 관리자에 Excel이 남아 있게 됩니다.

 

AboutExcel.zip

 

 

using System;
using System.Collections.Generic;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;

namespace AboutExcel
{
    class Program
    {
        static void Main(string[] args)
        {
            AboutExcelWrite();
        }

        /// <summary>
        /// Excel에 작성하는 방법에 대해 설명할 메소드입니다.
        /// </summary>
        private static void AboutExcelWrite()
        {
            Excel.Application excelApp = new Excel.Application();
            Excel.Workbook wb = excelApp.Workbooks.Add(true);
            Excel._Worksheet workSheet = wb.Worksheets.get_Item(1) as Excel._Worksheet;


            //엑셀은 맨처음 Cell이 1,1 입니다      0,0이 아닙니다
            workSheet.Cells[1, 1] = "테스트";


            ExcelDispose(excelApp, wb, workSheet);
        }


        /// <summary>
        /// 저장및 메모리 해제
        /// </summary>
        /// <param name="excelApp"></param>
        /// <param name="wb"></param>
        /// <param name="workSheet"></param>
        public static void ExcelDispose(Excel.Application excelApp, Excel.Workbook wb, Excel._Worksheet workSheet)
        {
            wb.SaveAs(@"E:\Program\etc\C#\About\AboutExcel\bin\Debug\test.xls", Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
                Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            wb.Close(Type.Missing, Type.Missing, Type.Missing);
            excelApp.Quit();
            releaseObject(excelApp);
            releaseObject(workSheet);
            releaseObject(wb);
        }

        #region 메모리해제
        private static void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception e)
            {
                obj = null;
            }
            finally
            {
                GC.Collect();
            }
        }
        #endregion
    }
}


 

 

 

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo( "en-US" );
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "en-US" );


 

 

 

영어로 설정할 경우

 

            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo( "en-US" );
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "en-US" );
            try
            {
                throw new InvalidCastException();
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message);
            }

 


 

 

 

 

 

한글로 설정할 경우

 

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo( "ko-KR" ); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "ko-KR" ); try { throw new InvalidCastException(); } catch(Exception e) { MessageBox.Show(e.Message); }

 

 

 


 

'.Net > Winform' 카테고리의 다른 글

C# ListView Headr Column Size 변경 막기  (0) 2012.08.28
C# Excel 작성  (0) 2012.08.28
C# DirectX.AudioVideoPlayback 을 이용한 동영상 재생  (11) 2012.08.21
C# 중복 실행 방지 Mutex  (0) 2012.08.14
C# DragDrop & DragEnter  (0) 2012.08.10

 

예제를 위한 프로젝트입니다.

 

 

 

 

디자이너를 이용해 패널과 버튼 3개를 만들었습니다.

 

 

 

 

 

 

 

Microsoft.DirectX.AudioVideoPlayback 참조 추가하여줍니다.

 

 

DirectX가 보이지 않을 시에 설치해주세요.

http://www.microsoft.com/en-us/download/details.aspx?id=4064

 

 

 

 

 

 

 

 

 

 

Form cs 코드입니다.

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

namespace HowToVideoPlayer
{
    public partial class Form1 : Form
    {
        Microsoft.DirectX.AudioVideoPlayback.Video video;
        public Form1()
        {
            InitializeComponent();
            Init();
        }

        private void Init()
        {
            OpenFileDialog of = new OpenFileDialog();
            if (of.ShowDialog() == DialogResult.OK)
            {
                video = new Microsoft.DirectX.AudioVideoPlayback.Video(of.FileName);
                video.Owner = this.panel;
                video.Size = this.panel.Size;
            }
        }

        private void button_play_Click(object sender, EventArgs e)
        {
            if(video!=null)
                video.Play();
        }

        private void button_pause_Click(object sender, EventArgs e)
        {
            if (video != null)
                video.Pause();
        }

        private void button_stop_Click(object sender, EventArgs e)
        {
            if (video != null)
                video.Stop();
        }
    }
}


 

 

 

 

 

 

 

 

 

실행 시 위와 같은 LoaderLock Exception이 발생한다면 아래와 같이 설정해줍니다.

 

 

 

 

 

 

 

 

 

 

디버그->예외

LoaderLock 체크해제

 

 

 

 

 

 

 

 

 

 

 

Play화면입니다.

 

 

 

 

 

 

 

HowToVideoPlayer.zip

 

 

'.Net > Winform' 카테고리의 다른 글

C# Excel 작성  (0) 2012.08.28
C# 리소스 언어 설정  (0) 2012.08.22
C# 중복 실행 방지 Mutex  (0) 2012.08.14
C# DragDrop & DragEnter  (0) 2012.08.10
C# 디버깅 파일인지 아닌지 체크  (0) 2012.08.10

   static class Program
    {
        /// <summary>
        /// 해당 응용 프로그램의 주 진입점입니다.
        /// </summary>
        [STAThread]
        static void Main()

        {

           bool isCreatedNew;
            System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out isCreatedNew);

            if (isCreatedNew)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FormMain());
                mutex.ReleaseMutex();
            }
        }
      }

 

'.Net > Winform' 카테고리의 다른 글

C# 리소스 언어 설정  (0) 2012.08.22
C# DirectX.AudioVideoPlayback 을 이용한 동영상 재생  (11) 2012.08.21
C# DragDrop & DragEnter  (0) 2012.08.10
C# 디버깅 파일인지 아닌지 체크  (0) 2012.08.10
C# TextBox 실수만 입력받기  (0) 2012.08.08
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] datas = (string[])e.Data.GetData(DataFormats.FileDrop);            
        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
        }


 

        private bool IsAssemblyDebugBuild(string filepath) 
        {
            return IsAssemblyDebugBuild(System.Reflection.Assembly.LoadFile(System.IO.Path.GetFullPath(filepath))); 
        }
        private bool IsAssemblyDebugBuild(System.Reflection.Assembly assembly) 
        {
            foreach (var attribute in assembly.GetCustomAttributes(false)) 
            {
                var debuggableAttribute = attribute as System.Diagnostics.DebuggableAttribute; 
                if (debuggableAttribute != null) 
                {
                    return debuggableAttribute.IsJITTrackingEnabled;
                } 
            } 
            return false; 
        }

 

'.Net > Winform' 카테고리의 다른 글

C# 중복 실행 방지 Mutex  (0) 2012.08.14
C# DragDrop & DragEnter  (0) 2012.08.10
C# TextBox 실수만 입력받기  (0) 2012.08.08
C# Winform에서 Cookie 설정 및 가져오기  (0) 2012.08.07
C# 알림창 폼  (0) 2012.08.07

+ Recent posts