您的位置:首页 > 编程语言 > VB

.NET开发中的一些小技巧

2007-08-11 01:19 363 查看
这篇文章来自是Mukund Pujari的《Some Cool Tips for .NET》,本人给大家翻译总结一下,我英语水平也就那么回事,不合适的地方还是请大家提出来。
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 ">comboBox1.Items.AddRange (">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 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();

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息