Pages

Monday, August 31, 2009

Runtime Change control Position / location C# by Praveen P.R

// Code in C#

Using Button btnSave
//Change position / location  in the form
btnSave.Location = new System.Drawing.Point(300,272);//300= X,272= Y

C# Add | Fill ComboBox with Enum values C# By Praveen P.R

// Code in C# Add | Fill ComboBox with Enum values
//Declair Enum

public enum UserLevel { Admin = 0, Client = 1, Other = 2, Agent = 3, Supplier = 4, Accounts = 5, CheckPost = 6, Manager = 7 };

//Filling combobox with Enun Values

cmbUserLevel.DataSource = Enum.GetValues(typeof(classEnum.UserLevel));

//Set initial Value

cmbUserType.SelectedItem = classEnum.UserLevel.Other;

//Getting Selected Values

 classEnum.UserTypeAtGoodsRecpt usr = (classEnum.UserTypeAtGoodsRecpt)Enum.Parse(typeof(classEnum.UserTypeAtGoodsRecpt), cmbUserType.SelectedItem.ToString());

// To get the value
int userVal=(int)usr;

Friday, August 28, 2009

Change First Letter to Capital letter C# by Praveen P.R

// Code in C#
//Change First Letter to Capital letter

public static string titleCase(string text)
  {
  string returnTiltle;
  CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; //Convert to title case
  TextInfo textInfo = cultureInfo.TextInfo; //Convert to title case
  return returnTiltle = textInfo.ToTitleCase(text.Trim());
  }

Get System Drives C# by Praveen P.R

// Code in C#

//Get System Drives
public static void getSystemDrives(ComboBox cmbBox)
  {
  DriveInfo[] allDrives = DriveInfo.GetDrives();

  foreach (DriveInfo d in allDrives)
  {
  if (d.IsReady)
  {
  cmbBox.Items.Add((object)d.Name);
  }
  }
  if (cmbBox.Items.Count > 0)
  {
  cmbBox.SelectedIndex = 0;
  }
  }

Close a Form Slowly C# by Praveen P.R

// Code in C#
//Close a form Slowly C#
  public static void closeWindowSlowly(Form currentForm)
  {
  lock (currentForm)
  {
  for (double x = 1.0d; x > 0d; x = x - 0.1d)
  {
  System.Threading.Thread.Sleep(50);
  currentForm.Opacity = x;
  currentForm.Refresh();
  }
  }
  }

Thursday, August 27, 2009

Gradient Effect to Controls C# by Praveen P.R

// Code in C#

Give gradient effect to control at Paint Event

  private void Form1_Paint(object sender, PaintEventArgs e)
  {
  System.Drawing.Drawing2D.LinearGradientBrush gradBrush;
  Point start = new Point(-100,-100);
  Point end = new Point(Form1.Width-1000, Form1.Height+1300);
  gradBrush = new
  System.Drawing.Drawing2D.LinearGradientBrush(start, end, Color.Black, Color.Honeydew );
  Graphics g = Form1.CreateGraphics();
  g.FillRectangle(gradBrush, new Rectangle(0,0,Form1.Width, Form1.Height));
  }