Archive for Aprile 2nd, 2008

Creating a single instance application per machine.

CodeKeep C# Feed Aprile 2nd, 2008

Description: Here is code for creating an application that is restricted to a single instance on a machine.

Link: http://www.codekeep.net/snippets/4398653b-9816-41b4-b1c5-3e3d64592167.aspx

using System;
using System.Reflection;
using System.Threading;

namespace SingleInstanceApplication
{
	class Program
	{
		static void Main(string[] args)
		{
			bool firstApplicationInstance;

			string mutexName = Assembly.GetEntryAssembly().FullName;

			using (Mutex mutex = new Mutex(false, mutexName, out firstApplicationInstance))
			{

				if (!firstApplicationInstance)
				{
					Console.WriteLine("This application is already running.");
					Console.WriteLine("[ENTER]");
					Console.ReadLine();
				}
				else
				{
					Console.WriteLine("Do something interesting.");
					Console.WriteLine("[ENTER]");
					Console.ReadLine();
				}
			}
		}
	}
}

Joomla Templates: Creating a Pure CSS Template

WebReference News Aprile 2nd, 2008

This week you'll learn how to create a Joomla template that uses Cascading Style Sheets (CSS) to produce a layout. This makes the template code easier to validate. It also tends to load faster and is easier to maintain.`By Barrie North. 0211

Software Review: A1 Sitemap Generator

WebReference News Aprile 2nd, 2008

Sitemaps (used for mapping your site), are now being used by search engines to index Web sites, which can improve your site's listings. To quickly generate a sitemap, you need a script or a program. One of these is the A1 Sitemap Generator, the subject of this review. By Lee Underwood. 0213

Joomla Templates: Creating a Pure CSS Template - Part 2

WebReference News Aprile 2nd, 2008

This week we delve deeper into CSS with Joomla. We cover templateDetails.xml, index.php, creating a blank Joomla template body, using CSS to create a tableless layout, CSS shorthand, Joomla specific CSS and more. By Barrie North. 0218

Metrics with Email Marketing Software

WebReference News Aprile 2nd, 2008

With the right email marketing application, the days of blindly conducting marketing are a thing of the past. In this article you'll learn about several key methods of using the reports from your email marketing application to boost your results. By Robert Burko. 0220

center align every form

CodeKeep C# Feed Aprile 2nd, 2008

Description: Make Every form center aligned according to the display resolution

Link: http://www.codekeep.net/snippets/de4a42bc-8268-4084-ae6d-d9e539fd9642.aspx

//Get the Width and Height (resolution) of the screen
System.Windows.Forms.Screen src = System.Windows.Forms.Screen.PrimaryScreen;

int src_height = src.Bounds.Height;
int src_width = src.Bounds.Width;

//put the form in the center
this.Left = (src_width - this.Width) / 2;
this.Top = (src_height - this.Height) / 2;

Allowing Only One Instance of an Application

CodeKeep C# Feed Aprile 2nd, 2008

Description: Allowing Only One Instance of an Application to run at one time

Link: http://www.codekeep.net/snippets/6962e829-e964-4a57-af04-5f1f049f649e.aspx

    // Detect existing instances
    string processName = Process.GetCurrentProcess().ProcessName;
    Process[] instances = Process.GetProcessesByName(processName);

    if (instances.Length > 1)
    {
        MessageBox.Show("This application is already running.");
        return;
    }
    // End of detection

Chain

CodeKeep C# Feed Aprile 2nd, 2008

Description: Useful little class for creating IEnumerables in tests etc, Chain is an immutable list supporting IEnumerable

Link: http://www.codekeep.net/snippets/6a941ef6-88ff-4903-b0fd-7ca261ef3bd3.aspx

    public class Chain<T> : IEnumerable<T>, IEnumerable
    {
        private static readonly Chain<T> empty = new Chain<T>(default(T), null);
        public static Chain<T> Empty
        {
            get { return empty; }
        }

        public static Chain<T> From(T t)
        {
            return Empty.Append(t);
        }

        public static Chain<T> From(IEnumerable<T> _Items)
        {
            return Empty.Append(_Items);
        }

        public static Chain<T> From(params T[] items)
        {
            return Empty.Append(items);
        }

        private readonly T item;
        private readonly Chain<T> next;

        private IEnumerable<T> GetItemsRecursive()
        {
            if (next != null) {
                foreach (T child in next.GetItemsRecursive()) yield return child;
                yield return item;
            }
        }

        public Chain<T> Append(T t)
        {
            return new Chain<T>(t, this);
        }

        public Chain<T> Append(IEnumerable<T> _Items)
        {
            if (_Items == null) throw new ArgumentNullException("Items");
            Chain<T> current = this;
            foreach (T cur in _Items) {
                current = current.Append(current);
            }
            return current;
        }

        public Chain<T> Append(params T[] items)
        {
            return Append((IEnumerable<T>) items);
        }

        private Chain(T _Item, Chain<T> _Next)
        {
            item = _Item;
            next = _Next;
        }

        public IEnumerator<T> GetEnumerator()
        {
            return GetItemsRecursive().GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetItemsRecursive().GetEnumerator();
        }
    }

Interface example

CodeKeep C# Feed Aprile 2nd, 2008

Description: Interfaces are designed to manage messaging between objects. When I learned that concept, it made applying them much easier and logical. Somehow, that syntax was the first explaination that really clicked for me.

Link: http://www.codekeep.net/snippets/dc6ce91b-8380-473f-8ad2-a9e990c23150.aspx

Examples:

interface IPlural
{
  void Load();
  void Load(ELoadOptions option, int id);
}

interface IMembership
{
  void Save();
  void Delete();
  void Load(int id);
}

Reset RichTextBox selection after updates.

CodeKeep C# Feed Aprile 2nd, 2008

Description: After you finish modifying text within a RichTextBox control, you may want to move the cursor to the top of the control.

Link: http://www.codekeep.net/snippets/5766ef42-6439-4ccc-83e4-cad379460fca.aspx

richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 0;

Next »