visual basic 2005 express corrado cavalli microsoft.net mvp [email protected]
TRANSCRIPT
Visual Basic 2005 Express
Corrado CavalliMicrosoft .NET [email protected]
ImparareImparare.NET.NET
InterazioneInterazionetra studentitra studenti
CreareCreareapplicazioniapplicazioni
ImparareImparare VB VB
Hobbistii
StudentiStudenti Universitari
Appassionati
ExpresExpresss
StandarStandardd ProPro TeamTeam
Windows or Web DesignersWindows or Web Designers
Code Editors and IntelliSenseCode Editors and IntelliSense
Programming LanguagesProgramming Languages
Remote Data AccessRemote Data Access
Mobile Device DevelopmentMobile Device Development
User ExperienceUser Experience SimplifiedSimplified SimplifiedSimplified
Server Server Development/DebuggingDevelopment/Debugging
SQL Server 2005 SQL Server 2005 DevelopmentDevelopment
Application Modeling,Application Modeling,Code Profiling, Unit Testing, Code Profiling, Unit Testing, Static Code Analysis, Load Testing, Static Code Analysis, Load Testing, Enterprise Source Control, Enterprise Source Control, Work Item TrackingWork Item Tracking
Cosa c’è di nuovo?• Edit and Continue • My• Generics • Click Once• Data Sources Windows• Object Binding• Web Service Binding• Debugger Visualizers • Just My Code Debugging • The Exception Assistant • Design Time Expression Evaluation • IntelliSense Code Snippets • XML Comments • Error Correction and Warnings • Rename • Attribute Editing • IntelliSense Filtering • IntelliSense in Zone • New VB Item Templates • Find References • Exportable Development Settings • Simplified Tools -> Options• Project Designer • Starter Kits • XML Editor• Zero Impact Projects• Start Page• Authenticode signing support• Custom Setup Bootstrapper• Big 5 Bootstrapper packages
(Fx 2.0, SSE, etc.)• Strongly typed Resources
• Registration Free COM• Strongly typed Settings• Using statement• Continue statement• Global keyword• Accessor accessibility • Partial types• Unsigned types• Operator overloading• Warnings• Custom Events• TableAdapters• DataSet Designer• Drag Once Form creation• Smart Tags• Parameterized query• Connect the Dots databinding• Custom Control drag / drop• Lookup table binding• Upgrade WebBrowser• Upgrade Masked Edit • Upgrade Rich textbox • Upgrade Windows Common Controls
– TreeView, ListView, ImageList– ToolBar, StatusBar, ProgressBar
• Upgrade Common Dialogs• Upgrade MTS/COM+ Projects• Upgrade BackgroundImageLayout Property • Upgrade keys in KeyPress event • Upgrade additional Keywords• Updated Keys In Control Collections • Upgrade Unload Mode in FormClosing
Event
What’s new: Linguaggio
• Generics
• Partial Types
• IsNot
• Accessor accessibility
• Continue
• Operator overloading
• My
GenericsPrivate _Items As CollectionPrivate _Items As Collection
Private Sub Class_Initialize()Private Sub Class_Initialize() Set _Items = New CollectionSet _Items = New CollectionEnd SubEnd Sub
Private Sub Class_Terminate()Private Sub Class_Terminate() Set _Items = NothingSet _Items = NothingEnd SubEnd Sub
Public Function NewEnum() As stdole.IUnknownPublic Function NewEnum() As stdole.IUnknown Set NewEnum = moItems.[_NewEnum]Set NewEnum = moItems.[_NewEnum]End FunctionEnd Function
Public Function Item(Key As String) As PersonPublic Function Item(Key As String) As Person On Error Resume NextOn Error Resume Next Set Item = _Items.Item(Key)Set Item = _Items.Item(Key)End FunctionEnd Function
Public Property Get Count() As LongPublic Property Get Count() As Long Count = _Items.CountCount = _Items.CountEnd PropertyEnd Property
Public Sub Add(Person As Person, Key As String)Public Sub Add(Person As Person, Key As String) _Items.Add Text, Text.Key_Items.Add Text, Text.KeyEnd SubEnd Sub
Public Sub Remove(Index As Integer)Public Sub Remove(Index As Integer) _Items.Remove Index_Items.Remove IndexEnd SubEnd Sub
Public Class Cars : Inherits CollectionBasePublic Class Cars : Inherits CollectionBase Public Sub Add(ByVal item As Person)Public Sub Add(ByVal item As Person) MyBase.InnerList.Add(item)MyBase.InnerList.Add(item) End SubEnd Sub
Default Property Item(ByVal index As Integer) As PersonDefault Property Item(ByVal index As Integer) As Person GetGet Return DirectCast(MyBase.InnerList(index), Person)Return DirectCast(MyBase.InnerList(index), Person) End GetEnd Get Set(ByVal Value As Person)Set(ByVal Value As Person) MyBase.InnerList(index) = ValueMyBase.InnerList(index) = Value End SetEnd Set End PropertyEnd PropertyEnd ClassEnd Class
VB6
VB.NET
VB2005Dim Cars As New List(Of Car)
Cars.Add(New Car())
• Permettono la definizionedi tipi “incompleti” che verrano completati a compile time.
File Class1.vbFile Class1.vbPublic Class CarPublic Class Car Public Sub Start()Public Sub Start() End SubEnd SubEnd ClassEnd Class
File Class2.vbFile Class2.vbPublic Public PartialPartial Class Car Class Car Public Sub Stop()Public Sub Stop() End SubEnd SubEnd ClassEnd Class
Dim T As New Car()Dim T As New Car()T.Start()T.Start()T.Stop()T.Stop()
Partial Types
IsNot
Public Sub Test(ByVal o As SomeType)Public Sub Test(ByVal o As SomeType) If Not o Is Nothing ThenIf Not o Is Nothing Then o.DoSomething()o.DoSomething() ElseElse Throw New NullReferenceException()Throw New NullReferenceException() End IfEnd IfEnd SubEnd Sub
Public Sub Test(ByVal o As SomeType)Public Sub Test(ByVal o As SomeType) If o If o IsNotIsNot Nothing Then Nothing Then o.DoSomething()o.DoSomething() ElseElse Throw New NullReferenceException()Throw New NullReferenceException() End IfEnd IfEnd SubEnd Sub
Accessor Accessibility
Assembly Foo.dll
Public Class Person Private mName As String Public ReadOnly Property Name() As String Get Return mName End Get End Property
Friend WriteOnly Property SetName() As String Set(ByVal value As String) mName = value End Set End PropertyEnd Class
Assembly Assembly Foo.dllFoo.dll
Public Class PersonPublic Class Person Private mName As StringPrivate mName As String Public Property Name() As StringPublic Property Name() As String GetGet Return mNameReturn mName End GetEnd Get FriendFriend Set(ByVal value As String) Set(ByVal value As String) mName = valuemName = value End SetEnd Set End PropertyEnd PropertyEnd ClassEnd Class
Continue • Trasferisce il controllo all’iterazione successiva di un
ciclo For,Do, While
For i as Int32=0 to 10For i as Int32=0 to 10 If (i mod 2 =0 ) Then Continue ForIf (i mod 2 =0 ) Then Continue For Debug.WriteLine(i) ‘ 1,3,5,7,9Debug.WriteLine(i) ‘ 1,3,5,7,9NextNext
Dim i, j, k As Int32Dim i, j, k As Int32Dim rnd As New Random(DateTime.Now.Millisecond)Dim rnd As New Random(DateTime.Now.Millisecond)ForFor i = 0 To 5 i = 0 To 5 j = 0 j = 0 WhileWhile (j < 3) (j < 3) j += 1 j += 1 k = 0 k = 0 DoDo k += 1 k += 1 If (rnd.Next(100) >= 90) Then If (rnd.Next(100) >= 90) Then Continue ForContinue For LoopLoop Until k > j Until k > j End WhileEnd While Debug.WriteLine(String.Format("{0} {1} {2}", i, j, k)) Debug.WriteLine(String.Format("{0} {1} {2}", i, j, k))NextNext
Operator Overloading
Public Class SetPointPublic Class SetPoint Public Temperature as Single Public Temperature as Single Public Sub New (value as Single) Public Sub New (value as Single) Me.Temperature=valueMe.Temperature=value End Sub End SubEnd ClassEnd Class
Dim T1 as New SetPoint(12.5)Dim T1 as New SetPoint(12.5)Dim T2 as New SetPoint(13)Dim T2 as New SetPoint(13)Dim T3 as SetPoint = T1 + T2Dim T3 as SetPoint = T1 + T2
Public Class SetPointPublic Class SetPoint Public Temperature as Single Public Temperature as Single Public Sub New (value as Single) Public Sub New (value as Single) Me.Temperature=valueMe.Temperature=value End Sub End Sub
Public Shared Public Shared OperatorOperator +(ByVal a As SetPoint,_ +(ByVal a As SetPoint,_ ByVal b As SetPoint) As SetPointByVal b As SetPoint) As SetPoint
Return New SetPoint(a.Temperature + b.Temperature)Return New SetPoint(a.Temperature + b.Temperature)End OperatorEnd Operator
End ClassEnd Class
My
Application
Computer
User
Resources
Settings
WebServices
Forms
— Application title, version, logs, description, …— Registry, Printer, Audio, File System, …
— User name, group, domain, …
— Accesso alle risorse di un applicazione
— User e application settings
— Collezione dei form presenti nel progetto
— Collezione dei web services referenziati
My Namespace
Compiler & IDE Features
• Edit & Continue– Modificare il sorgente durante il debug senza riavviare
• Autocorrect
– Smart tag di autocorrezione• Expansions/Snippets
– Inserimento di blocchi di codice • XML Comments• Import / Export settings• Warnings
– Analisi dettagliata del codice• Enhanced debugging
– Debugger Visualizers– Debugger DataTips
Novità dei controlli windows• Smart Tags• Form
– ValidateChildren– Eventi FormClosing, StyleChanged
• TextBox– AutoComplete
• Masked Textbox• PictureBox
– Può caricare immagini da URL in modo asincrono
– LoadAsync(www.mysite.org/image.gif)
• WebBrowser• Enhanced ListView
– Può visualizzare informazioni raggruppate
– Virtual Mode
• Treeview– Supporta modalità OwnerDrawn
Novità dei controlli windows
• ToolStrip, MenuStrip, StatusStip, ToolStripContainer– Permettono di avere GUI “Office like”
• SerialPort• FlowLayouPanel, TableLayoutpanel,SplitContainer• DatagridView
– Nuova grid data-aware, rimpiazza il controllo Datagrid• Progressbar
– Marquee mode• BackgroundWorker
– Esegue operazioni in secondary thread gestendo il necessario marshaling
Drag & Drop Databinding
ClickOnce• Applicazioni
– Windows• Difficili da aggiornare
– Web • Server centrale, fix once.• Più difficile scrivere le applicazioni• No Offline mode
• Creazione di Smart Client
– Installazione da Web• Online• Online/Offline
– Autoupdate dell’applicazione• Allo startup• Dopo lo startup ad intervalli predefiniti• Via codice (System.Deployment)
• RegFree COM
Quanto costa?
•Gratis! – Scaricate le versioni da MSDN– Potete usare le versioni Express per scopi
commerciali
• ~50 €– DVD– Esempi e Starter Kits– Documentazione aggiuntiva
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN