Cyprich.com

Occasionally Relevant Insights from a Software Builder

By

How to Update .NET Windows Controls at Runtime

If you change the value of a control on Windows .NET form during runtime, it may not be updated with the changes. The following code should change the Text property of ToolStripStatusLabel, but it doesn’t work while its processing in the middle of its function. When its the last command in the function, it will change the label."

label_Folder.Text = "Converting documents to PDF.";

If additional code follows the label_Folder statement, it may not update the Text property. You can force the property to update with the Refresh method:

label_Folder.Text = "Converting documents to PDF.";
label_Folder.Refresh ();

The label will then be updated with the new content. If your using a ToolStripStatusLabel, you don’t have the option of using Refresh this way, i.e.

toolStripStatusLabel_ProcessingStatus.Text = "Status: 12 of 19 documents processed.";
toolStripStatusLabel_ProcessingStatus.Refresh ();

Instead, use this.Refresh () to force an update:

toolStripStatusLabel_ProcessingStatus.Text = "Status: 12 of 19 documents processed.";
this.Refresh ();

By

Hello World Example in iText

iText is a .NET library for creating and manipulating PDF’s. It was originally written in Java but it was also ported to .NET. The book, “iText in Action”, has examples in Java only which will only be useful if a .NET developer knows this language.  C# examples can be found at iText.NET site. The code needs to be slightly modified for it to compile with Visual Studio 2010.

The first thing that need to change is the library references. It uses a Java style code which may have been used in an older version of iText for .NET.

using com.lowagie.text;
using com.lowagie.text.pdf;

should be written as:

using iTextSharp.text; 
using iTextSharp.text.pdf;

If you cut and paste the code from the examples to VS, you will see multiple errors. Change getInstance to GetInstance, open to Open, add to Add, close to Close. If your not sure about the function being used, delete it (include the period), type a period and the available functions will be listed.

The code will then compile correction in VS 2010. I recommend purchasing iText in Action because it will save you time in learning how to use iText. A knowledge of Java is beneficial, but not necessary to port the examples to .NET.

The following is a simple example of using iText with C#.

 

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Text;

using iTextSharp.text; 
using iTextSharp.text.pdf;

namespace Chap0101 
{ 
  class Program 
  { 
    static void Main (string [] args) 
    { 
      Console.WriteLine ("Chapter 1 example 1: Hello World");

      // step 1: creation of a document-object
      Document document = new Document ();

      // step 2: 
      // we create a writer that listens to the document 
      // and directs a PDF-stream to a file 

      PdfWriter.GetInstance (document, new FileStream ("Chap0101.pdf", FileMode.Create));

      // step 3: we open the document 
      document.Open ();

      // step 4: we add a paragraph to the document 
      document.Add (new Paragraph ("Hello World"));

      // step 5: we close the document 
      document.Close (); 
    } 
  } 
}

By

How to Bypass Activation on Palm Pre 2

HP send me a Palm Pre 2 through a developer promotion they had not too long ago, and I had a very difficult time trying to get started using it. The problem occurs when the phone starts for the first time and you need to create an account on it with HP. I couldn’t connect to the internet with this unlocked phone. I contacted Fido (my cell phone provider) and also Rogers (they own Fido) and neither was able to get the phone connected to their network. This cost me $35 at Best Buy in purchasing a SIM card for Rogers.

I gave up for a while and then resumed my search for a solution later. This is one very effective method of solving problems: put it aside for some time and come back to it again with a fresh perspective. I’ve solved many IT related issues this way.

I found a post from unwiredben on the Palm developer forum who gave instructions on how to bypass the activation screen. On the first use of the phone, press the “make emergency call” button and erase the 911 number already there. Then type the keys that correspond to #*DEVMODE# (for GSM networks like Fido/Rogers) or ##DEVMODE# (for CDMA networks).

The phone will then function normally on your network.

By

3 Important Tools for Developing in JavaScript

JavaScript has become a language that every web developer must be deeply familiar with to build web applications, and it will even be heavily used in creating client applications for the upcoming Windows 8 operating system from Microsoft. The following sites will help you produce better, error-free JavaScript which is important if you want to maintain customer confidence over your products.

  1. JSFIDDLE (http://jsfiddle.net/)
    This site can be considered a sandbox for JavaScript. You can write code in HTML, CSS, and of course, JavaScript and run, test, and tidy up the code with automated tools.
  2. JSHINT (http://jshint.org/)
    Debugging tool for JavaScript and enforcing coding conventions. More powerful that JSLINT.
  3. JSONLint (http://www.jslint.com/)
    Specialized tool for validating JSON.