Tuesday, December 23, 2008

Change project build mode from Debug to Release

In every project after completing the whole work we need to change the project build mode from Debug to Release before delivery to the client. To change the project build mode at first go to “Build” menu, then “Configuration Manager” submenu.

Change “Active solution configuration” from Debug to Release. Then close it.

After this press F5. Now the application will run and you will see the .exe file has been generated on the \bin\Release folder.

Monday, December 8, 2008

Set image to Picture Box from webpage.

A few months ago I learnt an interesting thing. I have to set an image to a Picture Box from a webpage. For the first time I was a little bit surprised to hear this. But after completing the code, I realized that it was not too hard that I was thinking of.

First declare and initialize an HttpWebRequest object such as:

Dim req As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create(url), Net.HttpWebRequest)

Here url is the respective url of the webpage that contains the image.

Now declare and initialize an HttpWebResponse object such as:

Dim res As Net.HttpWebResponse = DirectCast(req.GetResponse, Net.HttpWebResponse)

Now declare and initialize an Image object such as:

Dim img As Image = New System.Drawing.Bitmap(res.GetResponseStream)
res.Close() 'Closes the response.

Your image is ready. Set the image to the Picture Box:

PictureBox1.Image = img
PictureBox1.Size = PictureBox1.Image.Size

The last line of code changes the size of the Picture Box to the size of the image that is set to the Picture Box.

Monday, December 1, 2008

Change the ListView column width.

Sometimes we face problems with ListView. The problem is that: suppose you have set the column width of a ListView in design time. But when the ListView is populated with data, then we see if there exists much data, all data are not showed. After some words “….” appears. This means more data exists. But we can size a column of its contents. Just write down the following code after adding an item to the ListView.

[c#]
lvTest.Columns[0].Width = -1;

[vb]
lvTest.Columns(0).Width = -1

Here lvTest is the name of the ListView. If the column width is set to -1, the column is sized to the width of the widest item in it.