Tags » Csharp

Delegates, the How and the What

Delegates were introduced to me not to long ago in my C# class. Admittedly they were a bit of a struggle to wrap my head around their concept, but after spending an entire afternoon iterating through examples and studying them I am now much more confident in tackling them and using them practically. 226 more words

C#

Mono GtkSharp Application at Taskbar

using System;
using Gtk;
using Gdk;

namespace monoGTK_Test
{
    class  gtkTest : Gtk.Window
    {
        private static StatusIcon trayIcon;

        public  gtkTest() : base("monoGTK_Test")
        {
            trayIcon = new StatusIcon(new Pixbuf ("theIcon.png"));
            trayIcon.Visible = true;
            trayIcon.PopupMenu += OnTrayIconPopup;
            
            this.SetSizeRequest(300,300);
            this.ShowAll();
        }
        static void OnTrayIconPopup (object o, EventArgs args)
        {
            Menu popupMenu = new Menu();
            
            ImageMenuItem menuItemQuit = new ImageMenuItem ("QUIT");
            Gtk.Image imgmenuItemQuit = new Gtk.Image(Stock.Quit, IconSize.Menu);
            menuItemQuit.Image = imgmenuItemQuit;
            
            
            
            ImageMenuItem menuItemTIME = new ImageMenuItem ("CHK NOW!");
            Gtk.Image imgmenuItemTIME = new Gtk.Image("icon_passive.png");
            menuItemTIME.Image = imgmenuItemTIME;
            
            popupMenu.Add(menuItemQuit);

            popupMenu.Add(menuItemTIME);
            menuItemQuit.Activated += delegate { Application.Quit(); };

            menuItemTIME.Activated+= new EventHandler(menuItemTIME_Activated);
            popupMenu.ShowAll();
            popupMenu.Popup();
        }
        static void menuItemTIME_Activated(object sender, EventArgs e)
        {
            Console.WriteLine("menuItemTIME_Activated");
        }

        public static void Main()
        {
            Application.Init();
            new gtkTest();
            Application.Run();
        }

        
    }
}
… 15 more words

When to use Delegates

A delegate can be thought of as a reference to a method signature, it specifies a return type and parameter list. Here is an example using a command line app: 135 more words

Csharp

Print a sequence...

Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, ...
using System;

class PrintSequence
{
    static void Main()
    {
            Console.WriteLine(2);
            Console.WriteLine(-3);
            Console.WriteLine(4);
            Console.WriteLine(-5);
            Console.WriteLine(6);
            Console.WriteLine(-7);
            Console.WriteLine(8);
            Console.WriteLine(-9);
            Console.WriteLine(10);
            Console.WriteLine(-11);
    }
}
… 296 more words
Source Code

Magic Numbers in IF Statements

If statements like the one below have readability issues

static void Main(string[] args)
{
    int creditRating = 100;
    int typeOfPerson = 5

    if (creditRating < 200 || typeOfPerson == 5)
    {
        Foo();
    }
}

private static void Foo()
{
    Console.WriteLine("Don't lend money to this person");
}
… 251 more words

Simple Security Precaution: Take picture of person who logins to your pc on logon

  • CSharp detect logon/logout to Windows PC
  • CSharp capture picture from webcam
  • CSharp send mail attachment
  • Source: https://drive.google.com/file/d/0B5CGxG0MWhPtZ1FUTVJ4YlNyRGc/view?usp=sharing
  • Setting File Example:
    • <?xml version=”1.0″ encoding=”UTF-8″?><ROOT><SYSTEM pathForlogtext=”C:\Users\huseyin.cakir\Desktop\log.txt” pathForlogimage=”C:\Users\huseyin.cakir\Desktop\log.jpg” mailTo=”mailto@gmail.com” mailFrom=”test@gmail.com” mailFromClient=”gmailclientserver” mailFromClientPort=”587″ mailFromUser=”tester” mailSorucePassword=”password”></SYSTEM></ROOT>
  • Screenshots: