Visual Basic 6.0 的 Screen 對(duì)象在 Visual Basic 2005 中沒(méi)有直接等效項(xiàng),但是可以使用 .NET Framework 來(lái)重復(fù)它的大部分功能。
在 Visual Basic 6.0 中,Screen 對(duì)象提供對(duì)應(yīng)用程序中的活動(dòng)窗體和控件的訪問(wèn),提供有關(guān)正在顯示應(yīng)用程序的屏幕的信息,并且允許控制光標(biāo)的外觀。
在 Visual Basic 2005 中,沒(méi)有對(duì)應(yīng)于 Screen 對(duì)象的直接等效項(xiàng),但是可以使用 .NET Framework 來(lái)重復(fù)它的大部分功能。
![]() |
---|
Visual Basic 2005 具有一個(gè) Screen 屬性 -- My.Computer.Screen。與 Visual Basic 6.0 Screen 對(duì)象不同,My.Computer.Screen 僅返回有關(guān)屏幕的只讀信息,如它的設(shè)備名稱(chēng)、工作區(qū)和顏色深度。有關(guān)更多信息,請(qǐng)參見(jiàn) |
在 Visual Basic 6.0 中,Screen 對(duì)象的 ActiveControl 屬性用于確定擁有焦點(diǎn)的控件。ActiveControl 屬性可用于全局功能中,例如,用于 Screen.ActiveControl
中,此時(shí)將返回當(dāng)前選定窗體上的活動(dòng)控件。如果引用了特定窗體(例如,Form2.ActiveControl
),則 ActiveControl 在引用窗體為活動(dòng)時(shí)指定將擁有焦點(diǎn)的控件。
在 Visual Basic 2005 中,不再有全局的 ActiveControl 屬性;窗體的每一個(gè)實(shí)例都具有它自己的 ActiveControl 屬性。當(dāng)引用特定的窗體時(shí),該屬性的工作方式與它在 Visual Basic 6.0 中的完全相同。若要確定當(dāng)前選定窗體上的活動(dòng)控件,必須先循環(huán)訪問(wèn) OpenForms 集合并檢查 ContainsFocus 屬性,確定哪一個(gè)窗體是活動(dòng)的。
在 Visual Basic 6.0 中,Screen 對(duì)象的 ActiveForm 屬性用于確定當(dāng)前哪一個(gè)窗體擁有焦點(diǎn)。如果 MDI 父窗體擁有焦點(diǎn),則 ActiveForm 返回最近一次擁有焦點(diǎn)的 MDI 子窗體。
在 Visual Basic 2005 中,不再有全局 ActiveForm 屬性。若要確定活動(dòng)窗體,必須循環(huán)訪問(wèn) OpenForms 集合并查找其 ContainsFocus 屬性設(shè)置為 True 的窗體。
Visual Basic 2005 MDI 父窗體(IsMDIContainer 設(shè)置為 True 的任何窗體)具有一個(gè) ActiveMDIChild 屬性,它可用于返回活動(dòng)子窗體而不必使用 OpenForms 集合。
在 Visual Basic 6.0 中,Screen 對(duì)象的 MousePointer 屬性用于更改光標(biāo)的外觀;設(shè)置之后它將應(yīng)用于應(yīng)用程序中的所有窗體。
在 Visual Basic 2005 中,不再有全局 MousePointer 屬性;每個(gè)窗體都具有一個(gè) Cursor 屬性,它可用于僅更改該窗體的光標(biāo)外觀。
在 Visual Basic 6.0 中,Screen 對(duì)象的 TwipsPerPixelX 和 TwipsPerPixelY 屬性用于將屏幕度量從邏輯緹(Visual Basic 6.0 中的標(biāo)準(zhǔn)度量單位)轉(zhuǎn)換為像素。
在 Visual Basic 2005 中,像素是標(biāo)準(zhǔn)度量單位;不再需要任何轉(zhuǎn)換。
下面的示例演示 Visual Basic 6.0 和 Visual Basic 2005 在編碼方法上的不同之處。
下面的代碼演示如何從當(dāng)前選定窗體上的當(dāng)前選定控件將文本復(fù)制到剪貼板。
![]() | |
---|---|
' Visual Basic 6.0 If TypeOf Screen.ActiveControl Is TextBox Then Clipboard.SetText Screen.ActiveControl.Text End If |
Visual Basic | ![]() |
---|---|
' Visual Basic 2005 Dim i As Integer For i = 0 To My.Application.OpenForms.Count - 1 If My.Application.OpenForms.Item(i).ContainsFocus Then If TypeOf (My.Application.OpenForms.Item(i).ActiveControl) _ Is TextBox Then My.Computer.Clipboard.SetText(My.Application.OpenForms. _ Item(i).ActiveControl.Text) End If End If Next |
下面的代碼演示如何更改當(dāng)前選中窗體的標(biāo)題。
![]() | |
---|---|
' Visual Basic 6.0 Screen.ActiveForm.Caption = "This is the selected form" |
Visual Basic | ![]() |
---|---|
' Visual Basic 2005 Dim i As Integer For i = 0 To My.Application.OpenForms.Count - 1 If My.Application.OpenForms.Item(i).ContainsFocus Then My.Application.OpenForms.Item(i).Text = _ "This is the selected form" End If Next |
下面的代碼演示如何更改當(dāng)前選中的 MDI 子窗體的標(biāo)題。
![]() | |
---|---|
' Visual Basic 6.0 Screen.ActiveForm.Caption = "This is the selected child form" |
Visual Basic | ![]() |
---|---|
' Visual Basic 2005 Me.ActiveMdiChild.Text = "This is the selected child form" |
下表列出了 Visual Basic 6.0 屬性和它們的 Visual Basic 2005 等效項(xiàng)。根據(jù)需要提供了解釋行為差異的主題鏈接。如果 Visual Basic 2005 中沒(méi)有直接等效項(xiàng),則提供指向介紹替換項(xiàng)的主題的鏈接。
Visual Basic 6.0 | Visual Basic 2005 等效項(xiàng) |
---|---|
ActiveControl | My.Application.OpenForms(0).ActiveControl |
ActiveForm | My.Application.OpenForms(0).ContainsFocus 或 |
FontCount Fonts | 新的實(shí)現(xiàn)。枚舉字體的行為有所不同。有關(guān)更多信息,請(qǐng)參見(jiàn)字體處理(針對(duì) Visual Basic 6.0 用戶(hù))。 |
Height | My.Computer.Screen.Bounds.Height |
MouseIcon | 新的實(shí)現(xiàn)。有關(guān)更多信息,請(qǐng)參見(jiàn)無(wú)法設(shè)置自定義 MousePointer。 |
MousePointer | System.Windows.Forms.Cursor |
TwipsPerPixelX TwipsPerPixelY | 新的實(shí)現(xiàn)。在 Visual Basic 2005 中,坐標(biāo)以像素為單位;緹不用作度量單位。 |
Width | My.Computer.Screen.Bounds.Width |
當(dāng) Visual Basic 6.0 應(yīng)用程序升級(jí)到 Visual Basic 2005 時(shí),Screen 對(duì)象的任何屬性都會(huì)升級(jí)到各自的 Visual Basic 2005 等效項(xiàng)。在可能存在行為差異的情況下,向代碼中插入升級(jí)注釋。
聯(lián)系客服