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 阅读(394) | 评论 (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 阅读(317) | 评论 (0)编辑 收藏
     摘要: pull模式          protected   void  Page_Load( object  sender, System.EventArgs e)         {             //  在...  阅读全文
posted @ 2006-05-28 14:12 record java and net 阅读(472) | 评论 (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 阅读(728) | 评论 (2)编辑 收藏
     摘要: 思路:建个模版文件,再用C#读此文件,把里面的标记替换掉。。  阅读全文
posted @ 2006-05-27 17:32 record java and net 阅读(319) | 评论 (0)编辑 收藏
仅列出标题
共31页: First 上一页 17 18 19 20 21 22 23 24 25 下一页 Last 

导航

常用链接

留言簿(44)

新闻档案

2.动态语言

3.工具箱

9.文档教程

友情链接

搜索

最新评论