Monday, January 31, 2011

GDI+ Introducation - C#

What is GDI+ :

This technique is the upgraded version of the GDI are used in the drawing for the making new tools, or for any purpose that needs to draw such a chart ...

Principles in the GDI +:
Create a new project Windows Forms Application, and then place a button on the form and type in the event Click:
Graphics myg = this.CreateGraphics();
Pen myp = new Pen(Brushes.Red, 2);
myg.DrawLine(myp, 0, 0, this.Width, this.Height);
myg.Dispose();
Try the code ...
The code will draw a red line of the upper-right corner of the form to the lower right corner ...

 

Sunday, January 30, 2011

Tip: Adding files to your program and extract them when need

Add executable files or other files, and then extract it from the program in one line:
 

  • Open a new project first, then add the files you want as follows:
  1. From the solution explorer window
  2. Open My project
  3. And select resources
  4. Then select the type of files and select Other
  5. Add files and then clicking on the Add existing file
  6. And select the files you want
    • When you want to retrieve files and save them on your computer You only write this line:
    My.Computer.FileSystem.WriteAllBytes(OutPutFN, My.Resources.ResourceFN, False)
    OutPutFN: a name and location of the file after extraction
    My.Resources.ResourceFN: the file that you want to extract
    False: If the file exists, do you want to overwrite it?

    What is the benefit of adding and extracting such files?

    • In terms of safety to the environment of your program, you can keep a copy of the files on which your program, and when you damage one of these files, you can restore it this way ... And this gives your program additional strength.

    Saturday, January 29, 2011

    Using Regular Expression - VB.NET

    What is Regular Expression?
    1. It is great technique to search through texts.
    2. Supported by many programming languages.
    3. It use textual formulas contain some special characters that have special meaning.

    • Imagine that you want to search for emails in a text file or search for titles in websites here comes the role of the Regular Expression optimal solution.

    The support of framework for Regular Expression:

    • Like many programming languages, the framework supports the Regular Expression through a set of classes exist in the space of names System.Text.RegularExpressions.


    Regex object is used to search through text on a certain formula Declaration for the object is like this:


    Friday, January 28, 2011

    Hanoi Towers - C#

    Here I'll show you the issue of Towers of Hanoi code .. Using a recursive way:

    namespace HanoiTowers
    {
        class Program
        {
            static void Main(string[] args)
            {
                int n;

                do{
                    Console.WriteLine("Enter number: ");
                    n = Int32.Parse(Console.ReadLine());
                }while(n<=0);

                Hanoi(n, 'A', 'B', 'C');
                Console.ReadLine();
            }

            static void Hanoi(int n, char A, char B, char C)
            {
                if (n == 1)
                    Console.WriteLine("{0} --> {1}", A, C);
                else
                {
                    Hanoi(n - 1, A, C, B);
                    Console.WriteLine("{0} --> {1}", A, C);
                    Hanoi(n - 1, B, A, C);
                }
            }
        }
    }

    This picture shows the method of work on this issue:

    Hanoi Towers

    Thursday, January 27, 2011

    How to show line numbers in Visual Studio.NET

    How to show line numbers:
    In order to show line numbers in the program Visual Studio. Net as it appears in following image:


    1. Open the Tools menu and then choose Options
    2. Then from the left side expand the node Text Editor
    3. Then choose the node All Languages
    4. Then check the Line Numbers

    Tuesday, January 25, 2011

    Killing Processes - VB.NET


    Introduction
    This article provides a simple example of how to use the System.Diagnostics.Process library to display a list of running processes, and to select and kill processes by their process name and ID.  It would not be a major trick to display additional information about the process using the same library or to kill processes by their ID or name alone rather than their name and ID but in this example, process names and IDs are used for display purposes and the purpose of killing a running process.
     
    Figure 1:  Listing and Killing Processes by Process Name and ID

    Getting Started
    There is a single solution included with this download, the solution contains a Win Forms project called “ProcessKillerVB”; this project contains one form (Form1.vb) and all of the code required to display and kill processes is contained within that single form class.  If you open the attached project into Visual Studio 2008; you should see the following in the solution explorer:

    Monday, January 24, 2011

    Handling strings in C#

    We can deal with strings as an array of characters. This means that we can access the characters of the string separately using a formula as follows:
    string m = "a world";
    char c = m[1];
    Reading the characters in this way is possible, but we can not use this method to assign characterss to any text string that is acceptable to code the following:
    m[1] = 'w';
    So that we can get a char array can write to it we use it ToCharArray () which returns a array characters represent the array codes the text string:
    string m = "a world";
    char[] c = m.ToCharArray();

    Structures in C#

    Structures:

    The second kind of the types of variables is the structure 'Struct' acronym for the word (structure)
    Represent the structure of different parts of the data can be different for each part type. It enables us to define our species of special variables, depending on the structure ...
    For example:
    Suppose we wish to save the path for the site specific from the point where this path composed of direction and distance measured in miles and simplify things we'll impose that the trend is one of the four directions of knowledge within a census orientation
    And that the mileage represented by type double
    Now we can use separate converts to represent this path as in the following code:


    orientation direction;
    double distance;

    There is nothing wrong in what we have done but it would be simpler if we used a single variable to store this information

    AJAX


    AJAX, shorthand for Asynchronous JavaScript and XML, is a web development technique for creating interactive web applications.

    AJAX meant to increase the web page’s interactivity, speed, and usability.

    If you know JavaScript, HTML, CSS and XML then you need to spend just one hour to start with AJAX.

    Ajax Acts as an Intermediary

    The Ajax engine works within the Web browser (through JavaScript and the DOM) to render the Web application and handle any requests that the customer might have of the Web server. The beauty of it is that because the Ajax engine is handling the requests, it can hold most information in the engine itself, while allowing the interaction with the application and the customer to happen asynchronously and independently of any interaction with the server.

    Asynchronous

    This is the key. In standard Web applications, the interaction between the customer and the server is synchronous.

    Top 10 reasons C# is better than VB.NET

    Let’s get practical, religion aside, with an eye on programmer productivity, here are the top 10 reasons why C# is better than VB.NET, in no particular order. If you have some other ones, let me know.

    1. In C# the line ends when I type the semicolon. The practical offshoot of this is that I write code like this
    string sql = @"SELECT *
                  FROM SomeSuchTable
                  WHERE ID=’WhatHaveYou’
                  ORDER BY ThisAndThatField ASC ";

    So when someone hands you a SQL statement you can just paste it into your code and the output (i.e. carriage returns) will still keep the format. In VB.NET, you would have to write the following to keep the formatting.

    Using Objects Instead of Enumerations

    Introduction

    Enumerations are one of many useful tools at the fingertips of developers. Most of us have been using them for years. Because they are so common and easy to use, I believe we sometimes overuse them. An enumeration at its core is merely a number value. Try this in C# and you will see how easy it is to convert between enumerations and integer values. Enumerations are useful because they are named collections of values which are associated under the surface with integer values.
    This example shows how one could quickly and easily print out the names and number values of an enumeration.

    Saturday, January 22, 2011

    Why .net is famous - Why ASP.NET ??



    Microsoft .NET (pronounced "dot net") is a software component that runs on the Windows operating system. .NET provides tools and libraries that enable developers to create Windows software much faster and easier. .NET benefits end-users by providing applications of higher capability, quality and security. The .NET Framework must be installed on a user's PC to run .NET applications.
    ASP.NET is a technology for building powerful, dynamic Web applications and is part of the .NET Framework.
    One can code ASP.NET applications in most .NET compatible languages including VB.NET, C#, and J#. ASP.NET pages, commonly known as web forms are compiled and stored on the web server for providing better performance. Web forms give you the flexibly to build powerful forms-based website pages. While building web forms based website pages you can use ASP.NET server controls to create common user interface (UI) elements and code them for accomplishing common tasks. These feature rich web controls allow you to build your web forms rapidly and make it usable as custom components.
    So many top level technicians select Microsoft platform with ASP.NET with following reasons.
    • Easy Programming Model
    ASP.NET makes building real world Web applications dramatically easier.

    C# Codes

    Create a directory if it does not exist

      if (!Directory.Exists(location))
          
      Directory.CreateDirectory(location);
       How to read the hard drive serial number

        public string GetHDDSerialNumber(string drive)

            
        if (drive == "" || drive == null)
            {
                
        drive "C";
            }  


            
        ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" drive +":\"");
            
        disk.Get();
           

            
        return disk["VolumeSerialNumber"].ToString();
        }

        Get a random number between two concrete

          Random Rnd = new Random();
          int A Rnd.Next(010); 
          Change the keyboard language to Arabic or English
            public enum Languge int{
                
            Arabic 0,
                
            English 1}

            public static 
            void SetLang(Languge Lang)
            {
                try
                {
                    
            string MyLang;
                    if (
            Lang == Languge.Arabic)
                        
            MyLang "Arabic";
                    else
                        
            MyLang "English";

                    foreach (
            InputLanguage ThisLang in InputLanguage.InstalledInputLanguages)
                        if (
            ThisLang.Culture.EnglishName.Contains(MyLang))
                            
            InputLanguage.CurrentInputLanguage ThisLang;
                }
                catch { }
            }
             
            To get the number of seconds that passed the device starts

              Int64 SecondsFromStart Environment.TickCount/1000;

              Way of sending e-mail from your porgram

                using System.ServiceProcess;  
                using System.Net.Mail;  
                using System.Text;  
                using System.Collections
                using System

                namespace MOJ {
                    class 
                Email
                    
                {
                        public 
                bool SendEmail(MailAddress FromEmailMailAddress ToEmailstring SubjectMailAddressCollection ToCCMailAddressCollection ToBCCstring Bodystring SMTPbool IsHTMLArrayList Attachments)
                        {
                            
                CheckService("smtpsvc");

                            
                MailMessage mailMsg = new MailMessage(FromEmailToEmail);
                            
                mailMsg.Subject Subject.Trim.ToString;
                            if (
                ToCC.Count != 0mailMsg.CC.Add(ToCC.ToString);
                            
                mailMsg.Bcc.Add(ToBCC.ToString);
                            
                mailMsg.IsBodyHtml IsHTML;
                            
                mailMsg.BodyEncoding Encoding.UTF8;
                            
                mailMsg.SubjectEncoding mailMsg.BodyEncoding;
                            
                mailMsg.Body Body.Trim.ToString;
                            if (
                Attachments != null)
                            {
                                
                Attachment mailAttachment;
                                foreach (
                Attachment mailAttachment in Attachments)
                                    
                mailMsg.Attachments.Add(mailAttachment);
                            }

                            
                SmtpClient client = new SmtpClient(SMTP.Trim.ToString);
                            try
                            {
                                
                client.Host "localhost";
                                
                client.Send(mailMsg);
                            }
                            catch (
                Exception ex) { throw ex; }
                            return 
                true;
                        }

                        public 
                void CheckService(string ServiceName)
                        {
                            
                //Ensure the SMTP Service is installed.
                            //Loop through all the services on the machine and find the SMTP Service.
                            
                ServiceController[] services ServiceController.GetServices;
                            
                ServiceController service null;
                            
                bool blnHasSmtpService false;
                            
                string Message "";

                            foreach (
                ServiceController service in services)
                            {
                                if (
                service.ServiceName.ToLower != ServiceName.ToLower)
                                    continue;
                                
                blnHasSmtpService true;
                                break;
                            }
                            if (!
                blnHasSmtpServiceMessage += "- There're no SMTP service on your system." Environment.NewLine;

                            if (
                service.Status != ServiceControllerStatus.Running)
                            {
                                try
                                {
                                    
                service.Start();
                                }
                                catch (
                Exception ex) { throw ex; }
                            }
                        }
                    }
                }  
                • To send an e-mail should be the SMTP service status and operated on your computer and be connected to the Internet and then can be used SendEmail () to send.

                Know the screen resolution

                  string ScrRes Screen.PrimaryScreen.Bounds.Width "X" Screen.PrimaryScreen.Bounds.Height;

                    XML - Introduction


                    XML Basics

                    • XML stands for eXtensible Markup Language.
                    • XML is designed to transport and store data.

                    • What is XML?
                    1. XML stands for EXtensible Markup Language
                    2. XML is a markup language much like HTML
                    3. XML was designed to carry data, not to display data
                    4. XML tags are not predefined. You must define your own tags
                    5. XML is designed to be self-descriptive
                    6. XML is a W3C Recommendation
                    • The Difference Between XML and HTML :
                    1. XML is not a replacement for HTML.
                    2. XML and HTML were designed with different goals:
                    3. XML was designed to transport and store data, with focus on what data is.
                    4. HTML was designed to display data, with focus on how data looks.
                    5. HTML is about displaying information, while XML is about carrying information

                    • Understanding the Vocabulary:
                    Well-formed XML:

                    Friday, January 21, 2011

                    بدء العمل بالمدونة

                    السلام عليكم
                    Peace be upon you



                    بفضل الله وعونه تم انشاء مدونة
                    المبرمج العربي دوت نت
                      والتي ستجدون من خلالها مواضيع ومقالات تخص مختلف التقنيات البرمجية وبمختلف اللغات