Windows Phone Developers

Tuesday, August 12, 2008

Get Stored Text from Clipboard using VB.NET

Extract Text from Clipboard using Vb.NET / Extract Clipboard Text from using Vb.NET

Sub Get_Text_From_ClipBoard()

Try

If My.Computer.Clipboard.ContainsText() Then

Dim ClipText As String

ClipText = My.Computer.Clipboard.GetText

MsgBox(ClipText)

Else

MsgBox("No Text in ClipBoard")

End If

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

See Also:

Clear Clipboard Content using VB.NET

Get Stored Images from Clipboard using VB.NET

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Get Stored Images from Clipboard using VB.NET

Extract Images from Clipboard using Vb.NET

Sub Get_Image_From_ClipBoard()

Try

If My.Computer.Clipboard.ContainsImage() Then

Dim ClipImage As System.Drawing.Image

ClipImage = My.Computer.Clipboard.GetImage

Me.Background = ClipImage

Else

MsgBox("No Images in ClipBoard")

End If

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

See Also:

Get Stored Text from Clipboard using VB.NET

Clear Clipboard Content using VB.NET

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Clear Clipboard Content using VB.NET

VB.NET Code to Delete Clipboard Contents

Sub Delete_ClipBoard_Content()

Try
My.Computer.Clipboard.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

See Also:

Get Stored Images from Clipboard using VB.NET

Get Stored Text from Clipboard using VB.NET Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Thursday, July 31, 2008

Validate Windows Form Controls in Vb.Net

Validation Controls for Windows Forms (VB.NET)

The Windows Forms ErrorProvider component is used to validate user input on a form or control. It is typically used in conjunction with validating user input on a form, or displaying errors within a dataset. An error provider is a better alternative than displaying an error message in a message box, because once a message box is dismissed, the error message is no longer visible. The ErrorProvider component displays an error icon ( ) next to the relevant control, such as a text box; when the user positions the mouse pointer over the error icon, a ToolTip appears, showing the error message string.


ErrorProvider Component

Drag the component to the Windows Forms Designer

ErrorProvider Component Attached to Designer


The ErrorProvider component's key properties are DataSource, ContainerControl, and Icon. When using ErrorProvider component with data-bound controls, the ContainerControl property must be set to the appropriate container (usually the Windows Form) in order for the component to display an error icon on the form. When the component is added in the designer, the ContainerControl property is set to the containing form; if you add the control in code, you must set it yourself.

The Icon property can be set to a custom error icon instead








The key method of the ErrorProvider component is the SetError method, which specifies the error message string and where the error icon should appear.

The code below uses ErrorProvider1.SetError instead of the usual msgbox for displaying errors.

Private Sub MaskedTextBox1_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles MaskedTextBox1.MaskInputRejected

If MaskedTextBox1.MaskFull Then

ErrorProvider1.SetError(MaskedTextBox1, "Please do not attempt to type extra data")

ElseIf e.Position = MaskedTextBox1.Mask.Length Then

ErrorProvider1.SetError(MaskedTextBox1, "End of Input: If necessary modify appropriate data by typeover")

Else

ErrorProvider1.SetError(MaskedTextBox1, "Only numerals are accepted")

End If

End Sub

The icon will appear next to the component that has error. This can be customized for your application. When you hover mouse over the icon, the error message will be displayed as a tooltip

Windows Forms ErrorProvider component in VB.NET, SetError Method in VB.NET, VB.NET Windows form Validation, Display error messages in tooltips using Vb.NET, VB.NET Windows Form Controls

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Visual Studio 2008 Image Library

The Visual Studio 2008 Image Library is a collection of application images that appear in Microsoft Windows, Microsoft Office, Microsoft Visual Studio, and other Microsoft software. You can use this set of over 1,000 images to create applications that look visually consistent with Microsoft software.

The image library includes three main categories of images: animations, bitmaps, and icons. A readme file, *readme.htm, is included for each major area. These readme files include information about the appropriate use of these images in your applications.
During Visual Studio setup, the image library is copied to your computer as the file VS2008ImageLibrary.zip. The default directory for this file is \...\Program Files\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary\ (for VS 2005) or C:\Program Files\Microsoft Visual Studio 9.0\Common7\.


VS2008ImageLibrary.zip


To Install VS 2008 Image library, right click the compressed file and select extract all and follow the process

Install Visual Studio 2008 Image Library

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Calculating Time taken for an operation using VB.NET (in Milliseconds)

Calculate Processing Time for a Vb.NET Subroutine (accuracy to millisecond)

Not every project will have the luxury of having rational analyzer to check the process time for every subroutine/function. In those cases we can use the StopWatch to determine the time taken for a program

Imports System.Diagnostics

Sub Get_Accurate_ProcessTime()

Dim oWatch As New Stopwatch

oWatch.Start()

Process_database()

oWatch.Stop()

MsgBox("Total Time Taken for Database Operation := " & oWatch.ElapsedMilliseconds.ToString)


End Sub

A Stopwatch instance can measure elapsed time for one interval, or the total of elapsed time across multiple intervals. In a typical Stopwatch scenario, you call the Start method, then eventually call the Stop method, and then you check elapsed time using the Elapsed property.
A Stopwatch instance is either running or stopped; use IsRunning to determine the current state of a Stopwatch. Use Start to begin measuring elapsed time; use Stop to stop measuring elapsed time. Query the elapsed time value through the properties Elapsed, ElapsedMilliseconds, or ElapsedTicks. You can query the elapsed time properties while the instance is running or stopped. The elapsed time properties steadily increase while the Stopwatch is running; they remain constant when the instance is stopped.

By default, the elapsed time value of a Stopwatch instance equals the total of all measured time intervals. Each call to Start begins counting at the cumulative elapsed time; each call to Stop ends the current interval measurement and freezes the cumulative elapsed time value. Use the Reset method to clear the cumulative elapsed time in an existing Stopwatch instance.
The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation.

The Stopwatch class assists the manipulation of timing-related performance counters within managed code. Specifically, the Frequency field and GetTimestamp method can be used in place of the unmanaged Win32 APIs QueryPerformanceFrequency and QueryPerformanceCounter. Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Tuesday, July 29, 2008

Create Custom Task Panes for Word using VSTO

How to Create a Word Addin using Visual Studio

Creating VSTO Word Addins in using Visual Studio is a simple process

Select Project - -> New Project - -> Office - ->Select the Version of Office (Office 2007, Office 2003) - ->Word 2007/2003 Addin


VSTO Word Addin

This will create a solution as shown below. A new class will be added with Startup and Shutdown methods



VSTO Startup & Shutdown Methods

To add a custom taskpane, insert an user control and add required controls on it and use the following code


VB.NET User Control
VSTO CustomTaskPane Designer

Imports Word = Microsoft.Office.Interop.Word

Public Class ThisAddIn

Private oUC As New UserControl1

Private oTaskPane As Microsoft.Office.Tools.CustomTaskPane

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

For i1 = 1 To Me.CustomTaskPanes.Count

Me.CustomTaskPanes.Remove(Me.CustomTaskPanes(i1))

Next i1

Add_Task_Pane()

End Sub

Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

End Sub

Public ReadOnly Property MyTaskPane() As Microsoft.Office.Tools.CustomTaskPane

Get

Return oTaskPane

End Get

End Property

Private Sub Add_Task_Pane()

oUC = New UserControl1 ' New Object of TaskPane (UserControl)

oTaskPane = Me.CustomTaskPanes.Add(oUC, "VBADUD Sample TaskPane", Me.Application.ActiveWindow)

oTaskPane.Visible = True

End Sub

Public ReadOnly Property WordDoc() As Word.Document

Get

Return Me.Application.ActiveDocument

End Get

End Property

End Class

To get the document information on the Label use the following code

Public Class UserControl1

Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Label1.Text = Globals.ThisAddIn.WordDoc.FullName

Label1.Update()

End Sub

End Class

WordDoc is retrieved from the property exposed by the Addin class


Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon