顯示具有 C# 標籤的文章。 顯示所有文章
顯示具有 C# 標籤的文章。 顯示所有文章

2012年5月2日 星期三

[C#] Windows FireWall 防火牆操作

防火牆的控制。

     功能

  1. -添加防火牆例外端口
  2. -將應用程序添加到防火牆例外
  3. -刪除防火牆例外端口
  4. -刪除防火牆例外中應用程序

按我下載類別

2012年3月26日 星期一

[C#] IP,Ping

CMD 下的 Ping 工具一直是很簡便的 網路連線偵測工具,本範例是使用

Net.framework 2 的 Ping 類別 來達成目的。

 

專案下載

KM-000

private void button1_Click(object sender, EventArgs e)
        {
            Ping p1 = new Ping();
            p1.PingCompleted += new PingCompletedEventHandler(this.PingCompletedCallBack);
            if (textBox1.Text.Trim().Length == 0)
            {
                return;
            }
            p1.SendAsync(textBox1.Text.Trim(), null);
        }

private void PingCompletedCallBack(object sender, PingCompletedEventArgs e)
        {
            listBox1.Items.Clear();

            if (e.Cancelled)
            {
                listBox1.Items.Add("Ping Canncel");
                return;
            }

            if (e.Error != null)
            {
                listBox1.Items.Add("e.Error.Message");
                return;
            }

            PingReply reply = e.Reply;
            listBox1.Items.Add(reply.Address + " " + reply.Status.ToString());
            if (reply.Status == IPStatus.Success)
            {
                listBox1.Items.Add("RoundTrip time:" + reply.RoundtripTime);
                listBox1.Items.Add("Time to live:"+reply.Options.Ttl);
                listBox1.Items.Add("Don't fragment:"+reply.Options.DontFragment);
                listBox1.Items.Add("Buffer size:"+reply.Buffer.Length);
            }
        }

2012年3月6日 星期二

[C#] MailMessage,SmtpClient,寄信,E-Mail


使用 smtpClient 送信

//引用
using System.Net.Mail;
using System.Net.Mime;

//主要方法
 public void send_email(string msg, string mysubject, string address)
        {
            MailMessage message = new MailMessage(test@123.co.jp, address);//MailMessage(寄信者, 收信者)
            message.IsBodyHtml = true;
            message.BodyEncoding = System.Text.Encoding.UTF8;//E-mail編碼
            message.Subject = mysubject;//E-mail主旨
            message.Priority = MailPriority.Normal; //優先權
            message.Body = msg;//E-mail內容
            string file_name = @"C:\Users\km\Desktop\fdkbc.xls"; //要寄送的添付檔案
            Attachment data = new Attachment(file_name, MediaTypeNames.Application.Octet);
            ContentDisposition disposition = data.ContentDisposition;
            disposition.CreationDate = System.IO.File.GetCreationTime(file_name);
            disposition.ModificationDate = System.IO.File.GetLastWriteTime(file_name);
            disposition.ReadDate = System.IO.File.GetLastAccessTime(file_name);
            message.Attachments.Add(data);
            SmtpClient smtpClient = new SmtpClient("172.23.120.254", 25);//設定E-mail Server和port
            smtpClient.Send(message);
        }

//使用方法
 send_email("測試內容", "測試主旨標題", "mailto:kuomingwang@gmail.com%22);//呼叫send_email函式測試

2012年1月18日 星期三

[C#] 防止多開的2個處理方法

方法1:
 //直接砍 Process
  System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName(Application.ProductName);
            if (p.Length > 1)
            {
                for (int i = 0; i < p.Length; i++)
                {
                    p[i].Kill();
                }
            }

方法2:

//宣告
        [DllImport("kernel32.dll", EntryPoint = "CreateMutexA", SetLastError = true)]
        public static extern IntPtr CreateMutex(IntPtr securityAttributes, bool initialOwner, string name);
        [DllImport("kernel32.dll", EntryPoint = "ReleaseMutex", SetLastError = true)]
        public static extern IntPtr ReleaseMutex(IntPtr handle);

        public static bool IsMutexDataExist(string name)
        {
            bool returnValue = false;
            int ERROR_ALREADY_EXISTS = 183;
            IntPtr handle = CreateMutex(IntPtr.Zero, true, name);
            if (Marshal.GetLastWin32Error() == ERROR_ALREADY_EXISTS)
            {
                returnValue = true;
            }
            ReleaseMutex(handle);
            return returnValue;
        }

//使用方法
             if (IsMutexDataExist("BetWorldAuthServer") == true)
            {
                //MessageBox.Show("已經在執行中", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Environment.Exit(0);
            }

2011年12月21日 星期三

[C#] 控制 WinForm 顯示於延伸視窗(延伸顯示器)、雙螢幕

有個需求是 必須要指定某個 WinForm 開啟於 延伸視窗



那個該如何讓 程式 開啟的時候 直接顯示於 延伸顯示器呢?
請在 Form1.Designer.cs 內追加 即可。
DesktopLocation 裡面的 X 的值 請務必大於 本機顯示器的 X 解析度.


2011年12月20日 星期二

[C#] 使用 ZedGraph Chart 來製作圖表(開源控件)

由於工作單位裡面老舊電腦比較多(還有一些是 Windows 2000)
所以 Net.Framework 只能使用到 2.0 版本。

需求是 必須產生即時線圖,比較過幾種開源控件,最終採用 ZedGraph

完整專案下載

使用效果











//首先要加入參考 ZedGraph


               GraphPane myPane = null;
                myPane = zg1.GraphPane;
                myPane.CurveList.Clear();
                myPane.GraphObjList.Clear();
                //資料來源 處理
                int[] x = { 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
                int[] y = { 100, 50, 20, 70, 20, 100, 50, 20, 70, 20, 100, 50, 20, 70, 20, 100, 50, 20, 70, 20, 100, 50, 20, 70};
                //資料填充
                PointPairList list = new PointPairList();
                list.Clear();
                for (int i = 0; i < x.Length; i++)
                {
                    list.Add(x[i], y[i]);
                }
                //圖形建立
                BarItem myCurve = myPane.AddBar("作業 OK品 實積", list, Color.Blue);  //建立長條圖
                //BarItem.CreateBarLabels(myPane, false, "f0"); //每個長條圖 都顯示個別數據
                //介面屬性處理
                myPane.Title.IsVisible = false; //主標題是否 顯示
                //myPane.Title.Text = "Emp"; //主標題
                myPane.Title.FontSpec.FontColor = Color.Green;
                myPane.XAxis.Title.IsVisible = false; //X軸 是否顯示 title
                //myPane.XAxis.Title.Text = "Hr"; //X 軸 Title
                //myPane.XAxis.Title.FontSpec.Size = 40; //X 軸 Title 文字Size
                string[] xx = { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" };
                myPane.XAxis.Scale.TextLabels = xx; //X軸刻度資料來源
                myPane.XAxis.Type = AxisType.Text; //X軸刻度資料型態
                myPane.XAxis.Scale.FontSpec.Size = 25;
                //myPane.XAxis.MajorGrid.IsVisible = true; //顯示格點
                //myPane.XAxis.MajorGrid.Color = Color.Pink; //格點顏色
                myPane.YAxis.Title.Text = "Pcs"; //Y 軸的 Title
                myPane.YAxis.Title.FontSpec.Size = 25;
                myPane.YAxis.Scale.FontSpec.Size = 25;
                myPane.YAxis.MajorGrid.IsVisible = true;
                myPane.YAxis.MajorGrid.Color = Color.Black;
                //myPane.YAxis.Scale.MajorStep = 10; //Y軸資料 間隔
                //myPane.YAxis.Scale.Max = 120; //Y軸 最大值
                myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, -45F); //Chart 填色
                myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), -45F); //外部 填色
                myPane.Legend.Position = ZedGraph.LegendPos.InsideTopRight; //圖例放置位置
                myPane.Legend.FontSpec.Size = 20;
                //畫面產生
                zg1.AxisChange();
                //重要! 若資料有變更時 畫面重整
                zg1.RestoreScale(myPane);



#相關網站:
1.)Think專欄  介紹一些常用函數。
2.)oayx 一些使用說明及資源。
3.)Codeproject 開源Project

 

[C#] 取得電腦名稱、變更電腦名稱、重新開機

因為要管理的電腦太多,雖然已經使用 IP、Terminal 來管理
但是還是常常找不到 電腦再哪裡?  所以準備使用 電腦名稱來管理。

完整原始碼下載















//取得電腦名稱
System.Windows.Forms.SystemInformation.ComputerName

//變更電腦名稱
 [DllImport("kernel32.dll")]
 static extern bool SetComputerName(string lpComputerName);
 [DllImport("kernel32.dll")]
 static extern bool SetComputerNameEx(_COMPUTER_NAME_FORMAT iType, string lpComputerName);


 enum _COMPUTER_NAME_FORMAT
            {
                ComputerNameNetBIOS,
                ComputerNameDnsHostname,
                ComputerNameDnsDomain,
                ComputerNameDnsFullyQualified,
                ComputerNamePhysicalNetBIOS,
                ComputerNamePhysicalDnsHostname,
                ComputerNamePhysicalDnsDomain,
                ComputerNamePhysicalDnsFullyQualified,
                ComputerNameMax
            };


        private void button1_Click(object sender, EventArgs e)
        {
            string MachineName = txt_New_PCName.Text.Trim();
            if (MachineName.Length == 0)
            {
                button1.Text = "NG";
                 return;
            }

            bool succeeded = SetComputerName(MachineName);
            bool succeeded2 = SetComputerNameEx(_COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, MachineName);

            if (succeeded && succeeded2)
            {
                button1.Text = "OK,請重開機!";
                btn_Restrate.Visible = true;
            }
            else
            {
                button1.Text="NG";
            }
        }



//重新開機
         private void btn_Restrate_Click(object sender, EventArgs e)
        {
            try
            {
                ManagementClass mmc = new ManagementClass("Win32_OperatingSystem");
                mmc.Scope.Options.EnablePrivileges = true; //取得作業系統使用者權限
                foreach (ManagementObject mo in mmc.GetInstances())
                {
                    mo.InvokeMethod("Reboot", null, null); //呼叫一般重新啟動
                }
                mmc.Dispose();
            }
            catch (Exception Q)
            {
                MessageBox.Show(Q.Message);
            }
        }

2011年11月22日 星期二

[C#] 將 Dictionary 內資料 綁定至 ComboBox


將容器 Dictionary 內資料,綁定至 ComboBox 內

//宣告變數
            private Dictionary<string, string> Lang = new Dictionary<string, string>();

//使用
            //先清空,然後增加資料
            Lang.Clear();
            Lang.Add("zh-CHT","Chinese (Traditional)");
            Lang.Add("en", "English");
            Lang.Add("ja","Japanese");

            //資料綁定
            cmbT.DataSource = new BindingSource(Lang, null);
            cmbT.DisplayMember = "value";
            cmbT.ValueMember = "key";
            cmbT.SelectedIndex = 0;




[C#] 運用微軟API 線上翻譯

因為之前 Google 線上翻譯 API 常常無法連線,所以使用 Microsoft TransLate API
來進行翻譯,採用 SOAP 方式來實做,能自動判斷要翻譯的文字 是哪一國語言
,再搭配 熱鍵 的註冊 使用,很方便。


按我下載測試使用


//申請開發者ID
請至 Bing API  這裡 登入帳號密碼,點選 開發人員 --> 點選 Add 新增  Application
填入各項 必要資訊後,會拿到1組 Application ID (把這個ID紀錄起來)

//MSDN參考資料
這裡 有提供相關 使用方式。

//建立專案, 並加入 Web 參考(Web Service)

//使用
string res = Km.Translate("剛剛申請的AppID", "要翻譯的文字", "來源文字語系", "要翻譯的語系", "text/html", "general");

一行就搞定,試試看吧!

目前功能:
1.)會自動判斷 要翻譯的文字語系。
2.)支援熱鍵 Ctrl + Q ,將要翻譯的文字反白選擇後,按熱鍵會自動翻譯。
3.)翻譯結果 僅支援 繁體中文、英文、日文

2011年11月18日 星期五

[C#] 讓電腦說話 Speech SDK

在製造現場作業 工作站裡,每個作業操作流程 都會產生 通知訊息
例如: OK  、NG、混料 、作業No 錯誤 .. 等等

先前的作法是,依據 各個訊息 錄製對應的 Wav 檔案來播放
目前嘗試使用 SDK 來自動播放語音。

若安裝 基本SDK 只能播放 英文語音,若要 念中文 則需要額外安裝 LangPack


//引用
using SpeechLib;

//使用
        private void button1_Click(object sender, EventArgs e)
        {
            SpeechVoiceSpeakFlags SP = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice Voice = new SpVoice();
            Voice.AllowAudioOutputFormatChangesOnNextSet = true;
            Voice.Rate = -3; // 速度 +- 100
            Voice.Volume = 100; //音量 0~100
            Voice.Speak("Good Job", SP);  //念出 Good Job
        }



下載 範例 Source Code  檔案




Quick links

The links in this section correspond to files available for this download.
Download the files appropriate for you.
File NameSize
msttss22L.exe1.0 MBDownload
sapi.chm2.0 MBDownload
Sp5TTIntXP.exe3.0 MBDownload
SpeechSDK51.exe67.0 MBDownload
SpeechSDK51LangPack.exe81.0 MBDownload
SpeechSDK51MSM.exe131.0 MBDownload

Important File Download Details
  • If you want to download sample code, documentation, SAPI, and the U.S. English Speech engines for development purposes, download the Speech SDK 5.1 file (SpeechSDK51.exe).

  • If you want to use the Japanese and Simplified Chinese engines for development purposes, download the Speech SDK 5.1 Language Pack file (SpeechSDK51LangPack.exe) in addition to the Speech SDK 5.1 file.

  • If you want to redistribute the Speech API and/or the Speech engines to integrate and ship as a part of your product, download the Speech 5.1 SDK Redistributables file (SpeechSDK51MSM.exe).

  • If you want to get only the Mike and Mary voices redistributable for Windows XP, download Mike and Mary redistributables (Sp5TTIntXP.exe).

  • If you only want the documentation, download the Documentation file (sapi.chm).

2011年11月16日 星期三

[C#] KMAudioDown MU空間 MP3 下載 [0.0.0.5]

針對 MU 免空 ,將近期MP3 壓縮檔 下載。

MP3 僅為試聽使用,請下載後刪除。
請購買正版音樂光碟。

檔案下載後請解壓縮後,執行。 (檔案下載)

Ps. 若無法執行檔案,請安裝 .Net Framework 2.0 環境 (下載)


--版本更新 0.0.0.5 --
1.免空改版對應,請自行等候讀秒,點選普通下載
--版本更新 0.0.0.4 --
1.變更連結方式
--版本更新 0.0.0.3 --
1.修正正確網址
--版本更新 0.0.0.2 --
1.修復無效字串
2.追加 檢測新版本連結



2011年11月14日 星期一

[C#] 製程能力指標 Cpk 計算

在做統計的時候都會使用到.

這裡是採用新式計算方式, 判斷 CpkU 、CpkL 取數值比較小的
Math.Abs(Math.Min(CpkU, CpkL));

其中 CpkU、CpkL 的公式如下:
CpkU=(USL-平均值) / 3*標準差
CPkL=(平均值-LSL) / 3*標準差

其中 USL、LSL 定義:
USL:規格上限
LSL:規格下限
Source Code 下載

2011年11月11日 星期五

[C#] UNC 網路芳鄰連接 含帳號密碼 [使用WindowsIdentity方法]

之前有寫過 UNC 連接,但是是採用 CMD 模式 請見

[C#] UNC 網路芳鄰連接 含帳號密碼


這一次因為是要在 IIS 上執行,所以改採用 WindowsIdentity 來作業.

按我下載 SourceCode

//首先
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Security.Principal;

//追加 namespace 上方
[assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum, UnmanagedCode = true)]
[assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, Name = "FullTrust")]

//Dll
        [DllImport("advapi32.dll", SetLastError = true)]
        public static extern bool LogonUser(
           string lpszUsername,
           string lpszDomain,
           string lpszPassword,
           int dwLogonType,
           int dwLogonProvider,
           ref IntPtr phToken);
      
        [DllImport("kernel32.dll")]
        public extern static bool CloseHandle(IntPtr hToken);


  public class Connect_Net
    {
        public string Server_IP
        {
            get;
            set;
        }
        public string UserNmae
        {
            get;
            set;
        }
        public string Password
        {
            get;
            set;
        }
    }



         private void button1_Click(object sender, EventArgs e)
        {
            Connect_Net z = new Connect_Net();
            z.UserNmae = "ftpuser";
            z.Password= "ftpuser";
            z.Server_IP = "172.23.108.157";

            string IPath = @"\\" + z.Server_IP + @"\ftp";
            const int LOGON32_PROVIDER_DEFAULT = 0;
            const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
            IntPtr tokenHandle = new IntPtr(0);
            tokenHandle = IntPtr.Zero;
            bool returnValue = LogonUser(z.UserNmae, z.Server_IP, z.Password,
            LOGON32_LOGON_NEW_CREDENTIALS,
            LOGON32_PROVIDER_DEFAULT,
            ref tokenHandle);
            WindowsIdentity w = new WindowsIdentity(tokenHandle);
            System.Security.Principal.WindowsImpersonationContext kk =  w.Impersonate();
            if (false == returnValue)
            {
                return;
            }
        
            DirectoryInfo dir = new DirectoryInfo(IPath);
            FileInfo[] inf = dir.GetFiles();
            for (int i = 0; i < inf.Length; i++)
            {
                Console.WriteLine(inf[i].Name);
                //檔案取回
                System.IO.File.Copy("\\\\"+z.Server_IP+"\\ftp\\"+inf[i].Name, "C:\\"+inf[i].Name+".jpg");
            }
            kk.Undo();
        }

2011年11月9日 星期三

[C#] JSON 序列化及反序列化 筆記

今天有使用到 先作個 Demo 筆記

下記範例下載

1.) 需要加入參考
System.ServiceModel.Web
System.Runtime.Serialization

2.) 先建立對象
 public class Pz
    {
        public string EMP_ID { get; set; }
        public string NAME { get; set; }
        public int Age { get; set; }
    }

3.) 做序列化
            Pz Q = new Pz();
            Q.Age = 10;
            Q.EMP_ID = "12345";
            Q.NAME = "king";
            DataContractJsonSerializer ds = new DataContractJsonSerializer(typeof(Pz));
            using (MemoryStream ms = new MemoryStream())
            {
                ds.WriteObject(ms, Q);
                output = Encoding.UTF8.GetString(ms.ToArray());
                MessageBox.Show("這是序列化:" + output);
            }

           
4.) 反序列化
             if (output.Length == 0)
            {
                return;
            }
            DataContractJsonSerializer outDs = new DataContractJsonSerializer(typeof(Pz));
            using (MemoryStream outMs = new MemoryStream(Encoding.UTF8.GetBytes(output)))
            {
                Pz QQ = outDs.ReadObject(outMs) as Pz;
                MessageBox.Show(QQ.Age + "," + QQ.EMP_ID + "," + QQ.NAME);
            }

2011年8月31日 星期三

[C#] 監控USB插拔 2

先前也寫過一篇 監控 USB 插拔的文章,見 http://kuomingwang.blogspot.com/2010/09/c-usb.html
但是那是監控已知的 USB 儲存設備,最近又有類似的需求,這算是另一種寫法。

//using System.Management;

ManagementEventWatcher mew = null;

         private void Form1_Load(object sender, EventArgs e)
        {
            mew = new ManagementEventWatcher("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE TargetInstance ISA \"Win32_DiskDrive\"");
            mew.Start();
            mew.EventArrived += new EventArrivedEventHandler(mew_go);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            mew.Stop();
        }
        private void mew_go(object sender, System.Management.EventArrivedEventArgs e)
        {
            ManagementBaseObject newEvent = e.NewEvent, newEventTarget = (newEvent["TargetInstance"] as ManagementBaseObject);
            if (newEventTarget["InterfaceType"].ToString() == "USB")
            {
                switch (newEvent.ClassPath.ClassName)
                {
                    case "__InstanceCreationEvent":
                        Listbox_text_Update(listBox1, Convert.ToString(newEventTarget["Caption"])+" 裝置已插入");
                        break;
                    case "__InstanceDeletionEvent":
                        Listbox_text_Update(listBox1, Convert.ToString(newEventTarget["Caption"])+" 裝置已退出");
                        break;
                }
            }
        }
        public static void Listbox_text_Update(ListBox lbox, string s)
        {
            if (lbox.InvokeRequired)
            {
                lbox.BeginInvoke(new MethodInvoker(() => Listbox_text_Update(lbox, s)));
            }
            else
            {
                lbox.Items.Add(s);
            }
        }


2011年8月17日 星期三

[C#] 如何變更本機電腦日期、變更本機電腦時間,來作 時間同步校正

主要需求是因為 有些 Client 端 PC 都是服役多年的老 PC 所以 BIOS 電池都沒力了,又懶得一台一台換。

所以直接從 SQL Server 端 作時間的校正。

 [DllImport("Kernel32.dll")]
 private extern static uint SetLocalTime(ref SYSTEMTIME lpSystemTime);

 [StructLayout(LayoutKind.Sequential)]
        private struct SYSTEMTIME
        {
            public ushort wYear;
            public ushort wMonth;
            public ushort wDayOfWeek;
            public ushort wDay;
            public ushort wHour;
            public ushort wMinute;
            public ushort wSecond;
            public ushort wMilliseconds;
        }

 public void SetTime(DateTime SqlServerTime)
        {
            SYSTEMTIME st = new SYSTEMTIME();
            st.wYear = Convert.ToUInt16(SqlServerTime.Year);
            st.wMonth = Convert.ToUInt16(SqlServerTime.Month);
            st.wDay = Convert.ToUInt16(SqlServerTime.Day);
            st.wHour = Convert.ToUInt16(SqlServerTime.Hour);
            st.wMilliseconds = Convert.ToUInt16(SqlServerTime.Millisecond);
            st.wMinute = Convert.ToUInt16(SqlServerTime.Minute);
            st.wSecond = Convert.ToUInt16(SqlServerTime.Second);
            SetLocalTime(ref st);
        }

//使用時
  ChangeLocalDateTime CLDT = new ChangeLocalDateTime();
 CLDT.SetTime(db_dt); //db_dt 是指從 SQL Server 取回來的 GETDATE()

2011年6月3日 星期五

[C#] 取得本機 網路介面卡名稱、網路名稱

作業上有用到 作個筆記


        //取得 網路名稱 例如:中華電信
        private void dd()
        {
             NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
             foreach (NetworkInterface adapter in interfaces)
             {
                 comboBox2.Items.Add(adapter.Name.ToString());
             }
        }
        //取得 網路介面卡名稱
        private void GetAdtInfo()
        {
            string strQry = "Select * from Win32_NetworkAdapterConfiguration";
            ManagementObjectSearcher objSc = new ManagementObjectSearcher(strQry);
            ArrayList ar = new ArrayList();
            foreach (ManagementObject objQry in objSc.Get())
            {
                comboBox1.Items.Add(objQry["Description"]);
            }
        }

2011年5月16日 星期一

[C#] String 處理, 簡體 轉 繁體

有兩種作法  ,  第一種 是引用 Microsoft.VisualBasic  ,第二種 是引用 作業系統 Dll
但是第一種 有時候轉完 會出現?號,原因不明 (時間關係 所以沒繼續追 下去)

1.)
Microsoft.VisualBasic 加入參考
 private string CHT_TO_BIG5(string str)
        {
            return Microsoft.VisualBasic.Strings.StrConv(str, Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 0);
        }

2.)
 //字串轉 繁體 使用
        internal const int LOCALE_SYSTEM_DEFAULT = 0x0800;
        internal const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
        internal const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;
        [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
        internal static extern int LCMapString(int Locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest);

 private string String_To_BIG5(string str)
        {
            String tTarget = new String(' ', str.Length);
            int tReturn = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, str, str.Length, tTarget, str.Length);
            return tTarget;
        }

2011年4月27日 星期三

[C#] 移動滑鼠游標到 x,y 位置

紀錄一下,移動滑鼠游標到某個按鍵上


        [DllImport("user32.dll")]
        static extern bool GetCursorPos(ref Point lpPoint);


 Cursor.Position = new Point(btn2.Location.X + this.Left + 34, btn2.Location.Y + this.Top + 47);

2011年4月11日 星期一

[C#] 簡單快速觀看股票行情 看股小工具

自己寫的簡單看股軟體,可以縮到工具列,目前設定每3分鐘自動更新一次。 

每個人都有自己一套的 選股邏輯,這個軟體 只是把相關資訊 拉出來比較方面觀看。

點我下載


ps. 若下載後不能執行,亦請下載 Microsoft .Net framework 2.0 環境,然後安裝。


簡單設定方式
1.) 點選 Setting
2.) Class,鋼鐵,2002  <-- 代表追加 鋼鐵分類,要觀察的有 2002 這隻個股
3.) 儲存 關閉文字檔
4.) 點擊 GO