Windows Phone Developers

Sunday, May 29, 2011

ForEach Loop in Array (C# / VB.NET)

How to iterate elements of Array using ForEach in .NET (C#)

Here is a simple example of that:

string[] arString = null;
            arString = new string[2];
            arString[0] = "First Element";
            arString[1] = "Second Element";
            foreach (string s1 in arString)
            {
                Console.WriteLine(s1);
            }
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

Wednesday, May 25, 2011

How to Write Padded (Formatted) Text File using VB.NET/C#

Writing Equi-Spaced Output using C# and VB.NET

Here is a small code to write a multiplication table.

For i1 As Integer = 1 To 20

Console.WriteLine(i1.ToString & " x 12 = " & (i1 * 12).ToString)

Next i1




Have you ever thought it would be better to have it properly aligned. Then use the Padding options (PadeLeft here) to format the output



Private Sub WritePaddedText()

        ' Write a Padded Multiplication Table
        For i1 As Integer = 1 To 20
            Console.WriteLine(i1.ToString.PadLeft(2) & " x  12 = " & (i1 * 12).ToString.PadLeft(3))
        Next i1
    End Sub


See also :How to Create Equispaced Text File using VBA; Spacing in Text Files 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

Unable to copy file "obj\x86\Debug\*.exe" to "bin\Debug\*.exe". The process cannot access the file 'bin\Debug\*.exe' because it is being used by another process.

To release the file go to the Task Manager and see if the Exe is running in the process Tab. Kill the process and Build the project it should work.

But before that make sure why the Exe was still running in the process even after the application is termninated. It might be due to some malperformance of garbage collection 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, May 24, 2011

VB.NET How to Resize the form along with Controls

Windows Form - Resize Controls Dynamically using VB.NET

There would be many occasions you would have come across the need to resize the form to fit some controls/text etc. In the following example we use the combination of LinkLabel and Panel Control to achieve that

Here is the sample form

This is how it needs to be expanded to accomodate the additonal information

I have used a '+/-' hyperlink (LinkLabel Control) to resize the form. (For more info on Link Label : Hyperlink Control in Windows Forms (VB.NET) Application). You can use >> or << etc to be more clear

The controls for Year Founded and Financial Performance are enclosed in a Panel

Add the following code to the LinkClicked event of the LinkLabel

If Panel1.Height = 0 Then
            Panel1.Height = 110
            Me.Height = Me.Height + 110
        Else
            Panel1.Height = 0
            Me.Height = Me.Height - 110

        End If


The form gets re-sized on clicking the hyperlink (it actually toggles)

See also : How to Get Width and Height of Desktop Screen using C#/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

Sunday, May 15, 2011

Hyperlink Control in Windows Forms (VB.NET) Application

How to use Hyperlinks on WinForms (VB.NET)

Create a small Windows Forms like the one below and add LinkLabel Control on the form:


Add the following code to the LinkLabel's LinkClicked event:

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        System.Diagnostics.Process.Start("www.google.com")
    End Sub


This will open the website in a new IE window 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

How to find Difference between two time (Dates) using VB.NET

Difference between two different dates using VB.NET

DATEDIFF function will come handy to find the difference between a set of dates. The snippet given below gets the difference in seconds

Private Sub DateDiffExample()

        Dim dt1 As Date = New Date(2011, 5, 15, 10, 11, 2)
        Dim dt2 As Date = New Date(2011, 5, 15, 10, 12, 22)

        Dim dt3 As Long = DateDiff(DateInterval.Second, dt1, dt2)

    End Sub

You can tweak a bit to get for Minutes or Hours etc by

Private Sub DateDiffExample()

        Dim dt1 As Date = New Date(2011, 5, 15, 10, 11, 2)
        Dim dt2 As Date = New Date(2011, 5, 15, 10, 12, 22)

        Dim dt3 As Long = DateDiff(DateInterval.Minute, dt1, dt2)

    End Sub

Other useful links:

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

Changes are not allowed while code is running or if the option 'Break all

If you are getting this error while editing the code, check if the Break all process option is enabled.


If 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