How To Get Mouse Location(X,Y) In C#

I know this is very basic but i am bored so writing this .
The program we are going to make will show you the mouse cursor location, okay first of all click your form and then go to event (the lightning icon in your properties tab) and then search for MouseMove and just double click on it.
How To Get Mouse Location(X,Y) In C#
After that you will fall into the mouse_move event , go to designer and add two labels and just write down the below codes in MouseMove
label1.Text = "X : "+e.X.ToString();
            label2.Text = "Y : "+e.Y.ToString();

Now debug and try moving your mouse .

How To Add Values To ListBox In C#

Adding values to a listbox is something really easy anyways if you don't know how to add values to a listbox then here you go.

You need to add these things to your project first of all
  1. Three buttons (add,show,clear)
  2. Listbox
  3. Textbox

Inter Process Communication in C#

Introduction

Alright, so you guys might know about the famous web-browser, Google Chrome. One remarkable thing in this (pretty) simple looking application is the use of a programming technique called IPC or Interprocess Communication; with IPC you can communicate with another process without invoking and other third party events. One of the most irritating about .Net is that the app freezes if it is trying to communicate with a web-service. With IPC we can eradicate this problem.

What can you do with it?

So, lets first take an example of what exactly we can do with this: suppose that you have a licensing application named LicMan.exe and a processing app called LicPro.exe. LicMan has the UI and every other part of standard human interference. And LicPro.exe just takes the License Key provided and then processes it and sends it back to LicMan.exe for display. This way the app would not hang and you have a happy customer :-)

Lots of bad ways of doing IPC:

  • Shared Memory: Difficult to manage and set-up.
  • Shared Files / Registry: Very slow doe to the writing & reading to/from disk. Difficult to manage as well.
  • SendMessage / PostMessage: Locks up the UI thread while the message is processed. Messages are limited to integer values. Can't communicate from a non-admin process to a admin process. Assumes that your process has a window. 

The Types Of Message Boxes In C#

I am sorry guys , i have so many problems nowadays so I cannot concentrate on blogging, by the way I came through some forums posts and I really wanted to write something so today you will be learning the Types of Message Boxes in C# and the same types of Message Boxes are available in VB.NET .

What is a Message Box?
Shortly I can say Message Boxes are used to show Messages/Alerts to the user.

What are the types of Message Boxes?
The types of Message Boxes are something very important, if you want to display a message box you should know what is the type of the Message Box is going to be(ie:if you display "Cannot Convert" then that's a Error Message.
  1. Error Message Boxes.
  2. Information/Detail Message Boxes.
  3. Warning Message Boxes.
  4. Empty Message Boxes.
  5. Questioning Message Boxes.
  6. Exception Message Boxes.
Note : There are difference between Exception and Error .

Error : Error is something that stops the system from doing it or else we can say something that does not allow doing it.

Exception : Problems that occur during the run of a program or during the usage of a function or a statement.

How To Read And Write Registry In C#

We will see how to read and write registry in c# today .
For people who don't know about registry if i tell it on my own words registry is like a registrar(the person who registers marriage) it registers all the software's that you install so it's like a registrar .


How to read registry ?
Actually reading a registry key is a simple and can be done with 3-4 lines of codes.I am doing this in Graphical User Interface program yes a Windows Forms Project . Add the namespace using Microsoft.Win32; now make sure what you want to read and where you want to read(Local Machine,Current User,etc) , I have no idea what to read so i will read a Google Chrome Extension registered here Google > Chrome > Extensions > dmibjfmphcpfoacbchialfobiohmhged 
How To Read And Write Registry In C#
So as you can see the path in registry now i write 3 lines of codes to read the registry key path(the path of the extension) and show it in a Message Box .
    RegistryKey path = Registry.LocalMachine.OpenSubKey("Software\\Google\\Chrome\\Extensions\\dmibjfmphcpfoacbchialfobiohmhged");//path of the registry
            string read = (string)path.GetValue("path");//creating a string to get the value of 'path'
            MessageBox.Show(read,"Registry Key Value", MessageBoxButtons.OK,MessageBoxIcon.Information);//the messagebox pops with the key 'path' value
I am sorry i couldn't explain everything in the code , as you can see in the first line we define where our key is  "Local Machine" you can put anything places as in your registry for that by the way remember when you read or write registry you should use double // for the destination .

Now when i debug here the Message Box pops up with the 'path' value.
How To Read And Write Registry In C#
Done with reading .

How to write registry?
As it's very easy to read registry , it's easy to write registry by the way i can't write my key into the path i read because it Google's so i chose Current User path to write the registry key. As we did before (reading) add the namespace using Microsoft.Win32; now i will create a registry path and i will add a value called , my whole path is HKEY_CURRENT_USER\Software\Shim\Ultimate_programming_tutorials . ok now i will write the code to write the registry key.
RegistryKey set = Registry.CurrentUser.CreateSubKey("Software\\Shim\\Ultimate_programming_tutorials");//setting the path
            set.SetValue("website", "http://ultimateprogrammingtutorials.blogspot.com");//setting the value
            MessageBox.Show("Value has been added " + set,"Value Added",MessageBoxButtons.OK,MessageBoxIcon.Information);//creating a messagebox to show it's added(value)
            set.Close();//closing the current process
website is the name of the value we are setting and http://ultimateprogrammingtutorials.blogspot.com is the value of work :).

Now when i debug a Message Box pops up saying value has been added and the path that the value was added.
How To Read And Write Registry In C#
Now when i look the path , the value is there .
How To Read And Write Registry In C#
Done with writing :) . I hope this is very useful :)

How To Set .NET Framework Target For VB.NET and C# Projects

I heard that many people don't know how to change the .NET Framework target in their projects or they don't know why their programs don't work on others pc who don't have the .NET Framework that you use  so i wanted to write an article about changing the Framework so , i think everyone should target their .NET Framework to the older version because not everyone have the latest .NET Framework ; i always target my Framework to .NET 2.0 because most of the people have .NET Framework 2.0 . There is a small problem in changing your .NET Framework , if you use any latest libraries or maybe algorithms that are not compatible with older versions of .NET Framework then when you change the Framework Target it will show lots of error . I will come to the point now changing the .NET Framework is easy by the way i would like to say that it's better to change the .NET Framework target when you just started the project and don't think to change the .NET Framework in the middle of your project or in a finished project because there is a chance of your project getting corrupted .

How To Get HWID In C#

How To Get HWID In C#
I think some of you know that i have write a tutorial to get the HWID in vb.net , if you want to look at it you can go here . coming to the point now to get the HWID first of all it's something with your system so first go ahead and add right click your project name and select add reference then a windows will pop up now go to .NET tab and search for System.Management when you found that tick it and click ok.

How To Make A Downloader In C#

How To Make A Downloader Picture
Making your own downloader (simple download) would sound hard and maybe boring but actually it's not , it's very easy to make a downloader in c# . Today i will tell you how to write downloader in c# in the easiest way by the way this is just a simple one .

First of all create a new project then add two buttons, two text boxes, two labels & at last add a progressbar now change the properties of your tools as given below

Button1 - Text : Download
Button2 - Text : Save
Label1 - Text : Direct Link(Optional)
Label2 - Text : Save File(Optional)
Textbox1 - To Put The Download Link
Textbox2 - To Show The Save Directory

Arrange the tools to make your form look like this
Arranging Form

How To Make Typing Effect In C#

typing thingy
Everyone wants the typing effect in their about form of their program even i want :) , so i found a very good way to do that thing easily .

First of all create a new project to test this & add a label from the toolbox because we need it also add a timer to the form . Don't change change anything in the timer properties , Now let's create a String and a Static Integer .
string Type_Text = "Ultimate programming tutorials";//This is the text that's going to be typed
   static int index_Num = 0;//declaring integer index_Num 
Now on form_load event let's code some basics
            timer1.Interval = (150);//setting the timer interval since timer interval is Int i am not using "
            timer1.Enabled = true;//enabling the timer
            label1.Text = "";//setting label1 text to be empty
        }
Now at last we'll go to timer_tick event so create the event first of all and we'll do some maths (*_*)
label1.Text = Type_Text.Substring(0, index_Num) + "_";//Substring is a part of Type_Text String that we declared at the start
            index_Num++;//Doing a post fix
            if (index_Num == Type_Text.Length + 1)//An if statment with a condition of course
            {
                index_Num = 0;
                
            }
Here is the full codes
        //Author : Mohamed Shimran
        //Blog : http://ultimateprogrammingtutorials.blogspot.com

        string Type_Text = "Ultimate programming tutorials";//This is the text that's going to be typed
        static int index_Num = 0;//declaring integer index_Num 

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = (150);//setting the timer interval since timer interval is Int i am not using "
            timer1.Enabled = true;//enabling the timer
            label1.Text = "";//setting label1 text to be empty
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = Type_Text.Substring(0, index_Num) + "_";//Substring is a part of Type_Text String that we declared at the start
            index_Num++;//Doing a post fix
            if (index_Num == Type_Text.Length + 1)//An if statment with a condition of course
            {
                index_Num = 0;
                
            }
        }

Now let's debug the program and see what happens

Typing Effect - Debug

As you can see in the image it's working nicely by the way the gif is bit laggy don't mind it . I hope this really helps .

Infographic : Brief History About Programming

Here is a Brief History About Programming in a form an infographic which i found while surfing over the web pages :)

brief  Programming



Click here to view the image

How Make A PictureBox Bounce Everywhere In C#

How Make A PictureBox Bounce Everywhere In C#
Okay I think you have seen this thing in VB.NET or Visual Basic 5.0/6.0 :) so i was at my class and one of my class guy asked me how he could make a picturebox bounce everywhere in your screen so i was bulbed what i mean from bulb-ed is i got an idea , so i gave him the codes and i wanted to give you all the codes too so lets start you can use a picturebox in this program


Add a image to the picturebox and change the form property Form_BorderStyle = NONE and double and you need a timer so drag and drop one and set it's interval to 0 , now click your form and add these codes ,
        
        //Author : Mohamed Shimran
        //Blog : http://ultimateprogrammingtutorials.blogspot.com
        public Boolean top_ = true;
        public Boolean left_ = true;
        public int Speed =25;
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (top_ == true) Form1.ActiveForm.Top += Speed; else Form1.ActiveForm.Top -= Speed;
                if (left_ == true) Form1.ActiveForm.Left += Speed; else Form1.ActiveForm.Left -= Speed;

                if (Form1.ActiveForm.Top >= Screen.PrimaryScreen.Bounds.Height - 40) top_ = false;
                if (Form1.ActiveForm.Left >= Screen.PrimaryScreen.Bounds.Width - 37) left_ = false;
                if (Form1.ActiveForm.Top < -5) top_ = true;
                if (Form1.ActiveForm.Left < -5) left_ = true;
            }
            catch
            {
                timer1.Enabled = false;
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        private void Form1_Deactivate(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Hide();
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

now debug and see it in action

How To Eject And Close CD/DVD Drive In C#

How To Eject And Close CD/DVD Drive In C#
Okay guys i was doing a program about managing the system things so i had to figure out eject and closing CD/DVD Drive so i did and here is the code for this .

first of all you need to import a interop service it's

   [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]
        protected static extern int mciSendString(string lpstrCommand,
        StringBuilder lpstrReturnString,
        int uReturnLength,
        IntPtr hwndCallback);
        
after importing it add the namespace using System.Runtime.InteropServices; , then add this code to eject CD/DVD Drive

            int ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);

now to close CD/DVD Drive use this code


            int ret = mciSendString("set cdaudio door closed", null, 0, IntPtr.Zero);

Hope it helped you ..

How To Get Windows Product Key In C#

How To Get Windows Product Key In C#
I wrote a tutorial before months on how to get windows product key in vb.net. Today we are going to do the same thing in c#.

First of all add these namespaces :
using Microsoft.Win32;
using System.Collections;

After that add this function.:

How To Play A Wave Sound File In Background Mode In C#

wave file

this is gonna be a snippet and i call it a useful snippet , you just need to add a namespace and add 4 lines of codes to a event .

add this namespace :

Using System.Media;

after that you need to add these 4 lines of codes for a event (for example form_load , button_click)

SoundPlayer wave = new SoundPlayer();
            string path = "path to .WAV";
            wave.SoundLocation = path; 
            wave.Play(); 

now replace path to .WAV with the destination (for example C:/new folder/hello.wav)

i hope you enjoy this !

Drop Shadow At The Form Border In C#

shadow


i hope you guys didn't forget the same thing that i have written for VB.NET . alright like that we are now going to make the form border drop shadow that will make the form look awesome :) if your on a project that doesn't matter or create a new project to test it .

under

    public partial class Form1 : Form
    {


add these codes

 protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }

now debug and enjoy the shadow

c# shadow at form

share ! comment ! like us on facebook ! follow us on twitter !

How To Make God Mode Windows 7 In C#/VB.NET



god mode is just a folder that can be used to control anything it's really easy rather than using the windows control panel because it has all the things that a user can control :) now we are going to create that folder using c# . just put these codes in button click event or form_load event


string godmode = @"D:\god.{ED7BA470-8E54-465E-825C-99712043E01C}";
            Directory.CreateDirectory(godmode);

you need to add the using system.io; namespace to make the directory applicable . now you see when i debug the program and make the event work there will be a folder called god.{ED7BA470-8E54-465E-825C-99712043E01C} remember god is the folder name and this is the extension {ED7BA470-8E54-465E-825C-99712043E01C}

if you want to do it in vb.net use this codes

        Dim godmode As String = "D:\god.{ED7BA470-8E54-465E-825C-99712043E01C}"
        Directory.CreateDirectory(godmode)

you need to add the namespace imports system.io.

now when you debug i mean when i debug i will show you the folder created in my D drive


as you see you will also see the same folder created in the directory you have given ok now i will show inside of the god folder

you have 274 files inside : how cool


i hope you enjoy this tutorial very much .

How To Make A Hangman Game In C#

hello everyone,everyone loves game except me so i thought to make a tutorial about making a hangman game in c# and it's command line application since its simple. i guess some people dont know what is hangman ok actually what is hangman ?
it is a paper and pencil guessing game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it by suggesting letters or numbers.Wikipedia

sounds like a interesting game :) , now lets start working on start a new project a console application and you will be falling in to the coding spot and add all the codes

How To Use Advanced Encryption Standard(AES) In C#


hey everyone , i got something interesting now :) ok now what is Advanced Encryption Standard(AES)
The Advanced Encryption Standard (AES) is a specification for the encryption of electronic data established by the U.S. National Institute of Standards and Technology (NIST) in 2001.Based on the Rijndael cipher developed by two Belgian cryptographers, Joan Daemen and Vincent Rijmen, who submitted a proposal which was evaluated by the NIST during the AES selection process.-Wikipedia
ok now you know AES lets try it in visual c# . create a console application and name it :) now here is my codes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;

//Author : Mohamed Shimran
//Blog : http://www.ultimateprogrammingtutorials.blogspot.com

namespace AES
{
    class Program
    {
        static void Main(string[] args)
        {
            UTF8Encoding UTF8 = new UTF8Encoding();

            Console.WriteLine("Shims Encryption UPT");

            string text = "Ultimate programming tutorials";
            byte[] txt = UTF8.GetBytes(text);
            Console.WriteLine("Text: " + text);

            AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
            byte[] key = aes.Key;
            byte[] iv = aes.IV;
            
            byte[] n;

            ICryptoTransform ict = aes.CreateEncryptor(key, iv);

            MemoryStream ms = new MemoryStream();

            CryptoStream cs = new CryptoStream(ms, ict, CryptoStreamMode.Write);

            StreamWriter sw = new StreamWriter(cs);
            sw.Write(text);
            sw.Close();

            n = ms.ToArray();

            Console.WriteLine("Encrypted : " + Convert.ToBase64String(n));

            ICryptoTransform icrt = aes.CreateDecryptor(key, iv);

            MemoryStream mms = new MemoryStream(n);

            CryptoStream cts = new CryptoStream(mms, icrt, CryptoStreamMode.Read);

            StreamReader sr = new StreamReader(cts);

            Console.WriteLine("Decrypted : " + sr.ReadToEnd());

            sr.Close();

            aes.Clear();
            Array.Clear(key, 0, key.Length);
            Array.Clear(iv, 0, iv.Length);

            Console.Read();
        }
    }
}

now string text is your text that is going to be encrypted using the program so replace Ultimate programming tutorials and now debug the program and you will the text encrypted and the text decrypted . how awesome :)

How To Make A Simple Magnifier In C#

Today we are going to make a simple magnifier in visual c# so let's continue. If you don't know what is a magnifier?.
A screen magnifier is software that interfaces with a computer's graphical output to present enlarged screen content. It is a type of assistive technology suitable for visually impaired people with some functional vision; visually impaired people with little or no functional vision usually use a screen reader. Wikipedia
Actually we are going to make a screen magnifier not just a magnifier the word magnifier refers to a scientific instrument.


How To End Process Using C#

end process

This is a very nice tutorial and very useful in the same time and i am not going to make it so hard since you should learn the basics first ok now you need to create a new project and name the project and after creating the project you should set up the normal things you do and after that i am using a button and a text box so just go ahead and add a button and text box and change the text property of button to "end process" or whatever now when you put the process name in the text box and press the button that process will be ended .

here is the codes

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

//Author : Mohamed Shimran
//Blog : Http://www.ultimateprogrammingtutorials.blogspot.com

namespace EndProcess
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {

            Process[] ps = Process.GetProcesses();
            foreach (Process p in ps)
            {
                if (p.ProcessName.ToLower() == textBox1.Text )
                {
                    p.Kill();
                }

            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        
    }
}


enjoy and try to make it more stable since its not stable