日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

.NET开发的一些小技巧

發(fā)布時(shí)間:2024/9/20 asp.net 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .NET开发的一些小技巧 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.?如何創(chuàng)建一個(gè)可改變大小沒有標(biāo)題欄的窗體?(How?to?create?a?form?with?resizing?borders?and?no?title?bar?)

form1.Text?=?string.?Empty;?

form1.ControlBox?=?false;

2.?如何在.NET的Windows窗體上啟用XP主題集?(How?to?use?XP?Themes?with?Windows?Forms?using?the?.NET?)

確認(rèn)你的控件中FlatStyle屬性已經(jīng)修改為System,再修改Main方法。

static?void?Main()?

{?

Application.EnableVisualStyles();

Application.DoEvents();?

Application.?Run(new?Form1());?

}?

3.?如何為一個(gè)窗體設(shè)置一個(gè)默認(rèn)按鈕?(How?to?set?the?default?button?for?a?form?)

form1.AcceptButton?=?button1;

4.?如何為一個(gè)窗體設(shè)置一個(gè)取消按鈕?(How?to?set?the?Cancel?button?for?a?form?)

form1.CancelButton?=?button1;

5.?如何阻止一個(gè)窗體標(biāo)題顯示在任務(wù)欄上?(How?to?prevent?a?form?from?being?shown?in?the?taskbar?)

設(shè)置窗體的ShowIntaskbar屬性為False

6.?如何用現(xiàn)有可用字體綁定到ComboBox控件?(How?to?fill?a?ComboBox?with?the?available?fonts?)

comboBox1.Items.AddRange?(FontFamily.Families);

7.?如何禁止TextBox控件默認(rèn)的郵件菜單?(How?to?disable?the?default?ContextMenu?of?a?TextBox?)

textBox1.ContextMenu?=?new?ContextMenu?();

8.?如何獲取“我的文檔”等一些系統(tǒng)文件夾路徑?(How?to?get?the?path?for?"My?documents"?and?other?system?folders?)

Environment.SpecialFolder中包含了一些系統(tǒng)文件夾信息

MessageBox.Show(Environment.GetFolderPath(?Environment.SpecialFolder.Personal?));?

9.?如何獲取應(yīng)用程序當(dāng)前執(zhí)行的路徑?(How?to?get?the?path?to?my?running?EXE?)

string?appPath?=?Application.ExecutablePath;?

10.?如何確定當(dāng)前運(yùn)行的系統(tǒng)?(How?to?determine?which?operating?system?is?running?)

OperatingSystem?os?=?Environment.OSVersion;

MessageBox.Show(os.Version.ToString());

MessageBox.Show(os.Platform.ToString());

11.?如何從完整的路徑中獲取文件名?(How?to?get?a?file's?name?from?the?complete?path?string?)

用System.IO.Path.GetFileName?和?System.IO.Path.GetFileNameWithoutExtension(無擴(kuò)展名)的方法

12.?如何從完整的路徑中獲取文件擴(kuò)展名?(How?to?get?a?file's?extension?from?the?complete?path?string?)

用System.IO.Path.GetExtension方法

13.?如何使沒有選擇日期的DateTimePicker控件為空文本?(How?to?make?the?DateTimePicker?show?empty?text?if?no?date?is?selected?)

dateTimePicker1.CustomFormat?=?"?";

dateTimePicker1.Format?=?DateTimePickerFormat.Custom;

14.?如何在Report?Viewer中隱藏Crystal?Report的狀態(tài)欄?(How?to?hide?the?status?bar?of?Crystal?Report?in?Report?Viewer?)

foreach(object?obj?in?this.crystalReportViewer1.Controls)

{?????

if(?obj.GetType()==?typeof(System.Windows.Forms.StatusBar))?

{?????

StatusBar?sBar=(StatusBar)obj;

sBar.Visible=false;

}?????

}

15.?如何利用Crystal?Report程序來生成PDF版本?(How?to?generate?PDF?version?of?Crystal?Report?programmatically?)

Reportdocument?O_Report=new?Reportdocument();

ExportOptions?exportOpts?=?new?ExportOptions();

PdfRtfWordFormatOptions?pdfFormatOpts?=?new?PdfRtfWordFormatOptions?();

DiskFileDestinationOptions?diskOpts?=?new?DiskFileDestinationOptions();

exportOpts?=?O_Report.ExportOptions;

//?設(shè)置PDF格式???

exportOpts.ExportFormatType?=?ExportFormatType.PortableDocFormat;

exportOpts.FormatOptions?=?pdfFormatOpts;

//?設(shè)置文件選項(xiàng)和導(dǎo)出

exportOpts.ExportDestinationType?=?ExportDestinationType.DiskFile;

diskOpts.DiskFileName?=?"C://Trial.pdf";?//設(shè)置PDF導(dǎo)出路徑????

exportOpts.DestinationOptions?=?diskOpts;

O_Report.Export?();

16.通過代碼如何輸入多行文本?(How?to?enter?multiline?text?in?textbox?through?code??)

利用TextBox控件的LINES屬性

string?[]?strAddress?=?{"Mukund?Pujari","Global?Transformation?Technologies","Pune,?India"};

textBox1.MultiLine=true;

textBox1.Lines=strAddress;

或者?textBox1.Text="Line?1 r nLine2 r nLine3.";

或者?用"System.Environment.NewLine"來替代換行符號

17.?如何在DataGrid中去掉CheckBox不確定狀態(tài)?(How?to?remove?the?indeterminate?status?of?checkbox?in?datagrid?)

DataGridTableStyle?ts1?=?new?DataGridTableStyle();?//創(chuàng)建Table樣式

ts1.MappingName?=?"Items";?//分配要應(yīng)用樣式的Data?Table

DataGridColumnStyle?boolCol?=?new?DataGridBoolColumn();?//?創(chuàng)建CheckBox列

boolCol.MappingName?=?"ch";?//分配數(shù)據(jù)列名稱

boolCol.AllowNull=false;?//?修改AllowNull屬性

18.?如何在用一個(gè)數(shù)據(jù)源DataTable綁定兩個(gè)控件,確保變化不反映在兩個(gè)控件中?(?How?to?bind?two?controls?to?the?same?DataTable?without?having?changes?in?one?control?also?change?the?other?control?)

我們在一個(gè)Form中放置一個(gè)ListBox和一個(gè)ComboBox控件,當(dāng)數(shù)據(jù)源是一個(gè)DataTable而且綁定的valueMember一致的時(shí)候我們選擇ListBox中的一個(gè)Item時(shí),ComboBox控件中的相同的Item也會(huì)被自動(dòng)選中,我們可以采取建立新的上下文綁定對象來拒絕這樣的同步操作

comboBox1.DataSource?=?dataset.Tables[?"Items"?];?

comboBox1.valueMember?=?"CustomerID";?

comboBox1.DisplayMember?=?"CustomerID";?

listBox1.BindingContext?=?new?BindingContext();?//?設(shè)置新的上下文綁定對象

listBox1.DataSource?=?dataset.Tables[?"Items"?];?

listBox1.valueMember?=?"CustomerID";?

listBox1.DisplayMember?=?"CustomerID";

19.?一個(gè)簡單的創(chuàng)建鏈接字符串的方法。(An?easy?way?to?build?connection?string.)

記事本創(chuàng)建一個(gè)New.udl的文件,一個(gè)Microsoft?數(shù)據(jù)鏈接文件

雙擊打開,熟悉吧

按照向?qū)?chuàng)建完成一個(gè)數(shù)據(jù)庫鏈接,測試成功

確定后,鏈接字符串寫入這個(gè)文件,用記事本打開就看到了

20.?如何打開客戶端E-Mail程序,Windows應(yīng)用和Web應(yīng)用?(?How?to?open?default?E-mail?client?on?your?system?with?all?parameters?entered?in?it,like?Outlook?Express?or?Eudora,?from?your?.NET?windows?or?Web?Application??)

Web?Application:

A?href="/"mailto:email@address1.com,email@address2.com?cc=email@address3.com&Subject=Hello&body=Happy?New?Year"

Windows?Application:

引用System.Diagnostics.Process?命名空間

Process?process?=?new?Process();

process.StartInfo.FileName?=?"mailto:email@address1.com,email@address2.com?subject=Hello&cc=email@address3.com

&bcc=email@address4.com&body=Happy?New?Year"?

process.Start();


21.?How?to?find?whether?your?system?has?mouse?or?the?number?of?buttons,?whether?it?has?wheel,?or?whether?the?mouse?buttons?are?swapped?or?size?of?your?monitor?and?many?such?information??

22.?如何使Windows?Form上的Panel或者Label控件半透明?(How?to?make?a?Panel?or?Label?semi-transparent?on?a?Windows?Form??)

通過設(shè)置控件背景色的alpha值

panel1.BackColor?=?Color.FromArgb(65,?204,?212,?230);

注意:在設(shè)計(jì)時(shí)手動(dòng)輸入這些值,不要用顏色選取


23.?如何觸發(fā)Button的Click事件?(How?to?trigger?a?button?click?event??)

button1.PerformClick();

總結(jié)

以上是生活随笔為你收集整理的.NET开发的一些小技巧的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。