ali raza

C#, .Net , and my thoughts

Monthly Archives: January 2008

True Jahid In Islam

atom Bomb

Sun Will Shine Again

Even though the sky seems dark, believe in the future.
The storm will pass over. The clouds will roll by.
Believe in the best though it seems hidden.
Know that it will come though it’s not in sight.

Your faith will take you through the darkness.
Your belief shall prove that the sun will shine again.

 reference : http://pravs

Saving and Restoring Form Location

A common requirement for a form is to remember its last location. Usually, this information
is stored in the registry. The code that follows shows a helper class that automatically stores
information about a form’s size and position using a key based on the name of a form.
public class FormPositionHelper
public static string RegPath = @”Software\App\”;
public static void SaveSize(System.Windows.Forms.Form frm)
// Create or retrieve a reference to a key where the settings will be stored.
RegistryKey key;
key = Registry.LocalMachine.CreateSubKey(RegPath + frm.Name);
key.SetValue(“Height”, frm.Height);
key.SetValue(“Width”, frm.Width);
key.SetValue(“Left”, frm.Left);
key.SetValue(“Top”, frm.Top);

public static void SetSize(System.Windows.Forms.Form frm)
RegistryKey key;
key = Registry.LocalMachine.OpenSubKey(RegPath + frm.Name);
if (key != null)
frm.Height = (int)key.GetValue(“Height”);
frm.Width = (int)key.GetValue(“Width”);
frm.Left = (int)key.GetValue(“Left”;
frm.Top = (int)key.GetValue(“Top”);
To use this class in a form, you call the SaveSize() method when the form is closing:

private void MyForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
and call the SetSize() method when the form is first opened:

private void MyForm_Load(object sender, System.EventArgs e)

How to fix the size of windows form at different monitor resolution

Some time developer/coder have to choose appropriate location of windows form on the screen, But limitation comes with the size and resolution of monitor. The solution is used Screen Class which gives right gives you working area of screen of monitor. Then Form load Event will look like this

private void dynamicSizeForm_Load(System.Object sender, System.EventArgse)
Screen scr = Screen.PrimaryScreen;
this.Left = (scr.WorkingArea.Width – this.Width) / 2;
this.Top = (scr.WorkingArea.Height – this.Height) / 2;
You can use above code to fix the location and size of windows form when it loads


Returns a Rectangle structure that represents the bounds
of the display area for the current screen, minus the space
taken for the taskbar and any other docked windows.

Flaws Within Us

Each of us has our own unique flaws.
It’s these flaws we have, that makes life so very interesting and rewarding. It binds our lives together.

Instead of looking for flaws; we have to accept people for what they are and look for the good in them.

Reference :


Random Number

Session vs ViewState

Session State is useful for storing values that must be persisted across
multiple pages by the same user. ViewState is useful for storing
serializable data that must be persisisted across PostBacks by a single
page. If you use Session State, the value you insert will remain in memory
until (1) The Session times out, or (2) Your code removes it. If you use
ViewState, the value you insert will remain in ViewState until the user
requests a different page.

ViewState stores data betwen PostBacks by putting it into a hidden form
field on the client HTML doc. when the doc is Posted Back, the values are
read from the hidden form field and stored in memory until the page has
finished processing. If ViewState is particularly large (and I’m talking KBs
here, not 6 bytes), it can negatively affect the speed at which the HTML doc
is downloaded by the browser.

Use the right tool for your job. I think after my explanation, it should be
obvious that you would want to use ViewState in your specific case.