blogjava's web log

          blogjava's web log
          ...

          // 得到路徑
          ???????????? string ?strPath = System.IO.Directory.GetCurrentDirectory();
          // 分割
          string ?str1 = " text1,text2,text3,text4 "
          string []?stri = str1.Split( new ? char [] { ' ' } );

          // 啟動一個程序

          using ?System;
          using ?System.Drawing;
          using ?System.Collections;
          using ?System.ComponentModel;
          using ?System.Windows.Forms;
          using ?System.Data;
          using ?System.Diagnostics;
          using ?System.Reflection;
          using ?System.Runtime.InteropServices;

          ????????
          /// ? <summary>
          ????????
          /// ?應用程序的主入口點。
          ????????
          /// ? </summary>

          ????????[STAThread]
          ????????
          static ? void ?Main()?
          ????????
          {
          ????????????
          // Get?the?running?instance.
          ????????????Process?instance? = ?RunningInstance();
          ????????????
          if ?(instance? == ? null )
          ????????????
          {
          ????????????????
          // 新實例
          ????????????????Application.Run( new ?Form1());
          ????????????}

          ????????????
          else
          ????????????
          {
          ????????????????
          // 相同的實例,并將窗口置前
          ????????????????HandleRunningInstance(instance);
          ????????}

          ????}


          public ? static ?Process?RunningInstance()
          {
          ????Process?current?
          = ?Process.GetCurrentProcess();
          ????Process[]?processes?
          = ?Process.GetProcessesByName?(current.ProcessName);
          ????
          // 查找相同名的進程
          ???? foreach ?(Process?process? in ?processes)
          ????
          {
          ????
          // 忽略當前線程
          ???? if ?(process.Id? != ?current.Id)
          ????
          {
          ????
          // 確認相同名的進程運行位置是否相同
          ???? if ?(Assembly.GetExecutingAssembly().Location.Replace( " / " ,? " \\ " )? == current.MainModule.FileName)
          {
          ????
          // 返回相同名進程
          ???? return ?process;
          }

          }

          }

          ????
          // 沒有其它進程,返回空值
          ???? return ? null ;
          }


          ?
          public ? static ? void ?HandleRunningInstance(Process?instance)
          ?
          {
          ?
          // 確認窗口是最小化或最大化
          ?ShowWindowAsync?(instance.MainWindowHandle?,?WS_SHOWNORMAL);

          ?
          // 將窗口置前
          ?SetForegroundWindow?(instance.MainWindowHandle);
          ?}


          ?[DllImport(
          " User32.dll " )]?

          private ? static ? extern ? bool ?ShowWindowAsync(IntPtr?hWnd,? int ?cmdShow);
          ?[DllImport(
          " User32.dll " )]? private ? static ? extern ? bool ?SetForegroundWindow(IntPtr?hWnd);
          ?
          private ? const ? int ?WS_SHOWNORMAL? = ? 1 ;

          ????????
          private ? void ?Form1_Load( object ?sender,?System.EventArgs?e)
          ????????
          {
          ????????
          ????????}

          ?}
          posted @ 2006-05-28 14:56 record java and net 閱讀(405) | 評論 (0)編輯 收藏

          [Serializable]
          ????
          public?class?MyObject?
          ????
          {
          ????????
          public?int?n1?=?0;
          ????????
          public?int?n2?=?0;
          ????????
          public?String?str?=?null;
          ????}

          using?System;
          using?System.Drawing;
          using?System.Collections;
          using?System.ComponentModel;
          using?System.Windows.Forms;
          using?System.Data;
          using?System.IO?;
          using?System.Runtime?.Serialization?.Formatters?.Binary?;
          using?System.Runtime?.Serialization?;

          //系列化
          private?void?button1_Click(object?sender,?System.EventArgs?e)
          ????????
          {
          ????????????MyObject?obj?
          =?new?MyObject();
          ????????????obj.n1?
          =?1;
          ????????????obj.n2?
          =?24;
          ????????????obj.str?
          =?"Some?String";
          ????????????IFormatter?formatter?
          =?new?BinaryFormatter();
          ????????????Stream?stream?
          =?new?FileStream("MyFile.bin",?FileMode.Create,?FileAccess.Write,?FileShare.None);
          ????????????formatter.Serialize(stream,?obj);
          ????????????stream.Close();

          ????????}

          //反。。。。。。
          ????????private?void?button2_Click(object?sender,?System.EventArgs?e)
          ????????
          {
          ????????????IFormatter?formatter?
          =?new?BinaryFormatter();
          ????????????Stream?stream?
          =?new?FileStream("MyFile.bin",?FileMode.Open,?FileAccess.Read,?FileShare.Read);
          ????????????MyObject?obj?
          =?(MyObject)?formatter.Deserialize(stream);
          ????????????stream.Close();
          ????????????MessageBox.Show?(obj.n1.ToString?()?);

          ????????}
          posted @ 2006-05-28 14:25 record java and net 閱讀(324) | 評論 (0)編輯 收藏
               摘要: pull模式 ???????? protected ? void ?Page_Load( object ?sender,?System.EventArgs?e)???????? {???????????? // ?在...  閱讀全文
          posted @ 2006-05-28 14:12 record java and net 閱讀(483) | 評論 (0)編輯 收藏
               摘要: 使用DataRelation類創建關系并利用父/子關系讀取數據示例void?Page_Load(object?sender,?System.EventArgs?e)????????????{????????????????//?連接字符串和?SQL?語句????????????????string?ConnString?=?System.Configuration.ConfigurationSet...  閱讀全文
          posted @ 2006-05-27 18:07 record java and net 閱讀(739) | 評論 (2)編輯 收藏
               摘要: 思路:建個模版文件,再用C#讀此文件,把里面的標記替換掉。。  閱讀全文
          posted @ 2006-05-27 17:32 record java and net 閱讀(328) | 評論 (0)編輯 收藏
          僅列出標題
          共31頁: First 上一頁 17 18 19 20 21 22 23 24 25 下一頁 Last 

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 土默特左旗| 辽源市| 那坡县| 广河县| 溧水县| 宁安市| 唐海县| 洱源县| 绥滨县| 渭源县| 兰溪市| 仁寿县| 海城市| 普安县| 昌平区| 黎川县| 三门峡市| 广平县| 荣成市| 甘肃省| 乌拉特中旗| 巴塘县| 正宁县| 乡城县| 云梦县| 阜宁县| 敖汉旗| 宜良县| 昭通市| 宁安市| 桃园县| 南部县| 金乡县| 永康市| 墨竹工卡县| 华亭县| 高安市| 佛学| 越西县| 青海省| 定西市|