Windows report viewers offer several advantages over their web based counterparts.
1. Print preview is available - this view displays to the user what the form will look like when it is printed. Not available in html or on report server.
2. Often times HTML rendered reports do not appear the same as they do when they are printed. This can be confusing for the user and the developer.
3. More feature rich tool set from which to work from. In my experience, features like multi column reporting seem to work when viewed from the windows report viewer, but not when rendered in html using the web report viewer.
4. HTML/Server reports do not render the same in Firefox and IE. They do when using windows based reports.
With a little bit of configuration, windows report viewers can be embedded in asp/web pages.
This offers the advantages of web availability and windows report viewer functionality.
The next several entries will provide a method to embed a windows report viewer in a web page.
The idea is :
1. Publish a report to SQL report server.
2. Create a windows report viewer project to view the report.
3. Create a wpf project to hold the windows report viewer.
4. Create a web page to hold the wpf project.
5. Set up certificate permissions to view web page
The end result is an xbap (which can be embedded in a web page for presentation) that can dynamically display any report based on its path.
Wednesday, March 18, 2009
VB .NET Sizable, Draggable, Windows Components in Visual Studio 2008
Adding the following code will add a sizable, draggable, panel to the toolbox. Although in this instance, a panel is used. It just as easily could have been any other windo
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class ResizeablePanel
Inherits Panel
#Region "Resize"
Private mDragging As Boolean
Private mMousePos As Point
Private mSize As Size
Public Sub New()
Me.BackColor = Color.FromKnownColor(KnownColor.ButtonShadow)
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
If (mDragging) Then
Me.Width = mSize.Width + e.X - mMousePos.X
Me.Height = mSize.Height + e.Y - mMousePos.Y
Me.Invalidate()
Else
If (e.X >= Me.Width - 8 AndAlso e.Y >= Me.Height - 8) Then
Me.Cursor = Cursors.SizeNWSE
Else
Me.Cursor = Cursors.Default
End If
End If
MyBase.OnMouseMove(e)
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
mDragging = IIf(Me.Cursor = Cursors.SizeNWSE, True, False)
mMousePos = e.Location
mSize = Me.Size
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
mDragging = False
MyBase.OnMouseUp(e)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim rc As Rectangle = New Rectangle(Me.Width - 16, Me.Height - 16, 16, 16)
ControlPaint.DrawSizeGrip(e.Graphics, Me.BackColor, rc)
MyBase.OnPaint(e)
End Sub
#End Region
#Region "Drag"
' Used to store the current cursor shape when we start
' to move the control
Private m_CurrentCursor As Cursor
' Holds the mouse position relative to the inside of
' our control when the mouse button goes down
Private m_CursorOffset As Point
' Used by the MoveMove event handler to show that the
' setup to move the control has completed
Private m_Moving As Boolean
'Public Sub New()
' ' Call the constructor of the base Label class to properly
' ' initialize our control
' MyBase.New()
' ' Setup the Cursor property so that, by default, when the
' ' mouse passes over our control, the cursor changes to a hand
' Me.Cursor = Cursors.Hand
'End Sub
Private Sub MovableLabel_MouseDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseDown
' Check to see if the correct button has been pressed
If Not mDragging Then
If e.Button = Windows.Forms.MouseButtons.Left Then
m_CurrentCursor = MyBase.Cursor
' replace it with our new image that says were in Movable mode
MyBase.Cursor = Cursors.SizeAll
' Save the location of the mouse pointer relative to the top-left
' corner of our control
m_CursorOffset = e.Location
' Set the mode flag to signal the MouseMove event handler that it
' needs to now calculate new positions for our control
m_Moving = True
End If
End If
End Sub
Private Sub MovableLabel_MouseMove( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseMove
' Check which mode we're in. If we're supposed to be moving
' our control
If Not mDragging Then
If m_Moving Then
MyBase.Cursor = Cursors.SizeAll
' get the screen position of the mouse pointer and map it
' to the position relative to the top-left corner of our
' parent container
Dim clientPosition As Point = _
MyBase.Parent.PointToClient(System.Windows.Forms.Cursor.Position)
' Calculate the new position of our control, maintaining
' the relative position stored by the MoveDown event
Dim adjustedLocation As New Point( _
clientPosition.X - m_CursorOffset.X, _
clientPosition.Y - m_CursorOffset.Y)
' Set the new position of our control
MyBase.Location = adjustedLocation
End If
End If
End Sub
Private Sub MovableLabel_MouseUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseUp
' The button was released, so we're going back to Static mode.
If Not mDragging Then
m_Moving = False
MyBase.Cursor = m_CurrentCursor
End If
End Sub
#End Region
End Class
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class ResizeablePanel
Inherits Panel
#Region "Resize"
Private mDragging As Boolean
Private mMousePos As Point
Private mSize As Size
Public Sub New()
Me.BackColor = Color.FromKnownColor(KnownColor.ButtonShadow)
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
If (mDragging) Then
Me.Width = mSize.Width + e.X - mMousePos.X
Me.Height = mSize.Height + e.Y - mMousePos.Y
Me.Invalidate()
Else
If (e.X >= Me.Width - 8 AndAlso e.Y >= Me.Height - 8) Then
Me.Cursor = Cursors.SizeNWSE
Else
Me.Cursor = Cursors.Default
End If
End If
MyBase.OnMouseMove(e)
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
mDragging = IIf(Me.Cursor = Cursors.SizeNWSE, True, False)
mMousePos = e.Location
mSize = Me.Size
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
mDragging = False
MyBase.OnMouseUp(e)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim rc As Rectangle = New Rectangle(Me.Width - 16, Me.Height - 16, 16, 16)
ControlPaint.DrawSizeGrip(e.Graphics, Me.BackColor, rc)
MyBase.OnPaint(e)
End Sub
#End Region
#Region "Drag"
' Used to store the current cursor shape when we start
' to move the control
Private m_CurrentCursor As Cursor
' Holds the mouse position relative to the inside of
' our control when the mouse button goes down
Private m_CursorOffset As Point
' Used by the MoveMove event handler to show that the
' setup to move the control has completed
Private m_Moving As Boolean
'Public Sub New()
' ' Call the constructor of the base Label class to properly
' ' initialize our control
' MyBase.New()
' ' Setup the Cursor property so that, by default, when the
' ' mouse passes over our control, the cursor changes to a hand
' Me.Cursor = Cursors.Hand
'End Sub
Private Sub MovableLabel_MouseDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseDown
' Check to see if the correct button has been pressed
If Not mDragging Then
If e.Button = Windows.Forms.MouseButtons.Left Then
m_CurrentCursor = MyBase.Cursor
' replace it with our new image that says were in Movable mode
MyBase.Cursor = Cursors.SizeAll
' Save the location of the mouse pointer relative to the top-left
' corner of our control
m_CursorOffset = e.Location
' Set the mode flag to signal the MouseMove event handler that it
' needs to now calculate new positions for our control
m_Moving = True
End If
End If
End Sub
Private Sub MovableLabel_MouseMove( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseMove
' Check which mode we're in. If we're supposed to be moving
' our control
If Not mDragging Then
If m_Moving Then
MyBase.Cursor = Cursors.SizeAll
' get the screen position of the mouse pointer and map it
' to the position relative to the top-left corner of our
' parent container
Dim clientPosition As Point = _
MyBase.Parent.PointToClient(System.Windows.Forms.Cursor.Position)
' Calculate the new position of our control, maintaining
' the relative position stored by the MoveDown event
Dim adjustedLocation As New Point( _
clientPosition.X - m_CursorOffset.X, _
clientPosition.Y - m_CursorOffset.Y)
' Set the new position of our control
MyBase.Location = adjustedLocation
End If
End If
End Sub
Private Sub MovableLabel_MouseUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseUp
' The button was released, so we're going back to Static mode.
If Not mDragging Then
m_Moving = False
MyBase.Cursor = m_CurrentCursor
End If
End Sub
#End Region
End Class
Subscribe to:
Posts (Atom)