Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
0

C# textbox with double value filter

Simply handle KeyPress event. Allow copy, paste, cut and backspace too.

private void txtSpadRef_KeyPress(object sender, KeyPressEventArgs e)
{
  Double isNumber = 0;
  String s = e.KeyChar.ToString();
  int[] allowedChar = new int[] {3,8,22,24 };
  foreach (int i in allowedChar) { 
    if(e.KeyChar.Equals(Convert.ToChar(i))){
      return;
    }
  }

  if (s == "." && txtSpadRef.Text.IndexOf(".") < 0)
  {
    s += "0";
  }
  e.Handled = !Double.TryParse(s, out isNumber);
}



1

XMLRPC Training (C# and PHP)

Today, I'm going to conduct a simple training on XML-RPC at my previous company.
You can access to the training materials on my googleDocs.


Presentation Slide
PHP source code
C# source code
0

.NET Licensing

I'm going to put the license component in my .Net program and considering the license for developer and run time.Microsoft already provide several licensing model in .NET such as Registry or Lic File.As for me, I'm prefer to use WMI with a propitiatory algorithm such as encryption to generate the license as I can generate an unique license key for each computer.

This how we could do that :

For Developer (Design Time) :

if (System.ComponentModel.LicenseManager.CurrentContext.UsageMode ==
System.ComponentModel.LicenseUsageMode.Designtime)
{
throw new System.Exception("Design Time License Required");
}



For run time :


if (System.ComponentModel.LicenseManager.CurrentContext.UsageMode == System.ComponentModel.LicenseUsageMode.Runtime)
{
throw new System.Exception("Run Time License Required");
}


For more details you can refer to these links :

  1. http://www.developer.com/net/net/article.php/11087_3074001_1/Applications-Licensing-using-the-NET-Framework.htm
  2. http://msdn.microsoft.com/en-us/library/fe8b1eh9.aspx
1

C# Clone Image

Aku tengah buat image processing program ada masalah masa clone image. Image yang dah asal yang dah diclone dan diproses turut menjejaskan image asal. Jadi aku cari jumpa code ni :


public static Image cloneImage(Image srcImage){
if (srcImage == null) return null;
Bitmap copy = new Bitmap(srcImage);
using (Graphics g = Graphics.FromImage(copy))
{
g.DrawImage(srcImage,new Rectangle(0, 0, srcImage.Width, srcImage.Height));
}
return copy;
}
 
Copyright © peyotest