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.

Monday, November 24, 2008

Change the manufacturer name in a .CAB file.

Few days ago I faced a problem about changing the manufacturer name in a .cab file. I solved the problem and sharing the solution with you.
To change the manufacturer name, open the .vddproj file in notepad. Find the manufacturer name there and change it. Also change the company (manufacturer) name in project Properties -> Application -> Assembly Information. After this rebuild the .cab. The manufacturer name will be changed. Now the question is how you will be sure that the manufacturer name has been changed? It is very simple. Just install the .cab in a device. After this go to RemoveProgram option of device. You will see the manufacturer name of the application. Or you can check in another way. First install the .cab in a device. Again try to install the same cab in that device. You will get a message that will warn you about the existence of that application in the device. In that message you will see the name of the manufacturer.

Saturday, November 22, 2008

Device connection problem

Sometimes it is seen that we have connected a Windows Mobile device through data cable with our pc, but the connection is not established. There may be many reasons. One of them is blockade by Firewall. Sometimes the firewall in our pc blocks the port that is being used to create connection between our pc and WM device. In this situation, we have to stop the service of the firewall to create the connection.

Friday, November 21, 2008

Set image as Form background in Windows Mobile.

In Windows Application we can set an image as a Form background easily as there exists a property of the Form named “FormBackgroundImage”. But in Windows Mobile Application Forms does not have this type of property. So, here if we want to set an image as a Form background then we can use a PictureBox Control having the same size as the Form and set an image in that PictureBox. But the problem is that after adding the PictureBox Control to the Form if we add any control dynamically to that Form, it will not be visible as the PictureBox control overlaps on it. So this technique is not good. Another technique is, we can use DrawImage method to set an image as Form background. Here we can easily add controls dynamically to the Form; the controls will remain visible.