www.pudn.com > baoyouzhuomian.zip > Form1.cs, change:2011-08-10,size:7867b


 
        string b;  
        StringChange sChange = new StringChange(); 
        string strPath = Application.StartupPath + "\\buttons.mdb"; 
        private void Form1_Load(object sender, EventArgs e) 
        { 
            string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source='" + strPath + "'"; 
            OleDbConnection oleCon = new OleDbConnection(ConStr); 
            string sg = "select * from buttons "; 
            string strDel = "delete * from buttons where tp='490'"; 
            OleDbCommand oleDel = new OleDbCommand(strDel, oleCon); 
            oleCon.Open(); 
            foreach (Control sad in this.Controls) 
            { 
                oleDel.ExecuteNonQuery(); 
            } 
            OleDbDataAdapter adapter = new OleDbDataAdapter(sg, oleCon); 
            // 创建DataSet,用于存储数据. 
            DataSet testDataSet = new DataSet(); 
            // 执行查询,并将数据导入DataSet. 
            adapter.Fill(testDataSet, "buttons"); 
            //string ab="select name from buttons  
            oleCon.Close(); 
            oleCon.Dispose(); 
            foreach (DataRow testRow in testDataSet.Tables["buttons"].Rows) 
            { 
                 
                string qq; 
                Button bt = new Button(); 
                bt.Name = testRow[0].ToString(); 
                //bt.Text = testRow[1].ToString(); 
                try 
                { 
                    GetSystemIcon asd = new GetSystemIcon(); 
                    string yy = testRow[2].ToString(); 
                    Icon a = asd.GetIconByFileName(@yy); 
                    bt.BackgroundImage = a.ToBitmap(); 
                    bt.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; 
                } 
                catch (Exception) 
                { 
                } 
                if (testRow[3].ToString() ==  ""||testRow[4].ToString() =="") 
                { 
                    bt.Top = bt.Left = 0; 
                } 
                else 
                { 
                    string f = testRow[3].ToString(); 
                    string g = testRow[4].ToString(); 
                    bt.Left = Convert.ToInt32(f); 
                    bt.Top = Convert.ToInt32(g) ; 
                } 
                qq = testRow[2].ToString(); 
                bt.Size = new System.Drawing.Size(60, 50); 
                bt.BackColor = Color.SkyBlue; 
                bt.ForeColor = Color.Black ; 
                bt.TextAlign = System.Drawing.ContentAlignment.BottomCenter; 
                this.Controls.Add(bt); 
                bt.Click += new EventHandler(mButton_Click); 
                bt.MouseMove += new MouseEventHandler(myButton_MouseMove); 
                bt.MouseUp += new MouseEventHandler(myButton_MouseUp); 
                ToolTip toolTip1 = new ToolTip(); 
                toolTip1.AutoPopDelay = 1000; 
                toolTip1.InitialDelay = 1000; 
                toolTip1.ReshowDelay = 1500; 
                toolTip1.ShowAlways = true; 
                toolTip1.SetToolTip(bt, bt.Name); 
            } 
        } 
        private void Form1_DragEnter(object sender, DragEventArgs e) 
        { 
            
                string tt = sChange.GetEnd(sChange.GetEnd(b, '\\', 1), '.', 2); 
                string nn = sChange.GetEnd(sChange.GetEnd(b, '\\', 1), '.', 2); 
                string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source='" + strPath + "'"; 
                OleDbConnection oleCon = new OleDbConnection(ConStr); 
                string strDel = "delete * from buttons where name='" + myButton.Name + "'"; 
                string strSQL = "insert into buttons(name,[text],[link],[lt],[tp]) values('" + nn + "','" + tt + "','" + qq + "','" + myButton.Left + "','" + myButton.Top + "')"; 
                OleDbCommand oleCmd = new OleDbCommand(strSQL, oleCon); 
                OleDbCommand oleDel = new OleDbCommand(strDel, oleCon); 
                oleCon.Open(); 
                try 
                { 
                    oleDel.ExecuteNonQuery(); 
                    oleCmd.ExecuteNonQuery(); 
                } 
                catch (Exception) 
                {} 
                string sg = "select * from buttons "; 
                OleDbDataAdapter adapter = new OleDbDataAdapter(sg, oleCon); 
                // 创建DataSet,用于存储数据. 
                DataSet testDataSet = new DataSet(); 
                // 执行查询,并将数据导入DataSet. 
                adapter.Fill(testDataSet, "buttons"); 
                oleCon.Close(); 
                oleCon.Dispose(); 
 
                foreach (DataRow testRow in testDataSet.Tables["buttons"].Rows) 
                { 
                    string pp; 
                    myButton.Name = testRow[0].ToString(); 
                    try 
                    { 
                        GetSystemIcon asd = new GetSystemIcon(); 
                        string yy = testRow[2].ToString(); 
                        Icon ty = asd.GetIconByFileName(@yy); 
                        myButton.BackgroundImage = ty.ToBitmap(); 
                        myButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; 
                    } 
                    catch (Exception) 
                    { 
                    } 
                    if (testRow[3].ToString() == "" || testRow[4].ToString() == "") 
                    { 
                        myButton.Top = myButton.Left = 0; 
                    } 
                    else 
                    { 
                        string f = testRow[3].ToString(); 
                        string g = testRow[4].ToString(); 
                        myButton.Left = Convert.ToInt32(f); 
                        myButton.Top = Convert.ToInt32(g); 
                    } 
                    pp = testRow[2].ToString(); 
 
                } 
            } 
        } 
        void mButton_Click(object sender, EventArgs e) 
        { 
 
            Button btn = (Button)sender; 
             
            if (click == true) 
            { 
                string strPath = Application.StartupPath + "\\buttons.mdb"; 
                string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source='" + strPath + "'"; 
                OleDbConnection oleCon = new OleDbConnection(ConStr); 
                string we = "select link from buttons where name='" + btn.Name + "'"; 
                oleCon.Open(); 
                OleDbDataAdapter adapter = new OleDbDataAdapter(we, oleCon); 
                // 创建DataSet,用于存储数据. 
                DataSet testDataSet = new DataSet(); 
                // 执行查询,并将数据导入DataSet. 
                adapter.Fill(testDataSet, "buttons"); 
                oleCon.Close(); 
                oleCon.Dispose(); 
                string ww = testDataSet.Tables[0].Rows[0][0].ToString(); 
                Process p = new Process(); 
                p.StartInfo.FileName = ww; 
                p.Start(); 
                p.Close(); 
            } 
        } 
        void myButton_MouseUp(object sender, MouseEventArgs e) 
        { 
            click = true; 
            Button btn = (Button)sender; 
            string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source='" + strPath + "'"; 
            OleDbConnection oleCon = new OleDbConnection(ConStr); 
            string strSQL = "update buttons set lt='" + btn.Left.ToString() + "',tp='" + btn.Top.ToString() + "'where name='" + btn.Name + "'"; 
             
            OleDbCommand oleCmd = new OleDbCommand(strSQL, oleCon); 
            oleCon.Open(); 
            try 
            { 
                oleCmd.ExecuteNonQuery(); 
            } 
            catch (Exception) 
            { } 
            oleCon.Close(); 
            oleCon.Dispose(); 
        }