400 likes | 581 Views
ISV Community Day. Nyheter i Visual Studio 2005 och Visual Basic .NET. Per Ahlberg Developer Evangelist Developer & Platform Evangelism Microsoft Sweden. Agenda. Visual Basic Language Enhancements New UI features in Windows Forms 2.0 Building Data-bound Windows Forms Applications.
E N D
ISV Community Day Nyheter i Visual Studio 2005 och Visual Basic .NET Per Ahlberg Developer Evangelist Developer & Platform Evangelism Microsoft Sweden
Agenda • Visual Basic Language Enhancements • New UI features in Windows Forms 2.0 • Building Data-bound Windows Forms Applications
Generics • Code can be parameterised with type details • Enables the creation of code templates • Appropriate type specified when template used • Like Eiffel and Ada generics and C++ templates • Can create various types of generics • Classes, structs, interfaces, methods and delegates • Provide significant benefits for generic code • Enables stronger compile-time type checking • Less run-time type checking, boxing and unboxing • Reduces need for explicit type conversions • Results in cleaner and faster type safe code
Creating Generics (Visual Basic) ' Generic MyStack class Public Class MyStack(Of T) Private frames As T() Private pointer _ As Integer = 0 Public Sub New( _ ByVal size As Integer) frames = New T(size) {} End Sub Public Sub Push( _ ByVal frame As T) frames(pointer) = frame pointer += 1 End Sub Public Function Pop() As T pointer -= 1 Return frames(pointer) End Function End Class Dim s As New _ MyStack(Of Integer)(7) For f As Integer = 0 To 6 s.Push(f) Next f ' Prints 6543210 For f As Integer = 0 To 6 Console.Write( _ s.Pop().ToString()) Next f
Partial Types • Allow an implementation to span multiple files • Valid for classes and structures (and C# interfaces) • Declared using new type modifier partial • Provide a number of benefits • Large implementations can be split up • User code can be separated from generated code • Prevents regeneration overwriting changes • Used by WinForms and strongly typed DataSets • Multiple developers can work on the same type • Enables code-beside as opposed to code-behind • Used by ASP.NET 2.0 • Can ease maintenance and source control
Examples (Visual Basic) ' Demo.Part1.vb Imports System Partial Public Class Demo Public Sub New() Console.Write("P1") End Sub End Class ' Demo.Part2.vb Partial Public Class Demo Private i As Integer End Class ' Demo.Part3.vb ' OK in Visual Basic Public Class Demo ' Error! Private i As Integer ' OK Private j As Integer Public Sub Test() ' OK in Visual Basic Console.Write("P3") End Sub End Class
Using Partial Types • Splitting a type does not affect compiled code • All parts must be merged at compile-time • Cannot extend an already compiled type • Code is accumulative or non-accumulative • Accumulative elements are combined • Includes methods, fields and interfaces • Non-accumulative elements must match in all parts • Includes type, visibility and base class • Helps to agree naming convention • For example MyCls.Part1.cs and MyCls.Part2.cs • Class View and navigation bar reflect full type
Accessibility Modifiers • Can now specify different accessibility for get and set accessors of properties and indexers • Common to want public get but protected set • Can only modify one of the two accessors • Other accessor takes its accessibility from the property or indexer declaration • Can only specify more restrictive accessibility Public Property Counter() As Integer Get Return _Counter End Get Friend Set(ByVal value As Integer) _Counter = value End Set End Property
My Classes • Provide access to common functionality • Significantly reduces amount of coding • Greatly improves productivity and ease of use • Discoverable through IntelliSense • My classes include: • My.Application • My.Computer • My.User • My.Forms • My.Webservices • My.Resources • My.Settings
Examples ' Show command line arguments For Each s As String In My.Application.CommandLineArgs MessageBox.Show(s) Next ' Show Visual Studio files in My Documents For Each s As String In My.Computer.FileSystem.GetFiles( _ My.Computer.FileSystem.SpecialDirectories.MyDocuments, _ False, "Visual Studio*.doc") MessageBox.Show(s) Next ' Test user permissions If My.User.IsInRole( "Administrators") Then MessageBox.Show( "Hello Administrator " + My.User.Identity.Name) End If ' Call web service method MessageBox.Show( My.WebServices.DemoService.HelloWorld())
Statements • New Continue statement • Skips to next iteration of Do, For, or While loop • New Using statement • Ensures disposal of unmanaged resources ' Visual Basic 2003 Dim p As Pen = New Pen(c) Try g.DrawLine(p, 0, 0, 50, 50) Finally If Not p Is Nothing Then CType(p, IDisposable) _ .Dispose() End If End Try ' Visual Basic 2005 Using p As New Pen(c) g.DrawLine(p, 0, 0, 50, 50) End Using
Operator Overloading • Can now overload standard operators • Supported for classes and structures ' Class with overload of + Public Class Dem Private x As Byte Private y As Byte Public Sub New(ByVal i As _ Byte, ByVal j As Byte) Me.x = i Me.y = j End Sub Public Overrides Function _ ToString() As String Return String.Format( _ "[{0},{1}]", x, y) End Function Public Shared Operator +( _ ByVal d1 As Dem, _ ByVal d2 As Dem) As Dem Return New Dem( _ d1.x + d2.x,d1.y + d2.y) End Operator End Class ' Test code Dim d1 As Dem = New Dem(1, 0) Dim d2 As Dem = New Dem(2, 2) Dim d3 As Dem = d1 + d2 d3 += d1 Trace.Write(d3) ' Prints [4,2]
Other Enhancements • Unsigned integer types • Additional types UShort, UInteger, and ULong • New IsNot operator • Helps avoid awkward syntax with Not and Is • Explicit zero lower bound on arrays • Makes bound clear, e.g. Dim b(0 To 7) As Byte • New compiler features • CLS compliance and uninitialised variable checks • New options including warning control • XML documentation comments using '''
Windows Forms 2.0 Goals • Bring the ease and reliability of Web application deployment to client apps • ClickOnce • Professional Look and Feel • New controls and enhancements • Simplify client application development • Simplify working with data • Fewer lines of code • Fewer clicks
ToolStrip Control • Toolstrips are highly customizable UI elements for toolbars, menus, drop-down menus, context menus and status bars • Features: • Layout support • Horizontal Vertical, Flow, Table • Overflow support • Styling ( or RenderMode ) • Professional • System • ManagerRenderMode (for custom)
ToolStrip Control (cont) • More features: • Hosting controls in menus and toolbars • Button, Labels, SplitButton, DropDown, Separator, Combobox, TextBox, ProgressBar, and custom • Enhanced design time experience • Drag & Drop • Smart Tag support • Editing Menus & Sub-Menus • Flexible run-time experience • Reordering, drag & drop ,tooltips,
SplitContainer Control • Single control composed of a splitter and two panel controls • More intuitive, easier to use Splitter control • Can be vertically or horizontally oriented • No z-order • Other Features: • SplitterDistance, IsSplitterFixed, FixedPanel • Panel1MinSize and Panel2MinSize • Eventing ( SplitterMoved, SplitterMoving)
WebBrowser Control • Optimized managed wrapper to IE browser Control • Features: • Navigation support • Navigate(), GoBack(), GoForward(), GoHome(), GoSearch(), Refresh(), Stop() • Security Level Control • AllowNavigation, AllowWebBrowserDrop • Managed code and script interaction
MaskedTextBox control • Allows users to specify the shape of the input for a TextBox control • Masking language is a combination of Access and VB6 • Support for parsing types • Support for Mask literals • Notification on Invalid input • MaskedTextProvider gives masking support to other controls
Snaplines • Replaces grid layout mode • In-situ alignment • Like snaps to like (e.g. left border to left, etc.), exposes margins/padding • Controls can expose “interesting points” • TextBox and Label “baseline” snapline
Smart Tags • In-site tasks • Extensible
Document Outine View • Allows easy control navigation, Z-order modification, parenting
Layout containers • Layout containers replace absolute positioning with their own logic for laying out child controls • Ideal for user-resizable dialogs and other forms of UI that resizes at runtime • Two layout containers shipping: • FlowLayoutPanel • TableLayoutPanel • Developers can create custom layout containers (layout engines)
FlowLayoutPanel • Offers HTML-style flow layout of child controls • Flow direction can be horizontal or vertical • Child controls can be aligned or “stretched” using the Anchor and Dock properties • Full design-time support • Excellent for “wrapping” portions of UI, or Web Portal-style interfaces
TableLayoutPanel • Offers HTML-style table layout of child controls • Excellent for supporting UI that needs to resize proportionally • 1 control per cell • Supports cell merging (both rows and columns) • Columns/rows can be absolutely or relatively sized, or autosize based on contents • Child controls can be aligned or “stretched” within each cell using the Anchor and Dock properties • Full design-time support (including smart tags)
Control API additions • Control expose new interesting properties: • AutoRelocate • AutoSize • Padding • Margin
More Designer & Layout Features • RTL support ( for control & Form) • Toolbox improvements • Auto-population of ‘in-project’ user controls • Search/Filter in Customize Toolbox dialog • Designer dragging improvements • WYSIWYG • Semi-transparency
Summarizing.. • Windows Forms 2.0 introduces a myriad of controls and features that allow you to create professional looking client applications in less time, lines of code, and less clicks than ever before.. • DataGridView • DataSources Window • BindingSource • BindingNavigator • Smart tags • Document Outline • FlowLayout • TableLayout • ToolStrips • WebBrowser • MaskedTextBox • SplitContainer • Sound
Many more run-time features… • Client Configuration • Read/Write User Settings • BackgroundWorker for async programming • Managed Sound API • Play System sounds, Play files (local, or http) • Enhanced Existing Controls • ListView: virtualization, owner draw • TreeView: owner draw, nodes editor • TextBox: AutoComplete, Multi-line • Tooltip: owner draw, BubbleMode
DataSources Window • Displays all the data sources in your project • Three types of datasources: • DataBase, Object, and WebService • Includes Wizard to define or connect to the datasources
DataSources Window (Features) • Enables creation of user interface by dragging data source items onto forms. • Creation of grid controls • Creation of individual controls for details view • Type mappings between data types and UI controls for customizable creation of controls • Smart Master/Details View
BindingSource Component • Design-time CurrencyManager support for • Objects • Web Services • DataSets • The BindingSource provides indirection • Before • After Dim ds as DataSet Dim ws as new myserver.WebService1 ds = ws.GetOrders Me.OrdersDataSet1.Merge(ds) Dim ws as new myserver.WebService1 Me.BindingSource1.DataSource = ws.GetOrders
BindingNavigator control • “VCR” control for data-bound user interfaces • Can be customized or extended
DataGridView Control • New implementation of DataGrid • Flexible, Extensible, Easy, Scalable • In-place control hosting • Shipping with multiple column/cell types • TextBox, ComboBox, Link, Image, CheckBox, Button • Flexibile DataBinding modes • Bound, Unbound, Virtual, Bound + Virtual
DataGridView control (cont.) • Copy to Clipboard support • Row & Column Freezing, • AutoSizing (based on displayed or all rows) • Advanced Customization • Cell based styling • Row and Cell painting • Error handling support • Global & cell events • Cell & row error icons
DataSet Designer Features • Visually design DataSets • Dragging to generate relationships • You no longer use the XSD editor • Property sheet has properties • Design typed DataAdapters • Automatically-generated Fill method is created • Create multiple Fill and Get methods • Map to queries and stored procedures • Use Add Query to add a custom query • DataSet extensibility through partial classes • Add custom validation logic • No need to inherit or change generated code
DesignEnhancements Through the Data Preview Dialog Box • Preview data from typed DataSets • Design-time editing • Saves time • Uses the typed FillBy methods
Code Enhancements • Physical separation between developer code and generated code • NorthwindDataSet.vb (developer code) • NorthwindDataSet.Designer.vb (generated code) • Partial class • Prevents overwriting code • Extensibility enhanced • Associated typed DataAdapters (TableAdapters)
Strongly-Typed DataSets • IDE Enhancements • New DataSet designer • No longer uses XSD editor • Property sheet has real properties • Automatically creates relationships from the underlying database