//ToolStripSplitButton是標準按鈕和下拉按鈕的組合,各自工作,但有聯系,感覺上后者是沒有向下箭頭ToolStripDropDownButton;
ToolStripDropDownButton只含有一個按鈕,可以選擇有沒有向下箭頭的標志,單擊時顯示關聯的 ToolStripDropDown 的控件。兩者均可改變箭頭標志在做還是在右。//VS自帶雙緩沖this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |ControlStyles.OptimizedDoubleBuffer, true);//控件雙緩沖Control.DoubleBuffered=true; //attribute modfied by PRotected//手工雙緩沖Bitmap bmp = new Bitmap(600, 600);Graphics g = Graphics.FromImage(bmp);g.DrawLine();this.CreateGraphics().DrawImage(bmp, 0, 0);//這句是關鍵,不能?在OnPaint里畫BitBmp在這里調InvalidateInvalidate(Rectangle)//規定區域重繪,解決閃爍的另一種方法ComboBox ComboBox1 = (ComboBox) sender;(Sender as SomeObject).Method()this.label1.Font = new System.Drawing.Font("微軟雅黑", 72F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label1.Font = new Font("微軟雅黑", fontSize);//自定義控件背景透明SetStyle(ControlStyles.UserPaint, true);SetStyle(ControlStyles.SupportsTransparentBackColor, true);this.BackColor = Color.Transparent;//獲得程序集System.Reflection.Assembly assem = System.Reflection.Assembly.GetExecutingAssembly();//點移位Point.Offset(Point);Point.Offset(int,int);Rectangle.Contains(Point);//截獲標題欄消息,自畫標題欄using System.Runtime.InteropServices;using System.Drawing.Drawing2D;[DllImport("user32.dll")]private static extern IntPtr GetWindowDC(IntPtr hWnd);[DllImport("user32.dll")]private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);private const int WM_NCPAINT = 0x0085;private const int WM_NCACTIVATE = 0x0086;private const int WM_NCLBUTTONDOWN = 0x00A1;protected override void WndProc(ref Message m){ base.WndProc(ref m); Rectangle vRectangle = new Rectangle((Width - 75) / 2, 3, 75, 25); switch (m.Msg) { case WM_NCPAINT: case WM_NCACTIVATE: IntPtr vHandle = GetWindowDC(m.HWnd); Graphics vGraphics = Graphics.FromHdc(vHandle); vGraphics.FillRectangle(new LinearGradientBrush(vRectangle, Color.Pink, Color.Purple, LinearGradientMode.BackwardDiagonal), vRectangle); StringFormat vStringFormat = new StringFormat(); vStringFormat.Alignment = StringAlignment.Center; vStringFormat.LineAlignment = StringAlignment.Center; vGraphics.DrawString("About", Font, Brushes.BlanchedAlmond, vRectangle, vStringFormat); vGraphics.Dispose(); ReleaseDC(m.HWnd, vHandle); break; case WM_NCLBUTTONDOWN: Point vPoint = new Point((int)m.LParam); vPoint.Offset(-Left, -Top); if (vRectangle.Contains(vPoint)) MessageBox.Show(vPoint.ToString()); break; }}Control.SuspendLayout;//在它和ResumeLayout之間的代碼不會引起Parent Control的重繪Control.AddRange(new Control[]{});//添加多個控件Control.ResumeLayout;// 在它和SuspendLayout之間的代碼不會引起Parent Control的重繪Button[] buttons = new Button[] {};//大膽地設類數組吧~Button.SetBounds(int,int,int,int);//設置Button的左、右、寬、高;//應該盡可能地用Anchor、Dock,特殊情況下用Layout事件Form.MdiParent=(Form);//設置MDI父窗口//Active事件里this.Hide()是正道Form.Show();Form.Text=”Mytext”;//這兩句的順序不能//static不能修飾臨時變量,一般用來修飾類變量(不是類的對象實例變量!?。。〧orm.MdiParent = this;Form.TopLevel = true;Form.IsMdiContainer= true;Form. ActivateMdiChild//sqlconnection連接字符串@"Data Source= ./SQLEXPRESS;AttachDBFilename=C:/../*.MDF;Integrated Security=True;User Instance=True"))//sqlconnection連接的基本步驟using System.Data.SqlClient;Dataset dataset = new DataSet();using (SqlConnection conn = new SqlConnection(@"Data Source= ./SQLEXPRESS;AttachDBFilename=C:/SQL Server 2000 Sample Databases/NORTHWND.MDF;Integrated Security=True;User Instance=True")){conn.Open();SqlDataAdapter adapter = new SqlDataAdapter(conn.CreateCommand()); adapter.SelectCommand.CommandText = "select * from customers";adapter.Fill(dataset);foreach (DataRow row in dataset.Tables[0].Rows){string item=row["ContactTitle"]+","+row["ContactName"]; listBox1.Items.Add(item);}}ListBox.Items.Add(new string)//ListBox添加項//創建DataSet中的記錄DataRow row = DataSet.Tables[0].NewRow();row["**"] =***;dataset.Tables[0].Rows.Add(row);//更新DataSetDataRow row=DataSet.Table[0].Rows[index];row[“***”]=***;//刪除DataSet中的記錄DataSet.Tables[0].Rows.Remove(DataSet.Table[0].Rows[index]);//DataRow.Delete()和DataSet.Tables[0].Rows.Remove()不一樣,后者是從DataSet中徹底刪除DataRow row=DataSet.Table[0].Rows[index];row[“***”]=***;row.delete();TYPE varable=row[“***”,DataRowVersion.Original]// DataRow的完整訪問方式和DataRow.RowStateSwitch (row.RowState){case DataRowState.Deleted: row["***", DataRowVersion.Original]; case DataRowState.Added: row["["***"] case DataRowState.Modified: row["***", DataRowVersion.Original] row["***", DataRowVersion.Current]case DataRowVersion.Unchanged: row["***"]}//獲取部分特定狀態的數據集DataTable modifiedTable = DataSet.Tables[0].GetChanges(DataRowState.Added| DataRowState.Modified| DataRowState.Deleted);//創建數據庫查詢連接適配器的幾種方式SqlDataAdapter adapter = new SqlDataAdapter("select * from TABLENAME", SqlConnection); //最簡單SqlDataAdapter adapter = new SqlDataAdapter(SqlConnection.CreateCommand());adapter.SelectCommand.CommandText = "select * from TABLENAME ";SqlDataAdapter adapter = new sqldat SqlDataAdapter();adapter.SelectCommand = new SqlCommand("select * from TABLENAME ", SqlConnection);//萬能的數據集更新器SqlCommandBuilderSqlDataAdapter adapter = new SqlDataAdapter("select * from TABLENAME ", SqlConnection);new SqlCommandBuilder(adapter);try{adapter.Update(modifiedDataSet);PoulateListBox();}catch (System.Exception ex){}//多表數據集建議分別創建適配器SqlDataAdapter adapter1 = new SqlDataAdapter("select * from TABLENAME", SqlConnection); adapter1.Fill(DataSet,”TABLENAME1”);SqlDataAdapter adapter2 = new SqlDataAdapter("select * from TABLENAME", SqlConnection); adapter2.Fill(DataSet,”TABLENAME2”);////Make some changes to the DataSet .TABLENAME1 or DataSet .TABLENAME2//new SqlCommandBuilder(adapter1);adapter1.Update(DataSet,” TABLENAME1”);new SqlCommandBuilder(adapter2);adapter2.Update(DataSet,” TABLENAME2”);//創建DataSet自帶約束UniqueConstraint constrint = new UniqueConstraint(DataTable.Columns["***"]);//唯一性約束DataTable.Constraints.Add(constrint);//外鍵約束:ForeignKeyConstraint//關系基于兩張表的兩個列上,添加于兩張表共屬的數據集,并且自動生成分別在兩個表上生成UniqueConstraint 和ForeignKeyConstraintDataRelation relation = new DataRelation("CustomersOrders", DataTable.Columns["***"], DataTable.Columns["***"]);dataset.Relations.Add(relation);Form.Modal//判斷顯示方式是模式還是非模式,模式為true,非模式為false,只有在Load事件中和之后該屬性才有實際意義,在構造期間默認為falsemyForm.Control1.Text=”Data put in by a user”;//這樣不好,封裝性不強不易維護更新,用下面的pulbic String Control1Text{ get{ return Control1.Text;}Set{ Control1.Text;=value;}}//…myForm. Control1Text=” Data put in by a user”;//DialogResult res=ShowDialog()只是獲取對話框結果的快捷方式,完整方式如下void someButton_Click(object sender,EventArgs e){this.DialogResult=DialogResult.Retry; this.close();}someForm=new someForm();someForm.showDialog();DialogResult ref= someForm .DialogResult;if(ref= DialogResult.Retry)//…string path =Directory.GetCurrentDirectory();System.IO.FileStream aFile = new System.IO.FileStream(path, FileMode.Open);StreamReader sr = new StreamReader(aFile, System.Text.Encoding.Default);/*對于每個關聯的 SqlConnection,一次只能打開一個 SqlDataReaderSqlConnection 與 SqlDataAdapter 和 SqlCommand 一起使用,可以在連接 Microsoft SQL Server 數據庫時提高性能。對于所有第三方 SQL 服務器產品以及其他支持 OLE DB 的數據源,請使用 OleDbConnection。SqlConnection 超出范圍,則不會將其關閉。因此,必須通過調用 Close 或 Dispose 顯式關閉該連接。最好在using 塊內部打開連接。連接自字符串關鍵字不區分大小寫,并將忽略鍵/值對之間的空格。 不過,根據數據源的不同,值可能是區分大小寫的。 任何包含分號、單引號或雙引號的值必須用雙引號引起來。*/System.Data.SqlClient.SqlConnectionStringBuilder builder =new System.Data.SqlClient.SqlConnectionStringBuilder();builder["Data Source"] = "(local)";builder["integrated Security"] = true;builder["Initial Catalog"] = "AdventureWorks;NewValue=Bad";// 使用System.Data.SqlClient.SqlConnectionStringBuilder不需要擔心分號、單引號或雙引號的轉義問題Console.WriteLine(builder.ConnectionString);//打開數據庫的某個古老方法SqlConnection mc=new SqlConnection();mc.ConnectionString=”/*…*/”;mc.Open();//有關SqlCommand, SqlDataReader的基本使用SqlCommand scm=SqlConnection.CreateCommand();scm.CommandText=”select */*…*/”;SqlDataReader sdr=scm.ExecuteReader();sdr.Read();//…sdr.close();//以ToolStrip為例繪制簡便背景e.Graphics.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Point(0, toolStrip1.Height),new System.Drawing.Point(0, 0), Color.FromKnownColor(KnownColor.ControlDark), Color.FromKnownColor(KnownColor.ControlLight)), toolStrip1.ClientRectangle);//獲取Color的幾種方式Color.FromKnownColor(KnownColor.ControlLight);Color.FromArgb(int r,int g,int b);Color.FromArgb(int a,int r,int g,int b);//a表示透明度,0-255,0為全透明,255為不透明,
/*
如果安裝時,改了實例名,也就是命名實例,那么客戶端在連接時,要使用機器名加實例名來進行標識:計算機名/實例名。
*/
//This table shows all connection string properties for the ADO.NET SqlConnection object. Most of the properties are also used in ADO. All properties and descriptions is from msdn.
Name | Default | Description |
application Name |
| The name of the application, or '.Net SqlClient Data Provider' if no application name is provided. |
AttachDBFilename |
| The name of the primary file, including the full path name, of an attachable database. The database name must be specified with the keyWord 'database'. |
Connect Timeout | 15 | The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. |
Connection Lifetime | 0 | When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by connection lifetime. Useful in clustered configurations to force load balancing between a running server and a server just brought on-line. |
Connection Reset | 'true' | Determines whether the database connection is reset when being removed from the pool. Setting to 'false' avoids making an additional server round-trip when obtaining a connection, but the programmer must be aware that the connection state is not being reset. |
Current Language |
| The SQL Server Language record name. |
Data Source |
| The name or network address of the instance of SQL Server to which to connect. |
Enlist | 'true' | When true, the pooler automatically enlists the connection in the creation thread's current transaction context. |
Initial Catalog |
| The name of the database. |
Integrated Security | 'false' | Whether the connection is to be a secure connection or not. Recognized values are 'true', 'false', and 'sspi', which is equivalent to 'true'. |
Max Pool Size | 100 | The maximum number of connections allowed in the pool. |
Min Pool Size | 0 | The minimum number of connections allowed in the pool. |
Network Library | 'dbmssocn' | The network library used to establish a connection to an instance of SQL Server. Supported values include dbnmpntw (Named Pipes), dbmsrpcn (Multiprotocol), dbmsadsn (Apple Talk), dbmsgnet (VIA), dbmsipcn (Shared Memory) and dbmsspxn (IPX/SPX), and dbmssocn (TCP/IP). |
Packet Size | 8192 | Size in bytes of the network packets used to communicate with an instance of SQL Server. |
Password |
| The password for the SQL Server account logging on. |
Persist Security Info | 'false' | When set to 'false', security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values including the password. |
Pooling | 'true' | When true, the SQLConnection object is drawn from the appropriate pool, or if necessary, is created and added to the appropriate pool. |
User ID |
| The SQL Server login account. |
Workstation ID | the local computer name | The name of the workstation connecting to SQL Server. |
新聞熱點
疑難解答