form.Close()和form.Hide()+form.Dispose()的区别?

zhanghaif 2006-07-28 03:16:40
如提!这两者在程序上的直观效果好像是一样的?这两者在功能上有什么区别吗?

我现在要做的是:有两个窗体form1和form2
在form1中单击一个按钮后打开form2窗体,并使得form1窗体不可见或者不可操作。
关闭form2窗体时form1窗体又恢复原样?象这样应该怎样操作?

还有,单击窗体右上角的×来关闭窗体时是调用的窗体的Closeing()事件吗?
...全文
1090 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanghaif 2006-07-28
  • 打赏
  • 举报
回复
谢谢jack6512006(雨浪) 和 tonysunny(tonysunny) 两个方法都可以
jack6512006 2006-07-28
  • 打赏
  • 举报
回复
不好意思
我把
form1.owner=f这句写反了
应该是
f.owner=form1
就行了
worms8888 2006-07-28
  • 打赏
  • 举报
回复
private void simpleButton1_Click(object sender, System.EventArgs e)
{
this.Hide();
Form2 f2 = new Form2();
f2.ShowDialog();
this.Show();
}

当关闭form2的时候,form1就自动出来了
zhanghaif 2006-07-28
  • 打赏
  • 举报
回复
多谢jack6512006(雨浪)的回答,我按照你的方法谢了函数,现在有点小问题,我谢了一个自定义的close事件如下:
private void Closing(object sender, System.ComponentModel.CancelEventArgs e)
{

this.Show();
MessageBox.Show("aa");
}
如果没有MessageBox.Show("aa");的话,程序直接退出。添加这这行代码确实能够显示原来的form1窗体,但是按下“确定”后程序还是直接退出了。
这个问题该怎么解决呢?
tonysunny 2006-07-28
  • 打赏
  • 举报
回复
在form1中单击一个按钮后打开form2窗体,并使得form1窗体不可见或者不可操作
//form1按钮代码
private void simpleButton1_Click(object sender, System.EventArgs e)
{
this.Hide();
Form2 f2 = new Form2();
f2.Owner = this;
f2.Show();
}
关闭form2窗体时form1窗体又恢复原样?象这样应该怎样操作
//form2窗体关闭事件代码
private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.Owner.Show();
}
jack6512006 2006-07-28
  • 打赏
  • 举报
回复
我写C#代码有点怪,呵呵
因为我vb.net和C#都用
常常搞手写代码搞浑,不好意思了
jack6512006 2006-07-28
  • 打赏
  • 举报
回复
还有,单击窗体右上角的×来关闭窗体时是调用的窗体的Closeing()事件吗?

温柔的对你说一句:是的
jack6512006 2006-07-28
  • 打赏
  • 举报
回复
在form1中单击一个按钮后打开form2窗体,并使得form1窗体不可见或者不可操作。
关闭form2窗体时form1窗体又恢复原样?象这样应该怎样操作?

在form1中写如下代码
form2 f=new form2()
form1.owner=f
f.closing+=自定义的close事件 //这里在form1中写一个自定义的close事件
f.show()
this.hide

void closing(什么sender,什么e) //级不住了,自己写
{
this.show()
}
smartstar2005 2006-07-28
  • 打赏
  • 举报
回复
同意楼上的

如果你在Form中有个变量,当你执行Hide后那个变量还是可以访问的,但你执行了其他的两个操作后就不可以了
jack6512006 2006-07-28
  • 打赏
  • 举报
回复
举个例子dispose与close的区别

存在form1,form2
form1中存在一个button名为btn
在form1中声明form2的实例
form2 f=new form2
f.Contrls.Add(btn)

如果写如下代码
f.close()
btn这个从form1移到form2的对象不会释放,可以用form1.Contrl.Add(btn)加载回来
如果f.dispose就释放了
jack6512006 2006-07-28
  • 打赏
  • 举报
回复
form.Close()
关闭窗体,并不一定释放与之相关的资源
form.Hide()
隐藏窗体,并没有实际关闭或者释放资源,可使用form.show()恢复
form.dispose()
释放窗体资源
没法下载,到这里折腾一把试试。 本文由abc2253130贡献 doc文档可能在WAP端浏览体验不佳。建议您优先选择TXT,或下载源文件到本机查看。 C#(WINFORM)学习 一、 C#基础 基础 类型和变量 类型和变量 类型 C# 支持两种类型:“值类型”和“引用类型”。值类型包括简单类型(如 char、int 和 float 等)、枚举类型和结构类型。引用类型包括类 (Class)类 型、接口类型、委托类型和数组类型。 变量的类型声明 变量的类型声明 每个变量必须预先声明其类型。如 int a; int b = 100; float j = 4.5; string s1; 用 object 可以表示所有的类型。 预定义类型 下表列出了预定义类型,并说明如何使用。 类型 object 说明 所有其他类型的最终 基类型 字符串类型; 字符串是 Unicode 字符序列 8 位有符号整型 16 位有符号整型 32 位有符号整型 64 位有符号整型 示例 object o = null; 范围 string sbyte short int long string s = "hello"; sbyte val = 12; short val = 12; int val = 12; long val1 = 12; -128 到 127 -32,768 到 32,767 -2,147,483,648 2,147,483,647 -9,223,372,036,854,775,808 到 第1页 C#(WINFORM)学习 long val2 = 34L; 到 9,223,372,036,854,775,807 byte ushort 8 位无符号整型 16 位无符号整型 byte val1 = 12; ushort val1 = 12; uint val1 = 12; uint 32 位无符号整型 uint val2 = 34U; ulong val1 = 12; ulong val2 = 34U; ulong 64 位无符号整型 ulong val3 = 56L; ulong val4 = 78UL; float 单精度浮点型 float val = 1.23F;7 位 double val1 = 1.23; double 双精度浮点型 double val2 = ±5.0 × 10?324 ±1.7 × 10 308 0 到 255 0 到 65,535 0 到 4,294,967,295 0 到 18,446,744,073,709,551,615 ±1.5 × 10?45 ±3.4 × 10 38 到 到 4.56D;15-16 布尔型;bool 值或为 真或为假 字符类型;char 值是 一个 Unicode 字符 精确的小数类型, 具有 28 个有效数字 bool val1 = true; bool val2 = false; char val = 'h'; decimal val = bool char decimal DateTime ±1.0 × 10?28 ±7.9 × 10 28 到 1.23M;28-29 变量转换 简单转换: float f = 100.1234f; 可以用括号转换: short s = (short)f 也可以利用 Convert 方法来转换: string s1; s1=Convert.ToString(a); MessageBox.Show(s1); 常用 Convert 方法有: 第2页 C#(WINFORM)学习 C# Convert.ToBoolean Convert.ToByte Convert.ToChar Convert.ToDateTime Convert.ToDecimal Convert.ToDouble Convert.ToInt16 Convert.ToInt32 Convert.ToInt64 Convert.ToSByte Convert.ToSingle Convert.ToString Convert.ToUInt16 Convert.ToUInt32 Convert.ToUInt64 备注 Math 类 常用科学计算方法: C# Math.Abs Math.Sqrt Math.Ro
设置窗体的代码解释 Imports System.Diagnostics Public Class 设置窗体 Private shutTime As String '关机时间的字符串 Private IsToday As Boolean = True '判断是否是今天的变量 Private delay As Integer '延时多少秒放关机 Private lastTime As Integer '关机的倒计时 Private action As String '关机或重启或注销 Private shellText As String '执行的命令字符串 Private firstShow As Boolean = True Private SysTime As Boolean = False Private autoHide As Boolean = True '启动自动隐藏 Private TotalData As New System.Diagnostics.PerformanceCounter("Network Interface", "Bytes Total/sec", "MS TCP Loopback interface") Private proTime As New System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total") '双击右下角的图标的响应事件 Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick If (Me.Visible = False) Then Me.Show() End If End Sub '重载窗体的关闭事件,使窗体隐藏 Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing e.Cancel = True '取消窗体的关闭动作 delayTime.Value = delay '还原delayTime控件的值 StrToItems() '还原ListBox的值 Me.Hide() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.SelectedIndex = 2 '设置默认选项 "每天" ComboBox2.SelectedIndex = 4 '设置默认选项 "关机" Timer1.Start() readReg() '读取存放在注册表的信息 StrToItems() '把字符串的信息读取到ListBox delayTime.Value = delay '把延时时间读取到delayTime控件 DateTimePicker1.Value = Today End Sub Private Sub 退出程序ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出程序ToolStripMenuItem.Click Me.Dispose() End Sub Private Sub 立即取消关机ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即取消关机ToolStripMenuItem1.Click Timer2.Stop() 取消窗体.Close() Shell("shutdown -a") Timer1.Start() End Sub Private Sub 设置关机计划ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 设置关机计划ToolStripMenuItem.Click If Me.Visible = False Then Me.Show() End If End Sub '点击确定按钮的事件处理 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click '判断是否要开机自动运行 If autoCheck.Checked Then 创建开机自动运行() Else 删除开机自动运行() End If If Me.HideCheck.Checked Then autoHide = True Else autoHide = False End If If Me.regCheck.Checked Then 禁止修改注册表() Else 取消禁止修改注册表() End If If Me.ManCheck.Checked Then 禁止使用任务管理器() Else 取消禁止使用任务管理器() End If If Me.SysTimeCheck.Checked Then SysTime = True Else SysTime = False End If '四舍五入delayTime控件的值 delay = Math.Round(delayTime.Value, MidpointRounding.AwayFromZero) Me.Hide() ItemsToStr() '把listBox的信息保存到字符串中 writeReg() '把字符串保存把注册表中 End Sub '取消按钮事件 Private Sub canelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles canelButton.Click StrToItems() '还原ListBox的值 delayTime.Value = delay '还原delayTime控件的值 Me.Hide() End Sub '点击添加按钮 Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click Dim tempStr As String = "" If ComboBox1.Items.Item(ComboBox1.SelectedIndex) = "指定日期" Then tempStr = DateTimePicker1.Value.ToShortDateString Else tempStr = ComboBox1.SelectedItem End If tempStr &= "," & CStr(Math.Round(hourNum.Value, MidpointRounding.AwayFromZero)) & ":" & CStr(Math.Round(minNum.Value, MidpointRounding.AwayFromZero)) & ":" & CStr(Math.Round(secNum.Value, MidpointRounding.AwayFromZero)) & "," Select Case ComboBox2.SelectedItem Case "打开网址" tempStr &= "打开网址" & "[" & TextBox1.Text.Replace(";", ";").Replace(":", ":") & "]" Case "提醒信息" tempStr &= "提醒信息" & "[" & TextBox1.Text.Replace(";", ";").Replace(":", ":") & "]" Case "打开文件" tempStr &= "打开文件" & "[" & TextBox1.Text.Replace(";", ";").Replace(":", ":") & "]" Case Else tempStr &= ComboBox2.SelectedItem End Select ListBox1.Items.Add(tempStr) End Sub '点击清除按钮 Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click ListBox1.Items.Clear() End Sub '把ListBox的值保存到字符串ShutTime Private Sub ItemsToStr() Dim i As Integer shutTime = "" For i = 0 To ListBox1.Items.Count - 1 '把ListBox中的各项连接到shutTime shutTime &= ListBox1.Items.Item(i) & ";" Next If shutTime "" Then '去除最后一个 ";" shutTime = Mid(shutTime, 1, shutTime.Length - 1) End If End Sub '把字符串ShutTime的值还原到ListBox Private Sub StrToItems() If shutTime "" Then '如果shutTime有保存信息 Dim temp() As String = shutTime.Split(";") 'temp字符串数组存放shutTime以";"分隔的各个字符子串 Dim t As String 't存放temp字符串数组的一项 ListBox1.Items.Clear() For Each t In temp If Not (Mid(t, 1, 2) = "今天" And Not IsToday) Then '如果今天还没过了 ListBox1.Items.Add(t) End If Next End If End Sub '读取注册表保存的信息 Private Sub readReg() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey Try key = Microsoft.Win32.Registry.LocalMachine subkey = key.OpenSubKey("SOFTWARE\AutoShutdown") shutTime = subkey.GetValue("time") delay = CInt(subkey.GetValue("delayTime")) autoHide = subkey.GetValue("autoHide") If (CStr(Today()) subkey.GetValue("day")) Then IsToday = False End If Catch ex As Exception shutTime = "" IsToday = True End Try End Sub Private Sub 禁止修改注册表() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser subkey = key.CreateSubKey("software\microsoft\windows\currentversion\policies\system") subkey.SetValue("disableregistrytools", 1) End Sub Private Sub 取消禁止修改注册表() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser subkey = key.CreateSubKey("software\microsoft\windows\currentversion\policies\system") subkey.SetValue("disableregistrytools", 0) End Sub Private Sub 禁止使用任务管理器() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser subkey = key.CreateSubKey("software\microsoft\windows\currentversion\policies\system") subkey.SetValue("DisableTaskMgr", 1) End Sub Private Sub 取消禁止使用任务管理器() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser subkey = key.CreateSubKey("software\microsoft\windows\currentversion\policies\system") subkey.SetValue("DisableTaskMgr", 0) End Sub '将需要保存的信息写入注册表 Private Sub writeReg() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine subkey = key.CreateSubKey("SOFTWARE\AutoShutdown") subkey.SetValue("time", shutTime) subkey.SetValue("day", CStr(Today())) subkey.SetValue("delayTime", CStr(delay)) subkey.SetValue("autoHide", autoHide) End Sub '点击删除按钮 Private Sub delButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delButton.Click Dim delIndex As Integer = ListBox1.SelectedIndex If delIndex -1 Then ListBox1.Items.RemoveAt(delIndex) End If End Sub '最小化窗体,这里指隐藏窗体 Private Sub 最小化ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 最小化ToolStripMenuItem.Click If Me.Visible = True Then StrToItems() delayTime.Value = delay Me.Hide() End If End Sub Private Sub 创建开机自动运行() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine subkey = key.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run") subkey.SetValue("定时自动关机", Application.ExecutablePath) End Sub Private Sub 删除开机自动运行() Dim key As Microsoft.Win32.RegistryKey, subkey As Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine subkey = key.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) subkey.DeleteValue("定时自动关机") End Sub '关闭显示器 Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Public Const WM_SYSCOMMAND = &H112 Public Const SC_MONITORPOWER = &HF170 '关闭显示器 Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 'Timer1的Tick事件,来监视现在的时间是否应该关机或别的了 Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Static nowTime As Date = Now updataMsg() If SysTime Then If (Now nowTime) Then Today = nowTime TimeOfDay = nowTime End If End If nowTime = nowTime.AddSeconds(1) If (shutTime "") Then Dim temp1() As String = shutTime.Split(";") 'temp1字符串数组存放shutTime以";"分隔的各个字符子串 Dim temp2() As String, i As Integer 'temp2字符串数组存放temp1某项的字符串以","或":"分隔的字符子串 Dim TimeOut As Boolean = False 'TimeOut存放是否时间到了 For i = 0 To temp1.Length - 1 temp2 = temp1(i).Split(New Char() {",", ":"}) If IsTimeOut(temp2) Then '判断时间是否到了 TimeOut = True action = temp2(4) '是"关机","注销","重启" End If Next If TimeOut Then '如果时间到 Select Case Mid(action, 1, 4) '根据action肯定命令字符串 Case "关闭计算" shellText = "shutdown -s -f -t 0" Case "重启计算" shellText = "shutdown -r -f -t 0" Case "注销用户" shellText = "shutdown -l -f -t 0" Case "关闭显示" SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 1) Exit Sub Case "锁定计算" shellText = "rundll32.exe user32.dll, LockWorkStation" Case "打开文件" System.Diagnostics.Process.Start(Mid(action, 6, action.Length - 6).Replace(":", ":")) Exit Sub Case "提醒信息" MsgBox(Mid(action, 6, action.Length - 6), , "提醒信息") Exit Sub Case "打开网址" System.Diagnostics.Process.Start(Mid(action, 6, action.Length - 6).Replace(":", ":")) Exit Sub End Select lastTime = delay '倒计时等于延时 Timer2.Start() '倒计时开始 取消窗体.Show() '倒计时窗口打开 Timer1.Stop() End If End If End Sub '判断时间是否到了 Private Function IsTimeOut(ByRef t() As String) As Boolean '如果时分秒都相等 If t(1) = CStr(Hour(Now())) And t(2) = CStr(Minute(Now()) And t(3) = Second(Now)) Then Select Case t(0) Case "每天" Return True Case "今天" Return True Case "每周二" If Weekday(Now) = FirstDayOfWeek.Tuesday Then Return True End If Case "每周六" If Weekday(Now) = FirstDayOfWeek.Saturday Then Return True End If Case "每周日" If Weekday(Now) = FirstDayOfWeek.Sunday Then Return True End If Case "每周三" If Weekday(Now) = FirstDayOfWeek.Wednesday Then Return True End If Case "每周四" If Weekday(Now) = FirstDayOfWeek.Thursday Then Return True End If Case "每周五" If Weekday(Now) = FirstDayOfWeek.Friday Then Return True End If Case "每周一" If Weekday(Now) = FirstDayOfWeek.Monday Then Return True End If Case "每周一至周五" If Weekday(Now) > FirstDayOfWeek.Sunday And Weekday(Now) < FirstDayOfWeek.Saturday Then Return True End If Case Else If (t(0) = Today.ToShortDateString) Then Return True End If End Select End If Return False End Function '刷新Msg控件 Private Sub updataMsg() Dim xingqi As String = "" Select Case Weekday(Now) Case 1 xingqi = "星期天" Case 2 xingqi = "星期一" Case 3 xingqi = "星期二" Case 4 xingqi = "星期三" Case 5 xingqi = "星期四" Case 6 xingqi = "星期五" Case 7 xingqi = "星期六" End Select msg.Text = "当前时间" & Now().ToLongDateString & " " & Now().ToLongTimeString & " " & xingqi & " CPU使用" & Format(proTime.NextValue, "#0") & "% 网速" & Format(TotalData.NextValue / 1024, "########0.00") & "KB/S" Me.NotifyIcon1.Text = msg.Text End Sub '倒计时处理事件 Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick If lastTime = 0 Then '如果时间到 Shell(shellText, AppWinStyle.Hide) 取消窗体.Label1.Text = "正在" & action Else 取消窗体.Label1.Text = "离" & action & "还有" & lastTime & "秒" '显示倒计时 lastTime -= 1 End If End Sub Private Sub 设置窗体_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown If autoHide Then Me.Hide() End If End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged Select Case ComboBox2.SelectedItem Case "打开网址" Button1.Visible = False TextBox1.Width = 299 TextBox1.Visible = True Case "提醒信息" Button1.Visible = False TextBox1.Width = 299 TextBox1.Visible = True Case "打开文件" Button1.Visible = True TextBox1.Width = 209 TextBox1.Visible = True Case Else Button1.Visible = False TextBox1.Visible = False End Select End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.SelectedItem = "指定日期" Then DateTimePicker1.Visible = True Else DateTimePicker1.Visible = False End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then TextBox1.Text = OpenFileDialog1.FileName End If End Sub Private Sub 立即关机ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即关机ToolStripMenuItem.Click Shell("shutdown -s -f -t 0") End Sub Private Sub 立即重启ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即重启ToolStripMenuItem.Click Shell("shutdown -r -f -t 0") End Sub Private Sub 立即注销ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即注销ToolStripMenuItem.Click Shell("shutdown -l -f -t 0") End Sub Private Sub 立即锁定计算机ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即锁定计算机ToolStripMenuItem.Click Shell("rundll32.exe user32.dll, LockWorkStation") End Sub Private Sub 立即关闭显示器ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 立即关闭显示器ToolStripMenuItem.Click SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 1) End Sub Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked System.Diagnostics.Process.Start("http://lywang.5d6d.com/space-uid-1.html") End Sub End Class
Contents xvii Web Forms 133 Intellisense 134 Customizing the IDE 135 Customizing the Code Editor 135 Customizing Shortcut Keys 135 Customizing the Toolbars 136 Exercise 3.4 Adding a New Toolbar to the Existing Set 136 Exercise 3.5 Adding Commands to Toolbars 137 Customizing Built-In Commands 137 Exercise 3.6 Creating an Alias 138 Customizing the Start Page 139 Accessibility Options 141 Summary 142 Solutions Fast Track 142 Frequently Asked Questions 143 Chapter 4 Common Language Runtime 145 Introduction 146 Component Architecture 148 Managed Code versus Unmanaged Code 150 Interoperability with Managed Code 152 System Namespace 153 File I/O 155 Drawing 156 Printing 157 Common Type System 158 Type Casting 160 Garbage Collection 163 Object Allocation/Deallocation 164 Close/Dispose 165 Summary 166 Solutions Fast Track 167 Frequently Asked Questions 168 Developing & Deploying… Embrace Your Parameters VB.NET is insistent upon enclosing parameters of function calls within parentheses regardless of whether we are returning a value or whether we are using the Call statement. It makes the code much more readable and is a new standard for VB programmers that is consistent with the standard that nearly all other languages adopted long ago. 153_VBnet_TOC 8/16/01 1:12 PM Page xvii xviii Contents Chapter 5 .NET Programming Fundamentals 171 Introduction 172 Variables 173 Constants 175 Structures 176 Program Flow Control 178 If…Then…Else 178 Select Case 182 While Loops 184 For Loops 186 Arrays 187 Declaring an Array 188 Multidimensional Arrays 189 Dynamic Arrays 191 Functions 192 Object Oriented Programming 196 Inheritance 196 Polymorphism 197 Encapsulation 197 Classes 198 Adding Properties 198 Adding Methods 200 System.Object 201 Constructors 201 Overloading 202 Overriding 203 Shared Members 205 String Handling 206 Error Handling 210 Summary 213 Solutions Fast Track 214 Frequently Asked Questions 217 NOTE When porting Visual Basic applications to Visual Basic .NET, be careful of the lower bounds of arrays. If you are using a for loop to iterate through the array, and it is hard-coded to initialize the counter at 1, the first element will be skipped. Remember that all arrays start with the index of 0. 153_VBnet_TOC 8/16/01 1:12 PM Page xviii Contents xix Chapter 6 Advanced Programming Concepts 219 Introduction 220 Using Modules 221 Utilizing Namespaces 222 Creating Namespaces 222 Understanding the Imports Keyword 226 Implementing Interfaces 229 Delegates and Events 232 Simple Delegates 235 Multicast Delegates 236 Event Programming 236 Handles Keyword 236 Language Interoperability 237 File Operations 239 Directory Listing 239 Data Files 241 Text Files 243 Appending to Files 246 Collections 246 The Drawing Namespace 248 Images 253 Printing 256 Understanding Free Threading 262 SyncLock 263 Summary 265 Solutions Fast Track 265 Frequently Asked Questions 267 Chapter 7 Creating Windows Forms 269 Introduction 270 Application Model 270 Properties 271 Manipulating Windows Forms 275 Properties of Windows Forms 275 Methods of Windows Forms 276 Creating Windows Forms 287 What Are Collections? Collectionsare groups of like objects. Collections are similar to arrays, but they don’t have to be redimensioned. You can use the Addmethod to add objects to a collection. Collections take a little more code to create than arrays do, and sometimes accessing a collection can be a bit slower than an array, but they offer significant advantages because a collection is a group of objects whereby an array is a data type. 153_VBnet_TOC 8/16/01 1:12 PM Page xix xx Contents Displaying Modal Forms 288 Displaying Modeless Forms 289 Displaying Top-Most Forms 289 Changing the Borders of a Form 289 Resizing Forms 291 Setting Location of Forms 292 Form Events 294 Creating Multiple Document Interface Applications 297 Creating an MDI Parent Form 297 Creating MDI Child Forms 298 Exercise 7.1 Creating an MDI Child Form 298 Determining the Active MDI Child Form 299 Arranging MDI Child Forms 299 Adding Controls to Forms 300 Anchoring Controls on Forms 301 Docking Controls on Forms 303 Layering Objects on Forms 304 Positioning Controls on Forms 304 Dialog Boxes 305 Displaying Message Boxes 306 Common Dialog Boxes 306 The OpenFileDialog Control 306 The SaveFileDialog Control 309 The FontDialog Control 311 The ColorDialog Control 313 The PrintDialog Control 315 The PrintPreviewDialog Control 316 The PageSetupDialog Control 321 Creating Dialog Boxes 322 Creating and Working with Menus 323 Adding Menus to a Form 323 Exercise 7.2 Adding a Menu to a Form at Design Time 323 Creating Dialog Boxes 1.Create a form. 2.Set the BorderStyle property of the form to FixedDialog. 3.Set the ControlBox, MinimizeBox, and MaximizeBox properties of the form to False. 4.Customize the appearance of the form appropriately. 5.Customize event handlers in the Code window appropriately. 153_VBnet_TOC 8/16/01 1:12 PM Page xx Contents xxi Dynamically Creating Menus 326 Exercise 7.3 Adding a Menu to a Form at Design Time 326 Adding Status Bars to Forms 328 Adding Toolbars to Forms 330 Data Binding 332 Simple Data Binding 332 Complex Data Binding 333 Data Sources for Data Binding 333 Using the Data Form Wizard 334 Using the Windows Forms Class Viewer 338 Using the Windows Forms ActiveX Control Importer 338 Summary 340 Solutions Fast Track 340 Frequently Asked Questions 344 Chapter 8 Windows Forms Components and Controls 347 Introduction 348 Built-In Controls 348 Label Control 351 LinkLabel Control 354 TextBox Control 357 Button Control 361 CheckBox Control 364 RadioButton Control 365 RichTextBox Control 367 TreeView Control 369 ListBox Control 371 CheckedListBox Control 374 ListView Control 376 ComboBox Control 381 DomainUpDown Control 384 NumericUpDown Control 386 PictureBox Control 388 TrackBar Control 389 Adding Items to a Combo Box at Design-Time 1.Select the ComboBox control on the form. 2.If necessary, use the Viewmenu to open the Properties window. 3.In the Properties window, click the Itemsproperty, then click the ellipsis. 4.In String Collection Editor, type the first item, then press Enter. 5.Type the next items, pressing Enterafter each item. 6.Click OK. 153_VBnet_TOC 8/16/01 1:13 PM Page xxi xxii Contents DateTimePicker Control 391 Panel Control 394 GroupBox Control 396 TabControl Control 397 Creating Custom Windows Components 399 Exercise 8.1:Creating a Custom Windows Component 399 Creating Custom Windows Controls 403 Exercise 8.2:Creating a Custom Windows Control 404 Summary 407 Solutions Fast Track 407 Frequently Asked Questions 408 Chapter 9 Using ADO.NET 409 Introduction 410 Overview of XML 411 XML Documents 411 XSL 411 XDR 412 XPath 412 Understanding ADO.NET Architecture 412 Differences between ADO and ADO.NET 414 XML Support 414 ADO.NET Configuration 415 Remoting in ADO.NET 415 Maintaining State 415 Using the XML Schema Definition Tool 416 Connected Layer 417 DataProviders 418 Connection Strings 418 Exercise 9.1 Creating a Connection String 419 Command Objects 421 DataReader 425 DataSet 426 XML Documents XML documents are the heart of the XML standard. An XML document has at least one element that is delimited with one start tag and one end tag. XML documents are similar to HTML, except that the tags are made up by the author. 153_VBnet_TOC 8/16/01 1:13 PM Page xxii Contents xxiii Disconnected Layer 427 Using DataSet 428 Relational Schema 428 Collection of Tables 430 Data States 431 Populating with the DataSet Command 432 Populating with XML 433 Populating Programmatically 434 Using the SQL Server Data Provider 435 TDS 436 Exercise 9.2 Using TypedDataSet 437 Remoting 439 Data Controls 440 DataGrid 440 Exercise 9.3 Using TypedDataSet and DataRelation 441 DataList 446 Repeater 450 Summary 454 Solutions Fast Track 454 Frequently Asked Questions 457 Chapter 10 Developing Web Applications 459 Introduction 460 Web Forms 461 A Simple Web Form 462 Exercise 10.1 Creating a Simple Web Form 462 How Web Forms Differ from Windows Forms 464 Why Web Forms Are Better Than Classic ASP 465 Adding Controls to Web Forms 467 Exercise 10.2 Adding Web Controls to a Web Form 468 Code Behind 473 NOTE Web form controls not only detect browsers such as Internet Explorer and Netscape, but they also detect devices such as Palm Pilots and cell phones and generate appropriate HTML accordingly. 153_VBnet_TOC 8/16/01 1:13 PM Page xxiii xxiv Contents How Web Form Controls Differ from Windows Form Controls 476 ASP.NET Server Controls 476 Intrinsic Controls 476 Bound Controls 478 Exercise 10.3 Using the DataGrid Control 478 Exercise 10.4 Customizing DataGrid Control 482 Custom Controls 487 Validation Controls 488 Exercise 10.5 Using the Validation Controls 489 Creating Custom Web Form Controls 492 Exercise 10.6 A Simple Custom Control 493 Exercise 10.7 Creating a Composite Custom Control 497 Web Services 504 How Web Services Work 505 Developing Web Services 505 Exercise 10.8 Developing Web Services 507 Web Service Utilities 509 Service Description Language 509 Discovery 510 Proxy Class 510 Consuming Web Services from Web Forms 511 Exercise 10.9 Consuming Web Services from Web Forms 511 Using Windows Forms in Distributed Applications 513 Exercise 10.10 Consuming Web Services from Windows Forms 514 Exercise 10.11 Developing a Sample Application 516 Summary 519 Solutions Fast Track 519 Frequently Asked Questions 521 153_VBnet_TOC 8/16/01 1:13 PM Page xxiv Contents xxv Chapter 11 Optimizing, Debugging, and Testing 523 Introduction 524 Debugging Concepts 524 Debug Menu 528 Watches 529 Breakpoints 531 Exceptions Window 532 Command Window 534 Conditional Compilation 536 Trace 538 Assertions 540 Code Optimization 541 Finalization 542 Transitions 542 Parameter Passing Methods 542 Strings 543 Garbage Collection 544 Compiler Options 544 Optimization Options 544 Output File Options 544 .NET Assembly Options 545 Preprocessor Options 546 Miscellaneous Options 546 Testing Phases and Strategies 546 Unit Testing 547 Integration Testing 547 Beta Testing 547 Regression Testing 548 Stress Testing 548 Monitoring Performance 548 Summary 550 Solutions Fast Track 551 Frequently Asked Questions 552 What Are Watches? Watchesprovide us with a mechanism where we can interact with the actual data that is stored in our programs at runtime. They allow us to see the values of variables and the values of properties on objects. In addition to being able to view these values, you can also assign new values. 153_VBnet_TOC 8/16/01 1:13 PM Page xxv xxvi Contents Chapter 12 Security 553 Introduction 554 Security Concepts 555 Permissions 555 Principal 556 Authentication 557 Authorization 557 Security Policy 558 Type Safety 558 Code Access Security 558 .NET Code Access Security Model 559 Stack Walking 559 Code Identity 561 Code Groups 562 Declarative and Imperative Security 564 Requesting Permissions 565 Demanding Permissions 570 Overriding Security Checks 572 Custom Permissions 576 Role-Based Security 578 Principals 578 WindowsPrincipal 579 GenericPrincipal 580 Manipulating Identity 581 Role-Based Security Checks 583 Security Policies 585 Creating a New Permission Set 588 Modifying the Code Group Structure 593 Remoting Security 600 Cryptography 600 Security Tools 603 Summary 606 Solutions Fast Track 607 Frequently Asked Questions 611 Within the .NET Framework, Three Namespaces Involve Cryptography 1.System.Security .CryptographyThe most important one; resembles the CryptoAPI functionalities. 2.System.Security .Cryptography.X509 certificatesRelates only to the X509 v3 certificate used with Authenticode. 3.System.Security .Cryptography.XmlFor exclusive use within the .NET Framework security system. 153_VBnet_TOC 8/16/01 1:13 PM Page xxvi Contents xxvii Chapter 13 Application Deployment 615 Introduction 616 Packaging Code 617 Configuring the .NET Framework 622 Creating Configuration Files 622 Machine/Administrator Configuration Files 623 Application Configuration Files 625 Security Configuration Files 626 Deploying the Application 629 Common Language Runtime 629 Windows Installer 630 CAB Files 631 Internet Explorer 5.5 632 Resource Files 633 Deploying Controls 637 Summary 639 Solutions Fast Track 640 Frequently Asked Questions 642 Chapter 14 Upgrading Visual Basic Applications to .NET 647 Introduction 648 Considerations Before Upgrading 648 Early Binding of Variables 649 Avoiding Null Propagation 650 Using ADO 651 Using Date Data Type 652 Using Constants 652 Considering Architecture Before Migration 653 Intranet/Internet Applications 653 Internet Information Server (IIS) Applications 654 DHTML Applications 655 ActiveX Documents 655 Client/Server and Multi-Tier Applications 655 Single-Tier Applications 656 Data Access Applications 656 WARNING You should under no circumstance edit the Security.config and Enterprise.config files directly. It is very easy to compromise the integrity of these files. Always use the Code Access Security Policy utility (caspol.exe) or the .NET Configuration tool; these will guard the integrity of the files and will also make a backup copy of the last saved version. 153_VBnet_TOC 8/16/01 1:13 PM Page xxvii xxviii Contents Data Types 657 Variants 657 Integers 658 Dates 658 Boolean 659 Arrays 659 Fixed-Length Strings 660 Windows API Data Types 661 Converting VB Forms to Windows Forms 662 Control Anchoring 664 Keyword Changes 665 Goto 666 GoSub 666 Option Base 666 AND/OR 666 Lset 666 VarPtr 667 StrPtr 667 Def 667 Programming Differences 668 Method Implementation 668 Optional Parameters 668 Static Modifier 669 Return Statement 669 Procedure Calls 670 External Procedure Declaration 671 Passing Parameters 672 ParamArray 672 Overloading 674 References to Unmanaged Libraries 677 Metadata 679 Runtime Callable Wrapper 681 COM Callable Wrapper 682 Properties 684 Working with Property Procedures 684 Control Property Name Changes 685 Default Property 687 Avoiding Null Propagation Nullpropagation means that if Null is used in an expression, the resulting expression is always Null. In previous versions of Visual Basic, the Null value disseminated throughout the expression. 153_VBnet_TOC 8/16/01 1:13 PM Page xxviii Contents xxix Null Usage 690 Understanding Error Handling 690 Exercise 14.1:Using Error Handling 692 Data Access Changes in Visual Basic .NET 693 Dataset and Recordset 694 Application Interoperability 694 Cursor Location 695 Disconnected Access 695 Data Navigation 695 Lock Implementation 696 Upgrading Interfaces 696 Upgrading Interfaces from Visual Basic 6.0 699 Using the Upgrade Tool 703 Exercise 14.2 Using the Upgrade Wizard 703 Summary 708 Solutions Fast Track 709 Frequently Asked Questions 712 Index 713 Contents xiii From the Series Editor xxxi Chapter 1 New Features in Visual Basic .NET 1 Introduction 2 Examining the New IDE 3 Cosmetic Improvements 3 Development Accelerators 5 .NET Framework 6 A Very Brief and Simplified History 6 .NET Architecture 7 ASP.NET 7 Framework Classes 8 .NET Servers 8 Common Language Runtime 8 History 8 Convergence 9 Object-Oriented Language 10 Object-Oriented Concepts 10 Advantages of Object-Oriented Design 11 History of Object Orientation and VB 13 Namespaces 13 Web Applications 13 Web Applications Overview 13 Web Forms 14 Web Services 15 HyperText Transport Protocol 16 Simple Object Access Protocol 17 .NET Architecture .NET Framework ASP.NET Updated ASP Engine Web Forms Engine Framework Classes System.Math, System.Io, System.Data, Etc. Common Language Runtime Memory Management Common Type System Garbage Collection .NET .NET Servers 153_VBnet_TOC 8/16/01 1:12 PM Page xiii xiv Contents Security 17 Type Safety 18 Casting 18 Data Conversion 19 Bitwise Operations 20 New Compiler 20 Compiling an Executable 20 Architecture 21 File Management in Previous Versions of VB 21 File Management 22 Changes from Visual Basic 6.0 23 Variants 23 Variable Lower Bounds 23 Fixed Length Strings 23 NULL Propagation 23 Other Items Removed 24 Function Values 24 Short Circuits 25 Properties and Variables 25 Variable Lengths 25 Get and Set 26 Date Type 26 Default Properties 27 Summary 28 Solutions Fast Track 28 Frequently Asked Questions 31 Chapter 2 The Microsoft .NET Framework 33 Introduction 34 What Is the .NET Framework? 34 Introduction to the Common Language Runtime 35 Using .NET-Compliant Programming Languages 37 Creating Assemblies 39 Using the Manifest 42 Compiling Assemblies 45 Assembly Cache 45 Locating an Assembly 45 153_VBnet_TOC 8/16/01 1:12 PM Page xiv Contents xv Private Assembly Files 51 Shared Assembly Files 51 Understanding Metadata 51 The Benefits of Metadata 52 Identifying an Assembly with Metadata 53 Types 53 Defining Members 54 Using Contracts 54 Assembly Dependencies 55 Unmanaged Assembly Code 55 Reflection 56 Attributes 57 Ending DLL Hell 58 Side-by-Side Deployment 58 Versioning Support 59 Using System Services 60 Exception Handling 60 StackTrace 61 InnerException 61 Message 61 HelpLink 62 Garbage Collection 62 Console I/O 62 Microsoft Intermediate Language 63 The Just-In-Time Compiler 63 Using the Namespace System to Organize Classes 64 The Common Type System 65 Type Safety 68 Relying on Automatic Resource Management 68 The Managed Heap 69 Garbage Collection and the Managed Heap 71 Assigning Generations 77 Utilizing Weak References 77 Security Services 79 Framework Security 80 Granting Permissions 81 NOTE Visualization is still key! Die-hard VB programmers may find themselves having a hard time visualizing all the new concepts in VB.NET (and we all know that proper logic visualization plays a big role in what we do). Something that may help is to think about VB.NET as a completely flexible language that can accommodate Web, console, and desktop use. 153_VBnet_TOC 8/16/01 1:12 PM Page xv xvi Contents Gaining Representation through a Principal 82 Security Policy 83 Summary 85 Solutions Fast Track 85 Frequently Asked Questions 88 Chapter 3 Installing and Configuring VB.NET 91 Introduction 92 Editions 92 Installing Visual Studio .NET 93 Exercise 3.1:Installing Visual Studio .NET 94 Installing on Windows 2000 99 The New IDE 100 Integrated Development Environment Automation Model 100 Add-Ins 104 Exercise 3.2 Creating an Add-In Using the Add-In Wizard 105 Wizards 109 Macros 109 Home Page 110 Project Options 112 Toolbox 116 Child Windows 120 Window Types 122 Arranging Windows 123 Task List 123 Exercise 3.3 Setting Up a Custom Token 124 TaskList Views 124 Locating Code 126 Annotating Code 126 Solution Explorer 127 Properties Window 129 Form Layout Toolbar 130 Hide/Show Code Elements 132 Installing Visual Studio .NET IPhase 1: Installing Windows components IPhase 2: Installing Visual Studio .NET IPhase 3: Checking for service releases 153_VBnet_TOC 8/16/01 1:12 PM Page xvi
《C#全能速查宝典》共分为8章,分别介绍了C#语言基础、Windows窗体及常用控件、Windows高级控件、控件公共属性、方法及事件、数据库开发、文件、数据流与注册表、GDI+绘图技术和C#高级编程,共包含562个C#编程中常用的属性、方法、类和各种技术,每一个知识点都配有具体的示例,便于读者理解。 《C#全能速查宝典》所讲的知识点按照功能和字母进行排序,读者既可以按照功能顺序查找,又可以按照字母顺序学习。 《C#全能速查宝典》不仅适合C#程序设计初学者,也可作为中、高级程序开发人员的参考手册。 ============================================================ 图书目录 第1章 C#语言基础 1 1.1 常用概念、关键字及基础类 1 1.1.1 abstract关键字——抽象 1 1.1.2 as操作符——引用类型转换 3 1.1.3 base关键字——从派生类中访问基类的成员 3 1.1.4 变量——存储特定类型的数据 4 1.1.5 Console类——控制台中的输入流、输出流和错误流 6 1.1.6 Convert类——类型转换 8 1.1.7 常量——值不改变的量 9 1.1.8 Dispose方法——释放资源 10 1.1.9 迭代器——相同类型的值的有序序列的一段代码 10 1.1.10 泛型——处理算法和数据结构 11 1.1.11 分部类——将一个类分成几部分 12 1.1.12 is操作符——检查变量是否为指定的类型 14 1.1.13 lock关键字——锁定 15 1.1.14 namespace关键字——定义命名空间 15 1.1.15 new运算符——创建一个新的类型实例 16 1.1.16 Object类型——所有类型的基类 17 1.1.17 OOP技术——面向对象编程技术 18 1.1.18 ReadLine方法——从当前流中读取一行字符 20 1.1.19 typeof运算符——获得系统原型对象的类型 21 1.1.20 using关键字——引入命名空间 22 1.1.21 WriteLine方法——写入流 23 1.2 数学方法类——Math 25 1.2.1 Abs方法——返回指定数字的绝对值 25 1.2.2 Acos方法——返回余弦值为指定数字的角度 26 1.2.3 Asin方法——返回正弦值为指定数字的角度 26 1.2.4 Atan方法——返回正切值为指定数字的角度 27 1.2.5 Pow方法——返回指定数字的指定次幂 27 1.2.6 Round方法——将小数值舍入到指定的精度 28 1.3 流程控制语句 29 1.3.1 break语句——跳出循环 29 1.3.2 case语句——比较表达式以确定结果 30 1.3.3 continue语句——继续执行下一个循环 31 1.3.4 do…while语句——循环语句 31 1.3.5 for语句——循环语句 32 1.3.6 foreach语句——枚举一个集合的元素 33 1.3.7 goto语句——跳转到标签 34 1.3.8 if…else语句——条件判断语句 36 1.3.9 return语句——返回 38 1.3.10 switch case语句——条件判断语句 39 1.3.11 throw语句——显式引发异常 40 1.3.12 try…catch…finally语句——捕捉异常 42 1.3.13 while语句——循环语句 43 1.4 字符串处理 44 1.4.1 AddDays方法——添加天数 44 1.4.2 AddString方法——添加文本字符串 45 1.4.3 Compare方法——比较两个字符串 46 1.4.4 CompareTo方法——比较两个字符串对象 47 1.4.5 DATEADD函数——在指定日期上加一段时间 48 1.4.6 DateDiff方法——获取日期时间的间隔数 48 1.4.7 DateTime结构——表示时间上的一刻 50 1.4.8 DAY函数——返回日期部分的整数 51 1.4.9 DayOfWeek属性——获取星期几 52 1.4.10 Equals方法——比较两个字符串对象 53 1.4.11 First函数——返回查询结果的第一个记录 55 1.4.12 FirstDayOfWeek属性——获取或设置一周中的第一天 56 1.4.13 Format方法——格式化字符串 56 1.4.14 GETDATE函数——返回当前系统日期和时间 58 1.4.15 GetDayOfMonth方法——返回几号 59 1.4.16 GetDayOfWeek方法——返回星期几 59 1.4.17 GetDayOfYear方法——返回第几天 60 1.4.18 GetDaysInMonth方法——返回指定月份中的天数 60 1.4.19 GetDaysInYear方法——返回指定年份中的天数 61 1.4.20 GetMonth方法——返回指定日期中的月份 61 1.4.21 GetMonthsInYear方法——返回指定年份的月数 62 1.4.22 GetText方法——检索文本数据 63 1.4.23 GetYear方法——返回指定日期中的年份 64 1.4.24 IndexOf方法——确定指定字符在字符串中的索引 65 1.4.25 IsLeapYear方法——判断年份是否为闰年 67 1.4.26 IsMatch方法——搜索正则表达式匹配项 67 1.4.27 IsUpper方法——判断是否大写 68 1.4.28 Join方法——串联字符串 69 1.4.29 LastIndexOf方法——确定字符在字符串中最后索引 70 1.4.30 Matches方法——检查字符串是否有重复的词出现 71 1.4.31 MONTH函数——返回指定日期中月部分的整数 73 1.4.32 PadLeft方法——在左边用空格填充 73 1.4.33 PadRight方法——在右边用空格填充 74 1.4.34 Random类——伪随机数生成器 75 1.4.35 Regex类——正则表达式 76 1.4.36 Split方法——分割字符串 78 1.4.37 String类——字符串 79 1.4.38 StringBuilder类——可变字符串 82 1.4.39 Substring方法——截取字符串 83 1.4.40 TimeSpan对象——表示时间间隔或持续时间 84 1.4.41 ToInt32方法——转换为32位有符号整数 85 1.4.42 ToLongDateString 方法——转换为长日期字符串 86 1.4.43 ToLongTimeString 方法——转换为长时间字符串 87 1.4.44 ToLower方法——转换为小写 87 1.4.45 ToShortDateString方法——转换为短日期字符串 88 1.4.46 ToShortTimeString方法——转换为短时间字符串 88 1.4.47 ToString方法——转换为字符串 89 1.4.48 ToUpper方法——转换为大写 90 1.4.49 Trim方法——移除所有空白字符 91 1.4.50 TrimEnd方法——从尾部移除匹配项 92 1.4.51 TrimStart方法——从开始移除匹配项 92 1.4.52 YEAR函数——返回指定日期的年份的整数 93 1.5 数组与集合 93 1.5.1 Add方法——添加项 93 1.5.2 ArrayList类——集合 95 1.5.3 AsEnumerable方法——转换为IEnumerable类型 97 1.5.4 Clear方法——清空内容 98 1.5.5 Contains方法——确定是否包含某项 99 1.5.6 ContainsKey方法——确定哈希表是否包含特定键 100 1.5.7 ContainsText方法——确定剪贴板中是否存在数据 101 1.5.8 ContainsValue方法——确定哈希表是否包含特定值 101 1.5.9 Count属性——获取数目 102 1.5.10 GetEnumerator方法——循环访问对象 103 1.5.11 GetEnvironmentVariables方法——检索环境变量 104 1.5.12 Hashtable类——哈希表 106 1.5.13 Insert方法——插入项 110 1.5.14 Item属性——获取或设置指定索引处的元素 111 1.5.15 Length属性——获取长度 112 1.5.16 Next方法——返回一个指定范围内的随机数 113 1.5.17 Queue类——队列 115 1.5.18 Remove方法——移除指定项 116 1.5.19 RemoveAt方法——移除指定索引处的项 118 1.5.20 Replace方法——替换文件或字符串 119 1.5.21 Reverse方法——反转数组元素 120 1.5.22 Sort方法——数组排序 121 1.5.23 Stack类——堆栈 123 第2章 Windows窗体及常用控件 126 2.1 Form窗体 126 2.1.1 AcceptButton属性——设置接受按钮 126 2.1.2 Activate事件——当激活窗体时发生 126 2.1.3 Appllication类——提供管理应用程序的静态方法 126 2.1.4 CancelButton属性——设置取消按钮 128 2.1.5 Computer类——提供操作计算机组件的属性 129 2.1.6 ComputerInfo类——获取计算机信息 130 2.1.7 Control类——定义控件基类 131 2.1.8 Environment类——提供当前环境和平台的信息 134 2.1.9 Form窗体——可视化界面 136 2.1.10 FormClosed事件——关闭窗体后事件 139 2.1.11 FormClosing事件——关闭窗体前事件 139 2.1.12 Icon属性——设置图标 139 2.1.13 IsMdiContainer属性——设置父窗体 140 2.1.14 LayoutMdi方法——排列子窗体 141 2.1.15 Load事件——窗体加载事件 141 2.1.16 MaximizeBox属性——是否显示最大化按钮 142 2.1.17 Maximum属性——设置数字显示框的最大值 142 2.1.18 MDI窗体——多文档界面 143 2.1.19 MdiChildren属性——获取子窗体的数组 146 2.1.20 MdiParent属性——设置父窗体 147 2.1.21 MinimizeBox属性——是否显示最小化按钮 147 2.1.22 Minimum属性——数字显示框的最小值 148 2.1.23 Opacity属性——设置窗体的透明度级别 148 2.1.24 Owner属性——设置窗体所有者 149 2.1.25 StartPosition属性——设置窗体起始位置 150 2.1.26 StartupPath 属性——获取可执行文件路径 150 2.1.27 TopMost属性——窗体是否应显示为最顶层窗体 151 2.1.28 WindowState属性——窗体的窗口状态 151 2.2 文本类控件 152 2.2.1 AllowEdit属性——是否可以编辑列表项 152 2.2.2 AppendText方法——追加文本 152 2.2.3 BeginEdit方法——将单元格置于编辑模式下 153 2.2.4 Button控件——按钮控件 153 2.2.5 CancelEdit属性——取消更改 155 2.2.6 CanPaste方法——是否可以粘贴数据 155 2.2.7 CanRedo属性——是否有可以重新应用的操作 156 2.2.8 CanSelect属性——是否可以选中控件 157 2.2.9 CanUndo属性——能否撤销上一个操作 157 2.2.10 Cut方法——将选定内容移动到“剪贴板”中 158 2.2.11 Find方法——搜索指定的项目 158 2.2.12 FindString方法——搜索文本 160 2.2.13 Label控件——标签控件 161 2.2.14 LabelEdit属性——允许用户编辑控件数据 163 2.2.15 LinkLabel控件——以超链接形式显示文本 164 2.2.16 MaskedTextBox控件——使用掩码区分用户输入 166 2.2.17 Multiline属性——是否为多行输入数据 169 2.2.18 PasswordChar属性——取代用户输入而显示的字符 170 2.2.19 Redo方法——重新应用控件中上次撤销的操作 171 2.2.20 RichTextBox控件——有格式文本控件 171 2.2.21 Select方法——激活控件 173 2.2.22 SelectAll方法——选定所有文本 176 2.2.23 Selected属性——是否选定 176 2.2.24 SelectedCells属性——用户选定的单元格集合 177 2.2.25 SelectedColumns属性——用户选定的列集合 178 2.2.26 SelectedRows属性——用户选定的行集合 179 2.2.27 SelectionBackColor属性——文本在选中时的颜色 180 2.2.28 SelectionColor属性——插入点的文本颜色 180 2.2.29 SelectionEnd属性——设置选定日期范围的结束日期 181 2.2.30 SelectionFont属性——选定文本或插入点的字体 182 2.2.31 SelectionIndent属性——所选内容开始行的缩进距离 183 2.2.32 SelectionLength属性——控件中选定的字符数 184 2.2.33 SelectionRange 属性——设置选定的日期范围 185 2.2.34 SelectionStart属性——选择的起始位置的字符索引 185 2.2.35 TextBox控件——输入或显示文本 186 2.2.36 TextChanged事件——Text属性值更改时发生 187 2.3 选择类控件 188 2.3.1 CheckBox控件——复选框控件 188 2.3.2 CheckBoxes属性——是否显示复选框 190 2.3.3 Checked属性——复选框是否处于选中状态 190 2.3.4 CheckedChanged事件——Checked属性更改时发生 191 2.3.5 CheckedListBox控件——复选框列表控件 191 2.3.6 CheckState属性——设置CheckBox控件的状态 193 2.3.7 ComboBox控件——下拉组合框控件 194 2.3.8 DomainUpDown控件——上下选择控件 195 2.3.9 DropDownStyle属性——指定组合框样式的值 197 2.3.10 GetItemCheckState方法——当前项的复选状态的值 198 2.3.11 GetItemText方法——指定项的文本表示形式 199 2.3.12 Index属性——从零开始的索引 200 2.3.13 Items属性——数组列表对象中的项的集合 200 2.3.14 ListBox控件——列表控件 201 2.3.15 ListView控件——显示带图标的项列表 205 2.3.16 NumericUpDown控件——数值选择控件 208 2.3.17 RadioButton控件——单选按钮 210 2.3.18 SelectedIndex属性——获取选择项的索引 212 2.3.19 SelectedIndices属性——表示当前选中的项 213 2.3.20 SelectedItem属性——当前选中的项 214 2.3.21 SelectedItems属性——选定项的集合 215 2.3.22 SelectedText属性——选定文本 216 2.4 容器类控件 217 2.4.1 FlatStyle属性——设置控件的平面样式外观 217 2.4.2 FlowDirection属性——指示FlowLayoutPanel控件的流向 217 2.4.3 FlowLayoutPanel控件——水平或垂直排列内容 218 2.4.4 GroupBox控件——分组控件 219 2.4.5 Panel控件——容器控件 220 2.4.6 TabControl控件——选项卡控件 222 2.4.7 TabIndex属性——控件的Tab键顺序 224 2.4.8 TabPages属性——选项卡页的集合 224 第3章 Windows高级控件 226 3.1 日期时间类控件 226 3.1.1 CalendarFont属性——日历的字体样式 226 3.1.2 CalendarForeColor属性——日历的前景色 226 3.1.3 DateTimePicker控件——日期和日历的组合 226 3.1.4 MaxDate属性——最大日期和时间 228 3.1.5 MinDate属性——最小日期和时间 228 3.1.6 MonthCalendar控件——以网格形式显示日历 229 3.1.7 SetDate方法——将日期设置为当前选定的日期 231 3.1.8 ShowToday属性——是否显示当前日期 232 3.2 对话框、菜单、工具栏及状态栏控件 232 3.2.1 ColorDialog控件——颜色对话框 232 3.2.2 ContextMenuStrip控件——右键快捷菜单 233 3.2.3 ExpandAll方法——展开所有树节点 233 3.2.4 Filter属性——设置筛选器字符串 234 3.2.5 FolderBrowserDialog控件——浏览文件夹对话框 234 3.2.6 Font属性——设置字体 235 3.2.7 FontDialog控件——字体对话框 235 3.2.8 InitialDirectory属性——文件对话框显示的初始目录 237 3.2.9 MenuStrip控件——菜单控件 238 3.2.10 Nodes属性——树节点集合 241 3.2.11 OpenFileDialog控件——打开文件对话框 241 3.2.12 RestoreDirectory属性——是否还原当前目录 244 3.2.13 RootFolder属性——设置浏览的根文件夹 245 3.2.14 SaveFileDialog组件——保存文件对话框 246 3.2.15 SelectedNode属性——获取选定的树节点 248 3.2.16 SelectedPath属性——用户选定的路径 249 3.2.17 ShowDialog方法——打开模式对话框 249 3.2.18 ToolStrip控件——工具栏控件 251 3.2.19 TreeNode类——树节点 252 3.2.20 TreeView控件——树控件 254 3.3 数据绑定类控件 256 3.3.1 BindingNavigator控件——导航和操作数据 256 3.3.2 Cell对象——表示Word文档中的单元格 258 3.3.3 CellClick事件——单元格的任何部分被单击时发生 259 3.3.4 CellEnter事件——控件接收到输入焦点时发生 260 3.3.5 CellMouseClick事件——鼠标单击单元格时发生 261 3.3.6 CellLeave事件——单元格失去输入焦点时发生 261 3.3.7 Cells属性——Bookmark控件中的表单元格 261 3.3.8 ColumnCount属性——DataGridView控件显示的列数 262 3.3.9 Columns属性——控件中所有列的集合 262 3.3.10 ColumnWidth属性——ListBox中列的宽度 263 3.3.11 CurrentCell属性——设置当前处于活动状态的单元格 263 3.3.12 CurrentRow属性——包含当前单元格的行 263 3.3.13 DataGridView控件——数据控件 264 3.3.14 FullRowSelect属性——是否选择其所有子项 268 3.3.15 GetCellCount方法——获取满足筛选器的单元格数目 269 3.3.16 GetColumn方法——指定子控件的列位置 270 3.3.17 NewRow方法——添加一条新记录 270 3.3.18 RowCount方法——DataGridView中显示的行数 271 3.3.19 Rows属性——DataGridView控件中的所有行 272 3.4 打印类控件 273 3.4.1 CrystalReportViewer控件——水晶报表查看控件 273 3.4.2 Document属性——设置要预览的文档 280 3.4.3 PageSetupDialog组件——配置页面的对话框 281 3.4.4 Print方法——打印当前页面 283 3.4.5 PrintDialog组件——打印对话框 283 3.4.6 PrintDocument组件——设置打印的文档 286 3.4.7 PrinterSettings属性——打印机设置 291 3.4.8 PrintPage事件——当需要为当前页打印的输出时发生 292 3.4.9 PrintPreviewControl组件——按文档打印时的外观显示Print Document组件 292 3.4.10 PrintPreviewDialog组件——显示PrintDocument组件在打印时的外观 295 3.4.11 PrinterSettings类——用来指定有关文档打印方式的信息 297 3.4.12 Zoom属性——指示页面的显示大小 300 3.5 其他常用组件 300 3.5.1 BackgroundWorker组件——在主线程的另一线程上异步执行耗时的操作 300 3.5.2 ErrorProvider控件——检查并显示错误信息 302 3.5.3 EventLog组件——连接本地和远程计算机的事件日志 303 3.5.4 HelpProvider组件——将帮助文件与Windows应用程序相关联 306 3.5.5 HScrollBar控件——一个标准Windows水平滚动条 309 3.5.6 Image属性——显示在控件上的图像 311 3.5.7 ImageAlign属性——在控件中显示的图像的对齐方式 312 3.5.8 ImageFormat类——指定图像的格式 312 3.5.9 ImageList组件——用于存储图像 314 3.5.10 ImageList属性——在控件中显示的图像的ImageList 316 3.5.11 Interval属性——设置Timer控件执行的间隔 317 3.5.12 NotifyIcon控件——设置程序的系统托盘图标 317 3.5.13 PerformStep方法——按照Step属性的数量增加进度栏的当前位置 319 3.5.14 PictrueBox控件——用于显示指定的图像 320 3.5.15 Play方法——播放.wav文件 323 3.5.16 ProgressBar控件——进度条 323 3.5.17 SetError方法——设置错误信息 326 3.5.18 SetShowHelp方法——是否显示帮助信息 327 3.5.19 SetToolTip方法——设置提示文本 328 3.5.20 Step属性——增加进度条的当前位置时所根据的数量 328 3.5.21 Stop方法——停止加载网页 329 3.5.22 Tick事件——计时器处于启用状态时发生 330 3.5.23 Timer组件——定期引发事件的组件 330 3.5.24 ToolTip控件——显示提示信息 332 3.5.25 ToolTipIcon属性——提示文本旁显示的图标类型 333 3.5.26 ToolTipText属性——ToolTip显示的文本 334 3.5.27 ToolTipTitle属性——工具提示窗口的标题 334 3.5.28 TrackBar控件——标准的Windows跟踪条 335 3.5.29 Url属性——引用服务说明的URL 337 3.5.30 VscrollBar控件——标准的Windows垂直滚动条 337 3.5.31 WebBrowser控件——在窗体中显示网页 339 3.5.32 Windows Media Player控件——播放常见的音频文件 343 第4章 控件公共属性、方法及事件 347 4.1 控件公共属性 347 4.1.1 BackColor属性——设置控件的背景色 347 4.1.2 BackgroudColor属性——设置控件背景色 347 4.1.3 BackgroudImage属性——设置控件背景图像 347 4.1.4 Border属性——控件边框 348 4.1.5 BorderStyle属性——控件的边框样式 349 4.1.6 Bottom属性——控件下边缘与其容器的工作区上边缘之间的距离 349 4.1.7 CanFocus属性——控件是否可以接收焦点 350 4.1.8 Capture属性——控件是否已捕获鼠标 350 4.1.9 Color属性——设置用户选定的颜色 350 4.1.10 Dock属性——控件在窗体中的布局样式 351 4.1.11 Enabled属性——控件是否可用 352 4.1.12 ForeColor属性——设置控件的前景色 352 4.1.13 Handle属性——获取控件绑定到的窗口句柄 352 4.1.14 Height属性——设置控件的高度 353 4.1.15 KeyChar属性——设置与按下的键对应的字符 354 4.1.16 KeyValue属性——获取KeyDown或KeyUp事件的键盘值 355 4.1.17 Lines属性——设置多行配置中的文本行 355 4.1.18 Location属性——控件的左上角相对于其容器的左上角的坐标 356 4.1.19 Name属性——控件或实例的名称 356 4.1.20 Parent属性——设置控件的父容器或获取指定子目录的父目录 357 4.1.21 Position属性——设置坐标 358 4.1.22 ReadOnly属性——是否只读 359 4.1.23 Right属性——控件右边缘与其容器的工作区左边缘之间的距离 359 4.1.24 RightToLeft属性——控件的文本从右向左读取 360 4.1.25 ScrollBars属性——滚动条的可见性和位置 360 4.1.26 SizeMode属性——指示如何显示图像 361 4.1.27 Tag属性——窗体或控件的标识 362 4.1.28 Text属性——与控件关联的文本 362 4.1.29 TextAlign 属性——控件上文本的对齐方式 363 4.1.30 Top属性——控件上边缘与其容器的工作区上边缘之间的距离 364 4.1.31 Value属性——辅助性对象的值 364 4.1.32 View属性——项在控件中的显示方式 365 4.1.33 Visible属性——控件是否可见 366 4.1.34 Width属性——控件的宽度 366 4.2 控件公共方法 367 4.2.1 BringToFront方法——将控件带到Z顺序的前面 367 4.2.2 Focus方法——为控件设置输入焦点 367 4.2.3 GetClipboardContent方法——检索选定单元格内容的格式化值 368 4.2.4 GetParent方法——检索指定路径的父目录 368 4.2.5 Hide方法——隐藏窗体 369 4.2.6 Load方法——加载XML文档 369 4.2.7 LoadFile方法——将文件加载到RichTextBox控件中 371 4.2.8 Navigate方法——打开指定的URL地址 372 4.2.9 Refresh方法——重新加载当前的网页 373 4.2.10 SaveAs方法——用新名称或新格式保存文档 373 4.2.11 SaveFile方法——将内容保存到文件中 374 4.2.12 Show方法——显示光标或者打开新窗体 375 4.2.13 UpButton方法——按照指定数值递增 376 4.3 控件公共事件 377 4.3.1 Click事件——单击控件时触发该事件 377 4.3.2 Enter事件——光标进入控件时发生 378 4.3.3 KeyDown事件——控件有焦点按下键时发生 378 4.3.4 KeyPress事件——控件有焦点按下键时发生 380 4.3.5 KeyUp事件——控件有焦点释放键时发生 381 4.3.6 Leave事件——输入焦点离开控件时发生 381 4.3.7 MouseClick事件——用户单击控件时发生 382 4.3.8 Navigated事件——加载新文档时发生 383 4.3.9 Paint事件——重绘或更新控件时发生 383 第5章 数据库开发 385 5.1 SQL语言基础 385 5.1.1 AVG聚合函数——返回组中值的平均值 385 5.1.2 CAST函数——数据类型显式转换 385 5.1.3 COUNT函数——返回组中的项的数量 386 5.1.4 Last函数——返回查询结果的最后一个记录 386 5.1.5 MAX函数——返回表达式中的最大值 388 5.1.6 MIN函数——返回表达式中的最小值 388 5.1.7 newid函数——创建uniqueidentifier类型的惟一值 389 5.1.8 SUM函数——返回表达式中所有值的和 389 5.1.9 UPDATE语句——更改表中的现有数据 390 5.2 ADO.NET技术 392 5.2.1 Command对象——对数据源执行增、删、改、查操作 392 5.2.2 CommandText属性——获取设置SQL语句或存储过程 393 5.2.3 CommandTimeout属性——获取或设置错误等待时间 393 5.2.4 CommandType属性——获取或设置如何解释CommandText属性 394 5.2.5 Connection对象——数据库连接对象 394 5.2.6 ConnectionState枚举——数据库连接状态 395 5.2.7 DataAdapter类——数据库桥接器 396 5.2.8 DataMember属性——获取或设置数据源列表或表名称 398 5.2.9 DataReader类——只读数据集 398 5.2.10 DataSet类——数据集 400 5.2.11 DataSource属性——获取或设置数据源 402 5.2.12 ExecuteNonQuery方法——执行SQL语句并返回受影响的行数 402 5.2.13 ExecuteReader方法——执行SQL语句并返回DataReader对象 403 5.2.14 ExecuteScalar方法——执行SQL语句并返回结果集中第1行的第1列 404 5.2.15 Fill方法——填充数据集 405 5.2.16 Merge方法——合并数据集 407 5.2.17 Parameters属性——获取SqlParameterCollection 409 5.2.18 ReadXml方法——将XML架构和数据读入数据集 410 5.2.19 SelectCommand属性——获取或设置选择记录命令 411 5.2.20 SQL注入式攻击——利用设计上的漏洞攻击SQL 412 5.2.21 SqlCommand类——SQL执行命令 413 5.2.22 SqlConnection类——SQL数据库连接对象 415 5.2.23 SqlDataAdapter类——SQL数据库桥接器 416 5.2.24 SqlDataReader类——SQL只读数据集 418 5.2.25 Tables属性——获取包含在数据集中的表的集合 421 5.2.26 Update方法——使控件重绘工作区内的无效区域 422 5.2.27 UpdateCommand属性——获取或设置更新记录命令 423 5.2.28 WriteXml方法——将数据集中数据写入到XML中 423 5.3 LINQ技术 424 5.3.1 Lambda表达式——匿名函数 424 5.3.2 LINQ技术——语言集成查询 426 5.3.3 LinqToDataSet技术——LINQ操作数据集 427 5.3.4 LinqToObjects技术——LINQ操作数组和集合 429 5.3.5 LinqToSql技术——LINQ操作SQL数据库 431 5.3.6 LinqToXml技术——LINQ操作XML文件 436 5.3.7 var关键字——根据初始化语句推断变量类型 439 第6章 文件、数据流与注册表 441 6.1 文件与I/O数据流 441 6.1.1 ASCII码——键盘的一种表示方式 441 6.1.2 ASCIIEncoding类——ASCII字符编码的操作类 442 6.1.3 Attributes属性——获取和设置文件的属性 443 6.1.4 BinaryReader类——将特定的数据读作二进制值 445 6.1.5 BinaryWriter类——将二进制值写入到流中 447 6.1.6 CanRead属性——判断当前流是否支持读写 448 6.1.7 Close方法——释放所有关联的资源 449 6.1.8 Copy方法——文件的复制 450 6.1.9 CopyFile方法——将文件复制到新的位置 451 6.1.10 CopyTo方法——将指定的字符串复制到字符数组中 452 6.1.11 Create方法——创建文件 455 6.1.12 CreateDirectory方法——创建指定路径中的所有目录 456 6.1.13 CreateText方法——创建或打开文本文件 456 6.1.14 CreationTime属性——获取或设置文件的创建时间 457 6.1.15 CryptoStream类——将数据流连接到加密转换的流 457 6.1.16 Delete方法——删除文件 461 6.1.17 Directory类——对文件夹进行操作的类 463 6.1.18 DirectoryEntry类——封装节点或对象 464 6.1.19 DirectoryInfo类——对文件夹进行操作的类 466 6.1.20 DirectoryName属性——获取路径 468 6.1.21 DirectorySearcher组件——执行查找 468 6.1.22 DriveInfo类——驱动器的信息访问 469 6.1.23 Encoding属性——获取编码方式 470 6.1.24 Exists方法——判断文件是否存在 471 6.1.25 Exists属性——判断文件是否存在 472 6.1.26 Extension属性——获取文件扩展名 473 6.1.27 File类——对文件进行操作的类 473 6.1.28 FileAttributes枚举——提供文件和目录的属性 475 6.1.29 FileInfo类——文件的操作类 476 6.1.30 FileName属性——获取或设置文件的名称 478 6.1.31 FileStream类——对文件流操作的类 478 6.1.32 Flush方法——清除流的缓冲区 480 6.1.33 GetBytes方法——将字符串编码设为字节序列 481 6.1.34 GetDirectories方法——获取子目录的名称 482 6.1.35 GetExtension方法——获取路径字符串的扩展名 485 6.1.36 GetFiles方法——获取目录中的文件名称 486 6.1.37 GetFileSystemEntries方法——获取目录中的所有名称 487 6.1.38 GetFileSystemInfos方法——获取所有文件的信息 489 6.1.39 GetStream方法——返回用于发送和接收的数据 491 6.1.40 GetString方法——将字节解码成字符串 491 6.1.41 HasRows属性——指示 OleDbDataReader是否有数据 493 6.1.42 MD5CryptoServiceProvider类——操作MD5的类 493 6.1.43 MemoryStream类——创建其支持存储区为内存的流 495 6.1.44 Move方法——文件的移动 497 6.1.45 MoveNext方法——移动到下一个字符 497 6.1.46 MoveTo方法——文件的移动 498 6.1.47 NetworkStream类——网络访问的基础数据流 500 6.1.48 Open方法——打开文件 502 6.1.49 OpenFile方法——以只读方式打开文件 503 6.1.50 OpenText方法——打开UTF-8编码文本文件 504 6.1.51 Path属性——监视的目录的路径 505 6.1.52 Peek方法——返回下一个可用的字符 506 6.1.53 Read方法——读取数据流 507 6.1.54 ReadBytes方法——将指定的字节读入字节数组 508 6.1.55 ReadToEnd方法——从流的当前位置读到末尾 509 6.1.56 Stream类——对数据流进行操作的类 510 6.1.57 StreamReader类——数据流的读取类 512 6.1.58 StreamWriter类——数据流的写入类 513 6.1.59 TextReader类——读取连续字符的读取器 515 6.1.60 TextWriter类——编写一个有序字符系列的编写器 516 6.1.61 Write方法——将流写入到文件中 517 6.2 注册表技术 521 6.2.1 CreateSubKey方法——创建或打开子项 521 6.2.2 GetValue方法——获取注册表项中的值 522 6.2.3 GetValueNames方法——所有值名称的字符串数组 523 6.2.4 GetSubKeyNames方法——所有子项名称字符串数组 525 6.2.5 OpenSubKey方法——以只读方式检索子项 525 6.2.6 Registry类——注册表操作类 528 6.2.7 RegistryKey类——表示Windows注册表中的项级节点 529 6.2.8 SetValue方法——设置注册表项的指定名称/值对 531 第7章 GDI+绘图技术 532 7.1 GDI+绘图基础 532 7.1.1 Bitmap类——图像对象 532 7.1.2 Cursor类——绘制光标指针图像 533 7.1.3 GDI+——图形图像的绘制 535 7.1.4 Graphics类——绘图类 536 7.1.5 GraphicsPath类——一系列相互连接的直线和曲线 540 7.1.6 Icon类——图标的操作类 542 7.1.7 Image类——图像的操作类 543 7.1.8 LinearGradientBrush类——线性渐变封装Brush 545 7.1.9 Region类——由矩形和路径构成的图形形状的内部 547 7.1.10 SolidBrush类——定义单色画笔 548 7.2 常用绘图方法 549 7.2.1 Draw方法——绘制光标 549 7.2.2 DrawArc方法——绘制圆弧 550 7.2.3 DrawBezier方法——绘制贝塞尔样条 551 7.2.4 DrawEllipse方法——绘制椭圆 553 7.2.5 DrawImage方法——绘制Image图像 555 7.2.6 DrawLine方法——绘制直线 556 7.2.7 DrawPath方法——绘制GraphicsPath图形路径 558 7.2.8 DrawPie方法——绘制扇形 558 7.2.9 DrawPolygon方法——绘制多边形 560 7.2.10 DrawRectangle方法——绘制矩形 561 7.2.11 DrawString方法——绘制文本字符串 562 7.3 常用填充图像方法 565 7.3.1 FillEllipse方法——填充椭圆 565 7.3.2 FillPath方法——填充GraphicsPath的内部 566 7.3.3 FillPie方法——填充扇形 567 7.3.4 FillPolygon方法——填充多边形 568 7.3.5 FillRectangle方法——填充矩形框 570 7.3.6 FillRegion方法——填充一个区域 572 7.4 其他常用方法 572 7.4.1 Clone方法——创建Bitmap对象的某个部分的副本 572 7.4.2 CreateGraphics方法——创建Graphics对象 574 7.4.3 FromArgb方法——从ARGB值创建Color结构 574 7.4.4 FromFile方法——从指定的文件创建Image 577 7.4.5 FromImage方法——从Image创建新的Graphics对象 578 7.4.6 FromStream方法——数据流创建Image 578 7.4.7 GetPixel方法——获取图像中的像素颜色 580 7.4.8 GetThumbnailImage方法——Image的缩略图 581 7.4.9 Save方法——将图片以文件的形式进行复制 583 7.4.10 SetPixel方法——设置图像中的像素颜色 583 7.4.11 Transform方法——对路径的数据点进行变换 584 第8章 C#高级编程 586 8.1 网络编程技术 586 8.1.1 Accept方法——为新建连接创建新的Socket对象 586 8.1.2 AcceptSocket方法——接收挂起的连接请求 586 8.1.3 BeginConnect方法——开始远程主机连接的异步请求 587 8.1.4 Dns类——从Internet域名系统检索特定主机的信息 588 8.1.5 GetHostAddresses方法——返回主机的IP地址 589 8.1.6 GetHostByAddress方法——创建IPHostEntry实例 590 8.1.7 GetHostByName方法——获取指定DNS主机名的信息 591 8.1.8 GetHostName方法——获取本地计算机的主机名 592 8.1.9 IPEndPoint类——将网络端点表示为IP地址和端口号 592 8.1.10 IPHostEntry类——为主机地址信息提供容器类 594 8.1.11 Listen方法——将Socket置于侦听状态 596 8.1.12 MachineName属性——读取或写入事件的计算机名称 596 8.1.13 MailMessage类——邮件的操作类 597 8.1.14 Net send命令——用net send命令进行发送 598 8.1.15 Net use命令——实现映射网络驱动器 599 8.1.16 Ping类——网络访问远程计算机的操作类 601 8.1.17 POP3协议——POP邮件的操作类 603 8.1.18 Receive方法——由远程主机发送的UDP数据报 608 8.1.19 Send方法——将数据发送到连接的Socket 609 8.1.20 SerialPort类——控制串行端口文件资源 610 8.1.21 SMTP协议——进行邮件的传输 612 8.1.22 SmtpClient类——将电子邮件发送到SMTP服务器 614 8.1.23 Socket类——网络通信的操作类 616 8.1.24 TcpClient类——为TCP网络服务提供客户端连接 618 8.1.25 TcpListener类——从TCP网络客户端侦听连接 619 8.1.26 UdpClient类——用户数据报(UDP)网络服务 620 8.1.27 WebClient类——URI标识的资源发送和接收 623 8.1.28 WebRequest类——访问Internet数据 625 8.1.29 WebResponse类——协议特定的响应类 629 8.2 多线程编程 630 8.2.1 Abort方法——终止线程 630 8.2.2 BeginInvoke方法——线程上异步执行委托 631 8.2.3 EndInvoke方法——异步操作的返回值 632 8.2.4 Join方法——确保线程已终止 633 8.2.5 Kill方法——强制关闭进程 633 8.2.6 Process类——对正在计算机上运行的进程的访问 635 8.2.7 Sleep方法——线程挂起 640 8.2.8 Start方法——启动进程 640 8.2.9 Thread类——创建并控制线程的类 642 8.2.10 ThreadState属性——获取当前线程的状态 645 8.3 WMI技术——系统管理 646 8.3.1 MainWindowTitle属性——获取进程的主窗口标题 646 8.3.2 ManagementClass类——公共信息模型管理类 647 8.3.3 ManagementObject类——表示WMI实例 648 8.3.4 ManagementObjectSearcher类——查询检索管理对象 650 8.3.5 ManagementScope类——管理操作的范围 651 8.3.6 Microsoft.Win32命名空间——操作注册表类 652 8.3.7 WndProc方法——处理Windows消息 654 8.4 其他高级技术 655 8.4.1 Children属性——获取节点的子项 655 8.4.2 COM+服务——为类的实例提供服务 655 8.4.3 DirectShow技术——流媒体处理的一个开发包 656 8.4.4 DLL组件——动态链接库 663 8.4.5 MVC开发模式——模型视图控制器 664 8.4.6 VFW技术——视频应用程序提供的软件工具包 666 8.4.7 XML——定义其他标识语言的元标识语言 668 8.4.8 XmlReader类——XML读取器 670 8.4.9 XmlWriter类——XML编写器 673 附录——字母索引 676

110,529

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧