| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1691 人关注过本帖
标题:[分享]c# 有用的知识点
只看楼主 加入收藏
tianlei
Rank: 1
等 级:新手上路
帖 子:180
专家分:0
注 册:2005-2-26
收藏
 问题点数:0 回复次数:10 
[分享]c# 有用的知识点


1. 如何创建一个可改变大小没有标题栏的窗体?(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?)

确认你的控件中FlatStyle属性已经修改为System,再修改Main方法。

static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application. Run(new Form1());
}


3. 如何为一个窗体设置一个默认按钮?(How to set the default button for a form?)

form1.AcceptButton = button1;

4. 如何为一个窗体设置一个取消按钮?(How to set the Cancel button for a form?)

form1.CancelButton = button1;

5. 如何阻止一个窗体标题显示在任务栏上?(How to prevent a form from being shown in the taskbar?)

设置窗体的ShowIntaskbar属性为False

6. 如何用现有可用字体绑定到ComboBox控件?(How to fill a ComboBox with the available fonts?)

comboBox1.Items.AddRange (FontFamily.Families);

7. 如何禁止TextBox控件默认的邮件菜单?(How to disable the default ContextMenu of a TextBox?)

textBox1.ContextMenu = new ContextMenu ();

8. 如何获取“我的文档”等一些系统文件夹路径?(How to get the path for "My Documents" and other system folders?)

Environment.SpecialFolder中包含了一些系统文件夹信息
MessageBox.Show(Environment.GetFolderPath( Environment.SpecialFolder.Personal ));

9. 如何获取应用程序当前执行的路径?(How to get the path to my running EXE?)

string appPath = Application.ExecutablePath;

10. 如何确定当前运行的系统?(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(无扩展名)的方法

12. 如何从完整的路径中获取文件扩展名?(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的状态栏?(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;
// 设置PDF格式
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.FormatOptions = pdfFormatOpts;
// 设置文件选项和导出
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
diskOpts.DiskFileName = "C://Trial.pdf"; //设置PDF导出路径
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不确定状态?(How to remove the indeterminate status of checkbox in datagrid?)

DataGridTableStyle ts1 = new DataGridTableStyle(); //创建Table样式
ts1.MappingName = "Items"; //分配要应用样式的Data Table
DataGridColumnStyle boolCol = new DataGridBoolColumn(); // 创建CheckBox列
boolCol.MappingName = "ch"; //分配数据列名称
boolCol.AllowNull=false; // 修改AllowNull属性

18. 如何在用一个数据源DataTable绑定两个控件,确保变化不反映在两个控件中?( How to bind two controls to the same DataTable without having changes in one control also change the other control?)

我们在一个Form中放置一个ListBox和一个ComboBox控件,当数据源是一个DataTable而且绑定的ValueMember一致的时候我们选择ListBox中的一个Item时,ComboBox控件中的相同的Item也会被自动选中,我们可以采取建立新的上下文绑定对象来拒绝这样的同步操作
comboBox1.DataSource = dataset.Tables[ "Items" ];
comboBox1.ValueMember = "CustomerID";
comboBox1.DisplayMember = "CustomerID";

listBox1.BindingContext = new BindingContext(); // 设置新的上下文绑定对象
listBox1.DataSource = dataset.Tables[ "Items" ];
listBox1.ValueMember = "CustomerID";
listBox1.DisplayMember = "CustomerID";

19. 一个简单的创建链接字符串的方法。(An easy way to build connection string.)

记事本创建一个New.udl的文件,一个Microsoft 数据链接文件
双击打开,熟悉吧
按照向导创建完成一个数据库链接,测试成功
确定后,链接字符串写入这个文件,用记事本打开就看到了

20. 如何打开客户端E-Mail程序,Windows应用和Web应用?( 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. VB.NET和C#有什么不同?( What is difference beween VB.NET and C#.NET? )

去微软下载一个文档吧,http://download.microsoft.com/download/6/3/5/6354bf47-c597-4029-89e9-2495e7539ab9/vbcsharpwp.exe

22. 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?

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

通过设置控件背景色的alpha值
panel1.BackColor = Color.FromArgb(65, 204, 212, 230);
注意:在设计时手动输入这些值,不要用颜色选取

24. C#程序的主函数写[STA Thread] 属性是什么目的?(What is the purpose of the [STA Thread] attribute for the Main method of a C# program? )

http://community.csdn.net/Expert/topic/4132/4132313.xml?temp=.2285272


25. 如何触发Button的Click事件?(How to trigger a button click event? )

button1.PerformClick();

搜索更多相关主题的帖子: 知识点 Main resizing form How 
2007-11-08 16:32
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
支持!

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-11-08 16:41
a464108502
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-11-5
收藏
得分:0 
好东西

2007-11-08 18:03
koffans
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-5-2
收藏
得分:0 
还有中英文对照那.

2007-11-08 19:49
liujinlin109
Rank: 1
来 自:福建福州
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-7-13
收藏
得分:0 
http://dev.yesky.com/284/7634784.shtml

到这里看看吧 原版的

诚征小MM,共同来灌水;我灌长江头,君灌长江尾。
2007-11-09 09:12
zh_hn
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-12-24
收藏
得分:0 
很好

2007-11-17 00:14
pacocai
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1583
专家分:0
注 册:2007-3-12
收藏
得分:0 

顶起,新手问的常见问题,建议版主们把这个新手常见问题集,这样可以让新手们能更好的学习C#。也能让大家省下更多的时间去思考和学习。


浮生若梦天边月,醉死如酒水中星。红楼一梦千人叹,岂让万夫空做贱。博客:http://hi.baidu.com/rxvip
2007-11-17 07:50
寂静夜
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-11-17
收藏
得分:0 
顶起 偶就是新手 3Q

2007-11-18 12:32
farderce
Rank: 1
来 自:上海
等 级:新手上路
帖 子:146
专家分:3
注 册:2006-1-11
收藏
得分:0 
System.Diagnostics.Process.start("D:a.wav");
在一个button上调用鼠标移上事件然后触发上面那句
我不想让它弹出播放器,怎,么做哦 (C#)
2007-11-19 10:48
达文西
Rank: 1
等 级:新手上路
威 望:1
帖 子:117
专家分:0
注 册:2007-8-4
收藏
得分:0 
gooOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOod
2007-11-20 11:02
快速回复:[分享]c# 有用的知识点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016720 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved