国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

WinForm常用代碼

2019-11-14 16:51:02
字體:
供稿:網(wǎng)友
//ToolStripSplitButton是標(biāo)準(zhǔn)按鈕和下拉按鈕的組合,各自工作,但有聯(lián)系,感覺上后者是沒有向下箭頭ToolStripDropDownButton;
ToolStripDropDownButton只含有一個(gè)按鈕,可以選擇有沒有向下箭頭的標(biāo)志,單擊時(shí)顯示關(guān)聯(lián)的 ToolStripDropDown 的控件。兩者均可改變箭頭標(biāo)志在做還是在右。//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);//這句是關(guān)鍵,不能?在OnPaint里畫BitBmp在這里調(diào)InvalidateInvalidate(Rectangle)//規(guī)定區(qū)域重繪,解決閃爍的另一種方法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();//點(diǎn)移位Point.Offset(Point);Point.Offset(int,int);Rectangle.Contains(Point);//截獲標(biāo)題欄消息,自畫標(biāo)題欄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[]{});//添加多個(gè)控件Control.ResumeLayout;// 在它和SuspendLayout之間的代碼不會引起Parent Control的重繪Button[] buttons = new Button[] {};//大膽地設(shè)類數(shù)組吧~Button.SetBounds(int,int,int,int);//設(shè)置Button的左、右、寬、高;//應(yīng)該盡可能地用Anchor、Dock,特殊情況下用Layout事件Form.MdiParent=(Form);//設(shè)置MDI父窗口//Active事件里this.Hide()是正道Form.Show();Form.Text=”Mytext”;//這兩句的順序不能//static不能修飾臨時(shí)變量,一般用來修飾類變量(不是類的對象實(shí)例變量!!!)Form.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添加項(xiàng)//創(chuàng)建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["***"]}//獲取部分特定狀態(tài)的數(shù)據(jù)集DataTable modifiedTable = DataSet.Tables[0].GetChanges(DataRowState.Added| DataRowState.Modified| DataRowState.Deleted);//創(chuàng)建數(shù)據(jù)庫查詢連接適配器的幾種方式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);//萬能的數(shù)據(jù)集更新器SqlCommandBuilderSqlDataAdapter adapter = new SqlDataAdapter("select * from TABLENAME ", SqlConnection);new SqlCommandBuilder(adapter);try{adapter.Update(modifiedDataSet);PoulateListBox();}catch (System.Exception ex){}//多表數(shù)據(jù)集建議分別創(chuàng)建適配器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”);//創(chuàng)建DataSet自帶約束UniqueConstraint constrint = new UniqueConstraint(DataTable.Columns["***"]);//唯一性約束DataTable.Constraints.Add(constrint);//外鍵約束:ForeignKeyConstraint//關(guān)系基于兩張表的兩個(gè)列上,添加于兩張表共屬的數(shù)據(jù)集,并且自動生成分別在兩個(gè)表上生成UniqueConstraint 和ForeignKeyConstraintDataRelation relation = new DataRelation("CustomersOrders", DataTable.Columns["***"], DataTable.Columns["***"]);dataset.Relations.Add(relation);Form.Modal//判斷顯示方式是模式還是非模式,模式為true,非模式為false,只有在Load事件中和之后該屬性才有實(shí)際意義,在構(gòu)造期間默認(rèn)為falsemyForm.Control1.Text=”Data put in by a user”;//這樣不好,封裝性不強(qiáng)不易維護(hù)更新,用下面的pulbic String Control1Text{ get{ return Control1.Text;}Set{ Control1.Text;=value;}}//…myForm. Control1Text=” Data put in by a user”;//DialogResult res=ShowDialog()只是獲取對話框結(jié)果的快捷方式,完整方式如下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);/*對于每個(gè)關(guān)聯(lián)的 SqlConnection,一次只能打開一個(gè) SqlDataReaderSqlConnection 與 SqlDataAdapter 和 SqlCommand 一起使用,可以在連接 Microsoft SQL Server 數(shù)據(jù)庫時(shí)提高性能。對于所有第三方 SQL 服務(wù)器產(chǎn)品以及其他支持 OLE DB 的數(shù)據(jù)源,請使用 OleDbConnection。SqlConnection 超出范圍,則不會將其關(guān)閉。因此,必須通過調(diào)用 Close 或 Dispose 顯式關(guān)閉該連接。最好在using 塊內(nèi)部打開連接。連接自字符串關(guān)鍵字不區(qū)分大小寫,并將忽略鍵/值對之間的空格。 不過,根據(jù)數(shù)據(jù)源的不同,值可能是區(qū)分大小寫的。 任何包含分號、單引號或雙引號的值必須用雙引號引起來。*/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不需要擔(dān)心分號、單引號或雙引號的轉(zhuǎn)義問題Console.WriteLine(builder.ConnectionString);//打開數(shù)據(jù)庫的某個(gè)古老方法SqlConnection mc=new SqlConnection();mc.ConnectionString=”/*…*/”;mc.Open();//有關(guān)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為不透明,

 

/*

如果安裝時(shí),改了實(shí)例名,也就是命名實(shí)例,那么客戶端在連接時(shí),要使用機(jī)器名加實(shí)例名來進(jìn)行標(biāo)識:計(jì)算機(jī)名/實(shí)例名。

*/

 

//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
-or-
extended properties
-or-
Initial File Name

 

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
-or-
Connection 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
-or-
Server
-or-
Address
-or-
Addr
-or-
Network Address

 

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
-or-
Database

 

The name of the database.

Integrated Security
-or-
Trusted_Connection

'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
-or-
Net

'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).
The corresponding network DLL must be installed on the system to which you connect. If you do not specify a network and you use a local server (for example, "." or "(local)"), shared memory is used.

Packet Size

8192

Size in bytes of the network packets used to communicate with an instance of SQL Server.

Password
-or-
Pwd

 

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.

 

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 信丰县| 资阳市| 札达县| 灵台县| 宣威市| 淮南市| 离岛区| 洞头县| 宾川县| 凤庆县| 桂东县| 陆丰市| 涿鹿县| 荥阳市| 淳安县| 祁阳县| 岱山县| 屏边| 重庆市| 迭部县| 新巴尔虎左旗| 井陉县| 米易县| 辛集市| 金湖县| 卢氏县| 远安县| 巫山县| 含山县| 治县。| 江源县| 陈巴尔虎旗| 马尔康县| 法库县| 蒙山县| 鄂伦春自治旗| 白玉县| 日喀则市| 红河县| 六枝特区| 自贡市|