顶部468*60ad 顶部468*60ad 顶部468*60ad 顶部468*60ad

.NET 开发中的一些小技巧集锦

2007-10-31 10:15:48  来源:网页教学网 小马甲

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

  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 ();
Webjx.Com

  16.通过代码如何输入多行文本?(How to enter multiline text in textbox through code? ) Webjx.Com

  利用TextBox控件的LINES属性

  string [] strAddress = {"Mukund Pujari","Global Transformation Technologies","Pune, India"};
  textBox1.MultiLine=true;
  textBox1.Lines=strAddress;
网页教学网

  或者 Webjx.Com

  textBox1.Text="Line 1\r\nLine2\r\nLine3.";

  或者 Webjx.Com

  用"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";

Webjx.Com

  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? )

Webjx.Com

  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

Webjx.Com

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

  通过设置控件背景色的alpha值网页教学网

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

Webjx.Com

  注意:在设计时手动输入这些值,不要用颜色选取

  23. 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

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

  button1.PerformClick();
网页教学网

共2页: 上一页 [1] 2 下一页

文章评论

共有 0 位网友发表了评论 查看完整内容

推荐文章