Skip to main content

Posts

Featured Post

How to create customizable products in Shopify for Free (No coding!)

Creating customizable products in your Shopify store not only increase your customer satisfaction, it also increases your conversion rate.  Here is a method to add custom options for your Shopify product and convert it into personalized product - Go to Shopify store page and search for "Advanced Product Customizer" app or you can directly the the Shopify app page by clicking on this link Advanced Product Customizer . Install  Advanced Product Customizer  app for free in your Shopify store  From the application dashboard, enable to app embed block to complete the installation process Click "Product Custom Options"  From the Shopify products list, select the product on which you want to add custom options. Advanced Product Customizer  offers Image Swatch, Color Swatch, Text box, File Upload, Radio, Checkbox, Date Picker and more. Here is the a demo video for adding custom option for a Shopify product -

Image Resizer using C#.NET Windows Application

Code to Resize Image (with Sample Application) In this post I am sharing the code to resize an image using C#.NET. Also sharing the code to preview and save resized image in multiple formats (jpeg, bmp, png, gif, tiff). Code to Resize Image for given width and height public static Bitmap ResizeImage(Image image, int width, int height) { var destRect = new Rectangle(0, 0, width, height); var destImage = new Bitmap(width, height); destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); using ( var graphics = Graphics.FromImage(destImage)) { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; ...

Draw transparent Label on PictureBox C#.NET

Label control supports transparent property but picture box do not work as container control. So even if we add label control on picturebox the parent control will become main form or any other underlying container control. Hence on adding label control on picture box and making label control background  transparent shows background of form or any other container control is rather than picture box. This can be changed using simple code in form constructor. We need to change parent property of label and recalculate its location because it is now relative to picturebox instead of form. Hetre is the sample code to do this -  public Form1() {         InitializeComponent();         var pos = this.PointToScreen(label1.Location);         pos = pictureBox1.PointToClient(pos);         label1.Parent = pictureBox1;         label1.Location = pos;         labe...

Recursively delete files from Directory C#.NET

Recursively delete files from given directory keeping the directory structure intact C#.NET To get all the files present in the subdirectories of the given directory, use "SearchOption.AllDirectories" DirectoryInfo  DirInfo   =  new   DirectoryInfo ( directoryPath ); DirInfo . GetFiles   ( "*" ,  SearchOption . AllDirectories   ). ToList (). ForEach ( file   => file . Delete ()); The above code will delete all the files for the given directory while keeping the structure of directory intact. To send files in recycle bin instead of deleting it from system use "FileSystem.DeleteFile" function of VisualBasic assembly. Add reference to VisualBasic dll and add "using Microsoft.VisualBasic.FileIO" DirInfo   =   new   DirectoryInfo (   directoryPath   ); List < FileInfo >  fileList   =   DirInfo . GetFiles ( "*" ,   SearchOption . AllDirectories ). ToList (); foreach ...

Split list into sublists using LINQ in C#.NET

Here is the sample LINQ C# code to split list into sublists public   static   List < List <T>> Split < T >(   this   List   <T>  source ,  int   NumberOfGroup   )         {              return   source                 . Select (( x   ,  i )=> new   {  Index   =  i ,  Value   =  x   })                 . GroupBy ( x   =>  x . Index   /  NumberOfGroup   )                 . Select ( x   =>  x . Select   ( v   =>  v . Value ). ToList ())        ...

Capture or Detect mouse click on or outside Windows Form using C#.NET

Sometimes in case of Windows form application where we have multiple windows opened and we need to find on which window user has clicked. One method to find this is to capture the mouse click message.  Here is the sample code to close form if mouse click happen outside the form.    public   partial   class   frmTest  :   Form     {           class   Window CaptureChanged   :   NativeWindow         {               public   CaptureChanged   OnCaptureChanged ;               protected   override   void   WndProc ( ref   Message   m )             {             ...

Running parallel tasks using ThreadPool.QueueUserWorkItem Method in .NET 3.5

Sometimes we need to run tasks in parallel so that performance of any application can be improved. Here is the sample function to run task in parallel using ThreadPool.QueueUserWorkItem. These parallel task will be added to Queue and as soon as thread is available in thread pool task will be executed. So number of tasks running in parallel depends upon the number of threads available in threadpool. So, in case if system have multiple processors then more threads will be available in threadpool and more tasks can run in parallel. C# Function to run tasks in parallel -             ///   <summary>          ///   Function to  Executes a set of methods or tasks in parallel. The results          ///   from each task or method in an array will be returned when all threads           ///    h...