• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 124,  comments - 29,  trackbacks - 0
                 摘要:   1 private void MoveCmdToLast(TextBox txtCmdInput, String selCmd)//把所選中的命令移動到最下一行然后顯示在文本框中  2        { &...  閱讀全文
            posted @ 2008-09-04 10:35 天書 閱讀(4543) | 評論 (0)編輯 收藏
                       String curRowText = "Hello!"
                       FileStream fs = new FileStream("D:\\file.txt",FileMode.Append,FileAccess.Write);
                        StreamWriter sw = new StreamWriter(fs);
                        sw.Flush();
                        sw.Write(curRowText);
                        sw.Flush();
                        sw.Close();


            或者:
            StreamWriter writer = null;
            try
            {
            writer = new StreamWriter(strFileName, true);
            writer.WriteLine(strCmdText);
            }
            catch (Exception ex)
            {
            //進行異常處理
            }
            finally
            {
            if (writer != null) writetofile.Close();
            }
            return false;
            posted @ 2008-09-03 18:17 天書 閱讀(818) | 評論 (0)編輯 收藏
                    private void 導入模板ToolStripMenuItem_Click(object sender, EventArgs e)
                    {
                        OpenFileDialog ofd = new OpenFileDialog();
                        ofd.Title = " 請選擇您要導入的模板文件:";
                        ofd.Filter = "TextDocument(*.cmd)|*.cmd|TextDocument(*.txt)|*.txt";
                        ofd.ShowDialog();
                        System.IO.StreamReader sr = new System.IO.StreamReader( ofd.FileName ,System.Text.Encoding.Default);
                        txtCmdInput.Text = sr.ReadToEnd();
                    }
            posted @ 2008-09-03 16:34 天書 閱讀(1347) | 評論 (1)編輯 收藏

             

             1 private void GetLine(TextBox txtCmdInput)//取控件里鼠標所在行的命令發(fā)送后提到最前
             2        {
             3            //取光標所在行的字符串包括末尾的換行回車符"\r\n"
             4            string strCmdText = txtCmdInput.Text;
             5            int curInx = txtCmdInput.SelectionStart;       //光標所在位置索引
             6            string tmp = strCmdText.Substring(0, curInx);  //開始到光標處的子串
             7            int start = tmp.LastIndexOf('\n');             //找光標所在行的開頭索引start + 1
             8
             9            tmp = strCmdText.Substring(curInx);//當前光標所在位置到最后的子串
            10            int end = tmp.IndexOf('\n'); //找該行的末尾索引包括"\r\n"
            11            string curRowText = null;
            12            if (end > 0)
            13            {
            14                curRowText = strCmdText.Substring(start + 1, curInx - start + end);
            15            }

            16            else
            17            {
            18                curRowText = strCmdText.Substring(start + 1);
            19            }

            20            //把光標所在行的命令提到第一行的下一行
            21            String strLeft = strCmdText.Remove(start + 1, curRowText.Length);
            22
            23            //處理剩下的字符串,注意把開頭結(jié)尾的"\r\n"找到刪掉
            24            if (strLeft != "")
            25            {
            26                while (strLeft[strLeft.Length - 1== '\r' || strLeft[strLeft.Length - 1== '\n')
            27                {
            28                    strLeft = strLeft.Remove(strLeft.Length - 11);
            29                }

            30            }

            31            if (strLeft != "")
            32            {
            33                while (strLeft[0== '\r')
            34                {
            35                    strLeft = strLeft.Remove(02);
            36                }

            37            }

            38            //處理你取出的當前行的字符串若有"\r\n"注意把它去掉
            39            if (curRowText != "" && curRowText.Length > 0)
            40            {
            41                while (curRowText[curRowText.Length - 1== '\r' || curRowText[curRowText.Length - 1== '\n')
            42                {
            43                    curRowText = curRowText.Remove(curRowText.Length - 11);
            44                }

            45            }

            46            String strNew = curRowText + "\r\n" + strLeft;
            47            //最后前面留一行空格且把鼠標定位到此
            48            txtCmdInput.Text = "\r\n" + strNew;
            49        }
              

            接著引發(fā)textbox控件的KeyDown事件
                    private void txtCmdInput_KeyDown(object sender, KeyEventArgs e)
                    {
                        if (e.KeyCode == Keys.Enter)
                        {
                            //發(fā)送光標所在行指令,且把它提到頭一行
                            GetLine(txtCmdInput);
                            e.SuppressKeyPress = true;//回車事件已經(jīng)處理完不再響應了
                        }
                    }
            posted @ 2008-09-03 15:09 天書 閱讀(4944) | 評論 (3)編輯 收藏

                    private void myNeTree_MouseDown(object sender, MouseEventArgs e)
                    {
                        MyTreeView mtreev = (MyTreeView)sender;
                        if(e.Button == MouseButtons.Right)
                        {
                            if (this.myNeTree.SelectedNode != null && this.myNeTree.SelectedNode.Nodes.Count == 0)
                            {
                                Point p = new Point(e.X,e.Y);
                                TreeNode tn = mtreev.GetNodeAt(p);//根據(jù)鼠標右鍵點下的位置,得到該位置的節(jié)點
                                if(myNeTree.SelectedNode.Equals(tn))//看當前鼠標位置所在的節(jié)點是否為當前控件樹中選中的節(jié)點
                                {
                                    this.rightMenu.Show(mtreev, p.X, p.Y);
                                }
                               
                            }
                        }
                    }

            因為MyTreeView 是動態(tài)加載:
                        private MyTreeView myNeTree;

                        ControlContainerItem contNe = new ControlContainerItem("myNeTree", "網(wǎng)元");

                        myNeTree = new BurEmluator.MyTreeView();
                        myNeTree.Name = "myNeTree";
                        myNeTree.Size = new System.Drawing.Size(95, 350);
                        //contNe鼠標右鍵監(jiān)聽事件
                        myNeTree.MouseDown += new MouseEventHandler(myNeTree_MouseDown);

                        contNe.Control = myNeTree;

                        this.NeGroup1.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] { radiocont, contNe });

            posted @ 2008-09-02 15:47 天書 閱讀(1346) | 評論 (0)編輯 收藏
            C#事件支持發(fā)布者/訂閱者模式,發(fā)布者將事件通知給訂閱者,而訂閱者在事件發(fā)生時調(diào)用已經(jīng)注冊好的事件處理函數(shù)。
                    public delegate void delUpdate();  //委托定義,相當于一個函數(shù)簽名,函數(shù)指針
                    public event delUpdate ENotify;    //定義事件,該事件引發(fā)此委托類型的事件處理函數(shù)
                    
                    private int a = 2;
                    public int A
                    {
                        get { return a; }
                        set
                        {
                            a = value;
                            if (ENotify != null)  //如果事件不等于空就是說有訂閱者注冊過該事件,比如:Publisher.getInstance().ENotify +=new Publisher.delUpdate(GetData);也就是說觸發(fā)事件后有相應的事件處理函數(shù)被調(diào)用。
                            {
                                ENotify();
                            }

                        }
                    }

                   public Observer()
                    {
                        Publisher.getInstance().ENotify +=new Publisher.delUpdate(GetData);
                    }

                    public void GetData()
                    {
                        oa = Publisher.getInstance().A;
                        ob = Publisher.getInstance().B;
                        oc = Publisher.getInstance().C;
                    }

            posted @ 2008-06-30 11:07 天書 閱讀(1510) | 評論 (0)編輯 收藏
            首先可以在解決方案資源管理器中添加->新建項目->配置文件(.config),
            寫配置文件,如:
            1<?xml version="1.0" encoding="utf-8" ?>
            2<configuration>
            3  <appSettings>
            4    <add key ="FactoryName" value="ChineseFactory"/>
            5  </appSettings>
            6</configuration>

            讀配置文件
            private string FactoryType = null;
                    System.Configuration.AppSettingsReader asr 
            = new System.Configuration.AppSettingsReader();
            1FactoryType = (string)asr.GetValue("FactoryName"typeof(string));
            注意語句要寫在函數(shù)里別直接寫在類里面了!!!!!!!!!!!!!!!!!
            posted @ 2008-06-24 11:08 天書 閱讀(627) | 評論 (0)編輯 收藏
            Abstract Factory 模式:關鍵特征
            意圖:為特定(不同)的客戶提供特定(不同)系列的對象
                         比如Vista風格的桌面,Window標準的桌面(其中包括圖標的樣式,菜單欄,任務欄等)
            問題:一系列相關或相互依賴的對象需要被實例化

            解決方案:
                         先定義一個抽象工廠類來選擇工廠類(可以根據(jù)配置文件選取)
             1    class AbstractFactory
             2    {
             3        private string FactoryType = null;
             4        System.Configuration.AppSettingsReader asr = new System.Configuration.AppSettingsReader();
             5        public IFactory GetFactory()
             6        {
             7            FactoryType = (string)asr.GetValue("FactoryName"typeof(string));
             8            switch(FactoryType)
             9            {
            10                case "ChineseFactory":
            11                    return new ChineseFactory();
            12                    break;
            13                case "AmericanFactory":
            14                    return new AmericanFactory();
            15                    break;
            16                default:
            17                    return new ChineseFactory();
            18            }

            19            
            20        }

            21    }

                      各個工廠類里創(chuàng)建不同系列的對象(同一工廠類里的對象風格相同),但他們有一個共同的接口或父類
             1    interface IFactory
             2    {
             3        Service CreateService();
             4    }

             5
             6    class ChineseFactory : IFactory
             7    {
             8
             9        IFactory 成員
            17    }

            18    class AmericanFactory : IFactory
            19    {
            20        IFactory 成員
            28    }
             最后在客戶端Service se = (new AbstractFactory()).GetFactory().CreateService();,提供一種“封裝機制”來避免客戶程序和這種“多系列具體對象創(chuàng)建工作”的緊耦合。每次在中國和美國的工資體制上切換時可以通過更改配置文件來切換。這樣就避免了源代碼保密的情況下無法更改業(yè)務規(guī)則的弊端。

            配置文件如下
            <?xml version="1.0" encoding="utf-8" ?>
            <configuration>
              
            <appSettings>
                
            <add key ="FactoryName" value="ChineseFactory"/>
              
            </appSettings>
            </configuration>


            posted @ 2008-06-24 11:00 天書 閱讀(837) | 評論 (0)編輯 收藏

             

                   Strategy策略模式是一種對象行為模式。主要是應對:在軟件構(gòu)建過程中,某些對象使用的算法可能多種多樣,經(jīng)常發(fā)生變化。如果在對象內(nèi)部實現(xiàn)這些算法,將會使對象變得異常復雜,甚至會造成性能上的負擔。

                   GoF設計模式》中說道:定義一系列算法,把它們一個個封裝起來,并且使它們可以相互替換。該模式使得算法可獨立于它們的客戶變化。

                   Strategy模式的結(jié)構(gòu)圖如下:


             

             

             


                  
            從圖中我們不難看出:Strategy模式實際上就是將算法一一封裝起來,如圖上的ConcreteStrategyAConcreteStrategyBConcreteStrategyC,但是它們都繼承于一個接口,這樣在Context調(diào)用時就可以以多態(tài)的方式來實現(xiàn)對于不用算法的調(diào)用。

                   Strategy模式的實現(xiàn)如下:

                   我們現(xiàn)在來看一個場景:我在下班在回家的路上,可以有這幾種選擇,走路、騎車、坐車。首先,我們需要把算法抽象出來:

                   public interface IStrategy

                {

                    void OnTheWay();

            }

            接下來,我們需要實現(xiàn)走路、騎車和坐車幾種方式。

            public class WalkStrategy : IStrategy

                {

                    public void OnTheWay()

                    {

                        Console.WriteLine("Walk on the road");

                    }

                }

             

                public class RideBickStragtegy : IStrategy

                {

                    public void OnTheWay()

                    {

                        Console.WriteLine("Ride the bicycle on the road");

                    }

                }

             

                public class CarStragtegy : IStrategy

                {

                    public void OnTheWay()

                    {

                        Console.WriteLine("Drive the car on the road");

                    }

            }

             

            最后再用客戶端代碼調(diào)用封裝的算法接口,實現(xiàn)一個走路回家的場景:

            class Program

                {

                    static void Main(string[] args)

                    {

                        Console.WriteLine("Arrive to home");

                        IStrategy strategy = new WalkStrategy();

                        strategy.OnTheWay();

                        Console.Read();

                    }

            }

            運行結(jié)果如下;

            Arrive to home

            Walk on the road

            如果我們需要實現(xiàn)其他的方法,只需要在Context改變一下IStrategy所示例化的對象就可以。

            posted @ 2008-06-18 09:38 天書 閱讀(169) | 評論 (0)編輯 收藏
            基于對象可以這樣說主要看重封裝這個特性的, 即把數(shù)據(jù)和操作數(shù)據(jù)的行為封裝;
            向?qū)ο?/font>主要是在對象封裝之上更加重視“多態(tài)性”特性。
            僅列出標題
            共13頁: First 5 6 7 8 9 10 11 12 13 

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章分類

            文章檔案

            好友的Bolg

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            一本色道久久综合亚洲精品| 亚洲AV日韩精品久久久久久久| 久久久婷婷五月亚洲97号色| 久久综合狠狠综合久久| 国内精品久久久久影院日本| 色综合色天天久久婷婷基地| 久久久这里有精品中文字幕| 久久精品中文无码资源站| 久久精品国产亚洲AV无码娇色| 国产精品激情综合久久 | 婷婷五月深深久久精品| 国产精品99久久99久久久| 久久国产香蕉视频| 人妻精品久久无码区| 日本欧美国产精品第一页久久| 色欲久久久天天天综合网 | 久久久久亚洲AV无码永不| 久久免费精品视频| 亚洲va中文字幕无码久久| 狠狠色伊人久久精品综合网| 久久精品一本到99热免费| 久久婷婷五月综合97色直播| 99久久精品费精品国产一区二区 | 精品无码久久久久久尤物| 亚洲国产成人乱码精品女人久久久不卡 | 欧美亚洲日本久久精品| 久久精品国产一区二区三区日韩| 久久午夜无码鲁丝片秋霞| 久久亚洲欧洲国产综合| 国产精品99久久精品爆乳| 久久777国产线看观看精品| 亚洲精品美女久久久久99| 久久久久久综合网天天| 久久午夜免费视频| 国产69精品久久久久APP下载 | 国产精品成人99久久久久 | 97久久超碰国产精品旧版| 亚洲精品美女久久777777| 人妻精品久久久久中文字幕69| 久久精品无码午夜福利理论片 | 久久99久久99精品免视看动漫|