Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, February 3, 2012

ASP.NET AJAX UpdateProgress Control

In head Section

<script language="javascript" type="text/javascript">

   var prm = Sys.WebForms.PageRequestManager.getInstance();
   prm.add_initializeRequest(InitializeRequest);
   prm.add_endRequest(EndRequest);
   var postBackElement;
   function InitializeRequest(sender, args)
   {

      if (prm.get_isInAsyncPostBack())
         args.set_cancel(true);
      postBackElement = args.get_postBackElement();
      if (postBackElement.id == 'Button1')
         $get('UpdateProgress1').style.display = 'block';
   }
 
   function EndRequest(sender, args)
   {
       if (postBackElement.id == 'Button1')
          $get('UpdateProgress1').style.display = 'none';
   }

</script>

 In Body Section

<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;
    </div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Width="145px"></asp:Label>
            </ContentTemplate>
         <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click"/>
        </Triggers>
        </asp:UpdatePanel>
       <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="0" AssociatedUpdatePanelID="UpdatePanel1">
            <ProgressTemplate>
                <script type="text/javascript">document.write("<div class='UpdateProgressBackground'></div>");</script>
                <center><div class="UpdateProgressContent">Loading...</div></center>
            </ProgressTemplate>
        </asp:UpdateProgress>

        <br />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    </form>
</body>

Friday, December 3, 2010

C# and the Web: Writing a Web Client Application with Managed Code in the Microsoft .NET Framework

What is a Web Client?

      As you know, accessing data from the Internet can be accomplished in several ways. Browsers are one type of Web client that enable you to send requests to a particular Uniform Resource Identifier (URI) and receive the response in a standard format. Browsers are great Web clients for human-readable content; they display the results in HTML format allowing you to read the text and see the images. Performing more advanced tasks such as extracting a stock price from a Web page can be pretty difficult and techniques such as page scraping aren't trivial to implement. So how can applications connect to other applications via the Web?
      The answer to that is the XMLHttpRequest object, which is another kind of Web client. Using this object you can send and receive information to and from a Web resource in various formats, as shown in the following code:
var httpOb = new ActiveXObject("Microsoft.XMLHTTP");

httpOb.Open("POST","http://uddi.microsoft.com/inquire", false);
httpOb.send(MySOAPMessage);
var Ans = httpOb.GetResponseXML();
      The .NET Framework has a request/response model for accessing data from the Internet. Applications that use the request/response model can request data from the Internet in a protocol-agnostic manner—the application works with instances of a Web client (the WebRequest and WebResponse classes), while the details of the request are carried out by protocol-specific descendant classes. The .NET Framework provides a rich class structure for enabling the request/response model. The base classes for that are WebRequest and WebResponse. In my Web client, their descendants—the HTTPWebRequest and HTTPWebResponse classes—play a major role.

A Managed Web Client is Born

      The .NET Framework provides all the goodies you need to have full Web client functionality in the world of managed code, but it doesn't provide a full-featured client that can be reused in your projects, like the XMLHttpRequest object. I decided to wrap some managed classes and create a new managed class with identical behavior to the unmanaged XMLHttpRequest object. It turned out to be easier than I thought.
      In order to write the managed Web client, it's important to understand the common language runtime (CLR) and how to program against it. In addition, understanding the Unified Class Library (UCL) structure is even more important in my case so that I'm able to select the right class for the right job. I won't bore you with the technical details about the structure of the CLR and the exact implementation of the garbage collection, and I won't go through every class of the base classes and explain its interface. Instead I will explain only those classes that are relevant to my implementation of the Web client.
      Take a look at the .NET Framework structure in Figure 1. It provides a schematic overview of the UCL namespace structure. The base classes actually expose the operating system services. For example, the System.IO library enables services such as file streaming, reading, and writing, and the Net library allows you to handle Web requests, Web responses, sockets, and more. On top of it there are the System.Web services which are used to create Web Forms and Web Services, and the System.WindowsForms services which are used to create Windows®-based applications. My application will make extensive use of the System.Net and System.IO libraries for the XMLHttpRequest class.

Figure 1 The Unified Class Library Structure
Figure 1 The Unified Class Library Structure

      The first task is to create a WebRequest object for a specific network request schema—in my case, HTTP. In order to do that I'll use the System.Net.WebRequest class's CreateDefault method. However, instead of using the returned WebRequest object, I'll typecast it to the HttpWebRequest class, which is actually the HTTP-specific implementation of the WebRequest object.

http://msdn.microsoft.com/hi-in/magazine/cc301587%28en-us%29.aspx

Exception Handling in C#

Painful Procedural Error Handling

In the absence of exceptions the classic way to handle errors is to intertwine your statements with error checks. For example:
public sealed class Painful
{  
    ...  
    private static char[] ReadSource(string filename)
    {
        FileInfo file = new FileInfo(filename);
        if (errorCode == 2342) goto handler;
        int length = (int)file.Length;  
        char[] source = new char[length];
        if (errorCode == -734) goto handler;
        TextReader reader = file.OpenText();
        if (errorCode == 2664) goto handler;
        reader.Read(source, 0, length);
        if (errorCode == -5227) goto handler;
        reader.Close();
        Process(filename, source); 
        return source;

        handler:
        ...
    }
}
This style of programming is tedious, repetitive, awkward, complex, and obscures the essential functionality. And it's too easy to ignore errors (either deliberately or accidentally). There have to be better ways. And there are. But some are better than others.

Separation of Concerns

The fundamental thing that exceptions allow you to do is to separate the essential functionality from the error handling. In other words, we can rewrite the mess above like this:
...
public sealed class PainLess
{    
    public static int Main(string[] args)
    {
        try
        {
           string filename = args[0];
           char[] source = ReadSource(filename);
           Process(filename, source);
           return 0;
        }
        catch (SecurityException    caught) { ... }
        catch (IOException          caught) { ... }
        catch (OutOfMemoryException caught) { ... }
        ...
    }

    private static char[] ReadSource(string filename)
    {
        FileInfo file = new FileInfo(filename);
        int length = (int)file.Length;
        char[] source = new char[length];
        TextReader reader = file.OpenText();
        reader.Read(source, 0, length);
        reader.Close();
        return source;
    }
}
There are several things to notice about this transformation.
  • The numeric integer error codes that utterly failed to describe the errors they represented (e.g. what does 2342 mean?) are now descriptively named exception classes (e.g. SecurityException).
  • The exception classes are not tightly coupled to each other. In contrast, each integer code must hold a unique value thus coupling all the error codes together.
  • There is no throw specification on ReadSource. C# does not have throw specifications.
However, by far and away the most important thing to notice is how much cleaner, simpler and easier to understand ReadSource has become. It now contains only the statements required to implement its essential functionality. It makes no apparent concession to error handling. This is possible because if an exception occurs the call stack will unwind all by itself. This version of ReadSource is the "ideal" we are aiming it. It is as direct as we can make it.
Ironically, exceptions allow us to get close to this ideal version of ReadSource but at the same time prevent us from quite reaching it. ReadSource is an example of code that acquires a resource (a TextReader), uses the resource (Read), and then releases the resource (Close). The problem is that if an exception occurs after acquiring the resource but before releasing it then the release will not take place. The solution has become part of the context. Nevertheless, this "ideal" version of ReadSource is useful; we can compare forthcoming versions of ReadSource to it as a crude estimate of their "idealness".

finally?

The solution to this lost release problem depends on the language you're using. In C++ you can release the resource in the destructor of an object held on the stack (the misnamed Resource Acquisition Is Initialization idiom). In Java you can use a finally block. C# allows you to create user-defined struct types that live on the stack but does not allow struct destructors. (This is because a C# destructor is really a Finalize method in disguise and Finalize is called by the garbage collector. Structs, being value types, are never subject to garbage collection.) Therefore, initially at least, C# must follow the Java route and use a finally block. A first cut implementation using a finally block might look like this:
private static char[] ReadSource(string filename)
{
    try
    {
        FileInfo file = new FileInfo(filename);
        int length = (int)file.Length;
        char[] source = new char[length];
        TextReader reader = file.OpenText();
        reader.Read(source, 0, length);
    }
    finally
    {
        reader.Close();
    }
    return source;
}
This version has had to introduce a try block (since a finally block must follow a try block) which isn't in the ideal solution but apart from that it's the same as the "ideal" version of ReadSource. It would be a reasonable solution if it worked. But it doesn't. The problem is that the try block forms a scope so reader is not in scope inside the finally block and source is not in scope at the return statement.

finally?

To solve this problem you have to move the declarations of reader and source outside the try block. A second attempt might be:
private static char[] ReadSource(string filename)
{
    TextReader reader;
    char[] source;
    try
    {
        FileInfo file = new FileInfo(filename);
        int length = (int)file.Length;
        source = new char[length];
        reader = file.OpenText();
        reader.Read(source, 0, length);
    }
    finally
    {
        reader.Close();
    }
    return source;
}
This version has moved the declaration of reader and source out of the try block and consequently assigns to reader and source rather than initializing them. That's another difference (and two extra lines) from the "ideal" version of ReadSource. Nevertheless, you might consider it a reasonable solution if it worked. But it doesn't. The problem is that assignment is not the same as initialization and the compiler knows it. If an exception is thrown before reader is assigned then the call to reader.Close() in the finally block will be on reader which won't be assigned. C#, like Java, doesn't allow that.

finally?

Clearly you have to initialize reader. A third attempt therefore might be:
private static char[] ReadSource(string filename)
{
    TextReader reader = null;
    char[] source;
    try
    {
        FileInfo file = new FileInfo(filename);
        int length = (int)file.Length;
        source = new char[length];
        reader = file.OpenText();
        reader.Read(source, 0, length);
    }
    finally
    {
        reader.Close();
    }
    return source;
}
This version introduces null which isn't in the "ideal" version of ReadSource. Nevertheless, you might still consider it a reasonable solution if it worked. But it doesn't (although it does compile). The problem is the call to reader.Close() could easily throw a NullReferenceException.

finally?

One way to solve this problem is to guard the call to reader.Close(). A fourth attempt therefore might be:
private static char[] ReadSource(string filename)
{
    TextReader reader = null;
    char[] source;
    try
    {
        FileInfo file = new FileInfo(filename);
        int length = (int)file.Length;
        source = new char[length];
        reader = file.OpenText();
        reader.Read(source, 0, length);
    }
    finally
    {
        if (reader != null)
        {
            reader.Close();
        }
    }
    return source;
}
Of course, the guard on reader.Close() isn't in the "ideal" version of ReadSource. But this is a reasonable version if only because it does, finally, work. It's quite different from the "ideal" version but with a bit of effort you can refactor it to this:
private static char[] ReadSource(string filename)
{
    FileInfo file = new FileInfo(filename);
    int length = (int)file.Length;
    char[] source = new char[length];
    TextReader reader = file.OpenText();
    try
    {
        reader.Read(source, 0, length);
    }
    finally
    {
        if (reader != null)
        {
            reader.Close();
        }
    }
    return source;
}
In some cases you might be able to drop the null guard inside the finally block (you can in the above case) but in general this is the best you can do with a finally block solution. (Consider if file.OpenText returned null, or if reader was assigned to inside the try block, or reader was passed as a ref/out argument inside the try block.) You have to add a try block, a finally block, and an if guard. And if you are using Java you have to do those three things every time. And therein is the biggest problem. If this solution was truly horrible and completely and utterly different to the ideal solution it wouldn't matter a jot if we could abstract it all away. But in Java you can't. The Java road stops here, but the C# road continues.

using Statements

In C#, the nearest you can get to the "ideal" version is this:
private static char[] ReadSource(string filename)
{
    FileInfo file = new FileInfo(filename);
    int length = (int)file.Length;
    char[] source = new char[length];
    using (TextReader reader = file.OpenText())
    {
        reader.Read(source, 0, length);
    }
    return source;
}
This is pretty close. And as I'll explain shortly it has a number of features that improve on the "ideal" version. But first let's look under the lid to see how it actually works.

using Statement Translation

The C# ECMA specification states that a using statement:
using (type variable = initialization)
    embeddedStatement
is exactly equivalent to:
{
    type variable = initialization;
    try
    {
        embeddedStatement
    }
    finally
    {
        if (variable != null) 
        {
            ((IDisposable)variable).Dispose();
        }
    }
}
This relies on the IDisposable interface from the System namespace:
namespace System
{
    public interface IDisposable
    {
        void Dispose();
    }
}
Note that the cast inside the finally block implies that variable must be of a type that supports the IDisposable interface (either via inheritance or conversion operator). If it doesn't you'll get a compile time error.

using TextReader Translation

Not surprisingly, TextReader supports the Disposable interface and implements Dispose to call Close. This means that this:
using (TextReader reader = file.OpenText())
{
    reader.Read(source, 0, length);
}
is translated, under the hood, into this:
{
    TextReader reader = file.OpenText();
    try
    {
        reader.Read(source, 0, length);
    }
    finally
    {
        if (reader != null)
        {
            ((IDisposable)reader).Dispose();
        }
    }
}
Apart from the cast to IDisposable this is identical to the best general Java solution. The cast is required because this is a general solution.

Do It Yourself?

It's instructive to consider what would happen if TextReader didn't implement the IDisposable interface. The lessons from this will show us how to implement Disposability in our own classes. One solution is the Object Adapter pattern. For example:
public sealed class AutoTextReader : IDisposable
{
    public AutoTextReader(TextReader target)
    {
        // PreCondition(target != null);
        adaptee = target;
    }

    public TextReader TextReader
    {
        get { return adaptee; }
    }

    public void Dispose()
    { 
        adaptee.Close();
    }

    private readonly TextReader adaptee; 
}
which you would use like this:
using (AutoTextReader scoped = new AutoTextReader(file.OpenText()))
{
    scoped.TextReader.Read(source, 0, length);
}
To make things a little easier you can create an implicit conversion operator:
public sealed class AutoTextReader : IDisposable
{
    ...
    public static implicit operator AutoTextReader(TextReader target)
    {
        return new AutoTextReader(target);
    }
    ...
}
which would allow you to write this:
using (AutoTextReader scoped = file.OpenText())
{
    scoped.TextReader.Read(source, 0, length);
}

struct Alternative

AutoTextReader is a sealed class intended, as its name suggests, to be used as a local variable. It makes sense to implement it as a struct instead of class:
public struct AutoTextReader : IDisposable
{
    // exactly as before
}
Using a struct instead of a class also gives you a couple of free optimizations. Since a struct is a value type it can never be null. This means the compiler must omit the null guard from generated finally block. Also, since you cannot derive from a struct its runtime type is always the same as its compile time type. This means the compiler can usually omit the cast to IDisposable from the generated finally block and thus avoid a boxing operation. (specifically, it can avoid the cast if Dispose is a public Implicit Interface Implementation rather than a non-public Explicit Interface Implementation). In other words, this:
using (AutoTextReader scoped = file.OpenText())
{
    scoped.TextReader.Read(source, 0, length);
}
is translated into this:
{
    AutoTextReader scoped = new file.OpenText();
    try
    {
        scoped.TextReader.Read(source, 0, length);
    }
    finally
    {
        scoped.Dispose();
    }
}
It should come as no surprise that I prefer the using statement solution to the finally block solution. In fact, the using statement solution scores several extra points in comparison to the "ideal" solution. A using statement:
  • Works! It always releases the resource.
  • Is an extensible mechanism. It allows you to create an abstraction of resource release. Creating your own resource releaser types such as AutoTextReader is easy.
  • Allows you to pair up the resource acquisition with the resource release. The best moment to organize the resource release is the moment you acquire the resource. If you borrow a book from a library you're told when to return it as you borrow it.
  • Says explicitly, in syntax, that you are using a resource.
  • Creates a scope for the variable holding the resource. Look carefully at the compiler translation of a using statement and you'll see that it cleverly includes a pair of outer braces:
    using (AutoTextReader scoped = file.OpenText())
    {
        scoped.TextReader.Read(source, 0, length);
    }
    scoped.TextReader.Close(); // scoped is not in scope here
    This is reminiscent of C++ declarations in conditions. Both allow you to restrict the scope of a variable so it's only usable when in scope and is only in scope when usable.

Friday, September 10, 2010

Different type of Exception code

//C#: Exception Handling
using System;
class MyClient
{
 public static void Main()
 {
  int x = 0;
  int div = 0;
 try
 {
  div = 100/x;
  Console.WriteLine(“This line in not executed”);
 }
 catch(DivideByZeroException de)
 {
  Console.WriteLine("Exception occured");
 }
 Console.WriteLine("Result is {0}",div);
 }
} 
//C#: Exception Handling
using System;
class MyClient
{
 public static void Main()
 {
  int x = 0;
  int div = 0;
 try
 {
  div = 100/x;
  Console.WriteLine(div);
 }
 catch(DivideByZeroException de)
 {
  Console.WriteLine ("Exception occured");
 }
 finally
 {
  Console.WriteLine("Finally Block");
 }
 Console.WriteLine("the Result is {0}";
}  
 
//This for File not found 
try
{
}
catch(IOException ex)
{
if(ex is FileNotFoundException)
   
}

// This for IO exception
catch(FileNotFoundException ex)
{
}
catch(IOException ex)
{
}

// This for DividebyZero exception
Try
{
}
catch(DivideByZeroException ex)
{
}

// This for SQL exception
Try
{
}
catch(SqlException ex)
{
} 

How To Replace String?

Use string To replace :</b>

private void button1_Click(object sender, EventArgs e)
{
     string oldstr = "Hu MAJAMA Chu?";
     string newstr=oldstr.Replace("chu","Tu");
     MessageBox.Show(newstr);
}

<b>

Tuesday, July 27, 2010

Interface

In object-oriented languages the term "interface" is often used to define an abstract type that contains no data but exposes behaviors defined as methods. A class  having all the methods corresponding to that interface is said to implement that interface. Furthermore, a class can implement multiple interfaces, and hence can be of different types at the same time.

An interface is hence a type definition; anywhere an object can be exchanged (in a function or method call) the type of the object to be exchanged can be defined in terms of an interface instead of a specific class. This allows later code to use the same function exchanging different object types; hence such code turns out to be more generic and reusable.

Usually a method in an interface cannot be used directly; there must be a class implementing that object to be used for the method invocation. For example, one can define an interface called "Stack" that has two methods: push() and pop() and later implement it in two different versions, say, FastStack and GenericStack—the first being faster but working with a stack of fixed size, and the second using a data structure that can be resized but at the cost of somewhat lower speed.

This approach can be pushed to the limit of defining interfaces with a single method; e.g. the Java language defines the interface Readable that has the single read() method and a collection of implementations to be used for different purposes, among others: BufferedReader, FileReader, InputStreamReader, PipedReader, and StringReader.
In its purest form, an interface (like in Java) must include only method definitions and constant values that make up part of the static interface of a type. Some languages (like C#) also permit the definition to include properties owned by the object, which are treated as methods with syntactic suga

Use of lambda operator => "Goes To"

delegate bool D();
    delegate bool D2(int i);

    class Test
    {
        D del;
        D2 del2;
        public void TestMethod(int input)
        {
            int j = 0;
            // Initialize the delegates with lambda expressions.
            // Note access to 2 outer variables.
            // del will be invoked within this method.
            del = () => { j = 10;  return j > input; };

            // del2 will be invoked after TestMethod goes out of scope.
            del2 = (x) => {return x == j; };
            
            // Demonstrate value of j:
            // Output: j = 0 
            // The delegate has not been invoked yet.
            Console.WriteLine("j = {0}", j);

            // Invoke the delegate.
            bool boolResult = del();

            // Output: j = 10 b = True
            Console.WriteLine("j = {0}. b = {1}", j, boolResult);
        }

        static void Main()
        {
            Test test = new Test();
            test.TestMethod(5);

            // Prove that del2 still has a copy of
            // local variable j from TestMethod.
            bool result = test.del2(10);

            // Output: True
            Console.WriteLine(result);
            
            Console.ReadKey();
        }
    }

Generating Alphanumeric Unique series

function randomPrefix($length)
{
$random= "";
srand((double)microtime()*1000000);
$data = "AbcDE123IJKLMN67QRSTUVWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";
for($i = 0; $i < $length; $i++)
{
$random .= substr($data, (rand()%(strlen($data))), 1);
}
return $random;
}
randomPrefix(10);

Monday, March 29, 2010

C# Language

1. Implicit Typed Local Variables


Declaring variable without specifying data-type.
E.g. var count = 1 ; instead of int count = 1;
E.g. var str = "Hello World"; instead of string str = "Hello World";
- var is not like an object or a variant type that has expensive cost.

- The compiler will set the data-type depending on what you initialize the variable.

Usage of Type Inference


- You can use it When deal with Anonymous type in LINQ.
- Declaration must include an initializer.
e.g. var test = "Hello World";

- Initializer must be an expression and not an object or collection initializer and also can not initialize it with an array.
e.g. var test = {1,2,3} ; //Gives error

- Compile time type of the initialzer expression can not be the null type.
e.g. var test = null;

- Implicity typed local variable can be initialize more than once but not with different type.
e.g. var test = 1;
test = "Hello World";

Benefits of Type Inference


- Save the typing time.
- It induces/brings on variable initialization

Limitations


- Scope is limited to local variable

2. Auto Implemented Properties


A way to declare property without code block in property accessors.

Usage of Auto Implemented Properties


- We can use it in data-accessor classes.

Note: VB 9.0 does not have auto implemented properties feature while C# 3.0 have.

- It makes property declaration more concise when there is no custom logic required in property accessors.

For example,
Suppose we have to create a class Employee with private attributes First-Name, Last-Name and ID. Now in order to access its attributes values either we can create properties or functions for each attribute.

In C# 2.0, we implement Employee class with above requirements as follows

 
public class Employee
{
 int _id;
 string _firstName;
 string _lastName;
 public int ID
 {
  get
  {
   return _id;
  } 
  set
  {
   _id = value;
  }
 }
public string FirstName
 {
  get
  {
   return _firstName;
  } 
  set
  {
   _firstName = value;
  }
 }
public string LastName
 {
  get
  {
   return _lastName;
  } 
  set
  {
   _lastName = value;
  }
 }
}


In C# 3.0, we implement Employee class with few lines for above requirements.

public class Employee
{
 public int ID
 {
  get;
  set;
 }
public string FirstName
 {
  set; 
  get;
  
 }
public string LastName
 {
  get;
  set;
 }

}


How to create read-only property?


We can create read-only property by adding private keyword private before set.
e.g.
public class Employee
{
 public int ID
 {
  get;
  private set;
        }
}


How to initialize read-only property?


public class Employee
{

 public Employee(int ID)
 {
  this.ID = ID;
 }
  
public int ID
 {
  get;
  private set;
        }
}


You can not create write only auto implemented properties but you can create it by traditional way.


public int ID
{
 set
 {
  _id = value;
        }
}


Benefits of Auto Implemented Properties


- Save typing time
- Increase productivity

3. Anonymous Types


A way to encapsulate a set of read-only properties into a object without defining class explicitly.

- The compiler will define a type/class automatically that represents the Anonymous Types in background.

- Anonymous types have been created with the help of "Object initializers" and implicitly typed variables.

- The Anonymous type is created with read-only properties mean you can not assign values to it after creation.

- It is strongly type.

- Mutable in VB and immutable in C#.

For example,
var product = new {Name = "C# Rocks!", Price = 3};

Automatically gets translated by the compiler to something like this:

class __Anonymous1
{
   private string name;
   private int price;

   public string Name 
   {
      get { return name; }
      set { name = value; }
   }

   public int Price
   {
      get { return price; }
      set { price = value; }
   }
}

__Anonymous1 product = new __Anonymous1();
product.Name = "C# Rocks!";
product.Price = 3;


Usage of Anonymous Types


- Use anonymous types when you deal with Linq to store query results. Anonymous type can be used in "LINQ to SQL" to access some of the fields from a whole set of fields.

Limitations of Anonymous Types


- The scope of Anonymous type is limited to the method in which it defines.

- It can not be used in method parameters or return values, class level (global) variables, properties.

4. Extension Methods


A way to extend an existing type
For example,
public static class StringExntensionMethods
    {
        public static void AlertMessageBox(this string str)
        {
            MessageBox.Show(str);
        }
   }
string str = "Extesion Method Example";
str.AlertMessageBox();


Benefits of Extension Methods


- To extend an existing type.
- To specify validation on value of an existing type instance.

5. Object and Collection Initializers


A way to initialize accessible members of a class at object creation time without invoking constructor explicitly.

For example,
class Employee
{
    // Auto-implemented properties
    public int Age { get; set; }
    public string Name { get; set; }
}

 // Object initializer
 Employee obj = new Employee {Age = 24, Name = "Test"};

public class CoOrdinate
{
   public int x ;
   public int y;
}


Now we can create and initialize the object via this.

var myCoOrd = new CoOrdinate{ x = 0, y= 0} ;

The above code can also be replaced by creating constructor with arguments Age and Name. Then what is the benefit of Object Initializers? The benefit here is that the arguments order and the number of arguments.


- Collection initializers allow to specify one or more element initializers when you create an object of collection class that implements IEnumerable.(i.e. Element initializers can be a simple value, an expression or an object initializers.)

In C# 2.0, we create collection and add elements in collection.
For example,

List animals = new List();
animals.Add("monkey");
animals.Add("donkey");
animals.Add("cow");
animals.Add("dog");
animals.Add("cat");


In C# 3.0, the above code will be replaced by collection initializers features in C# 3.0

List animals = new List {
"monkey", "donkey", "cow", "dog", "cat" } ;

//Element initializers as a simple value
List digits = new List { 0, 1, 2 };

//Element initializers as a Object initializers
List emp = new List { new Employee(1), new Employee{FirstName = "Test", LastName = "Test" } };

Benefits of Object and Collection Initializer


- The benefit of object initializers is that the arguments order and the number of arguments.

6. Lambda Expressions


It is a substitution for anonymous method – declaring method inline.

For example,
1) Traditional way of assigning method to delegate

delegate bool SomeDelegate(int i);
public void SomeMethod()
{
 SomeDelegate sd = new SomeDelegate(OtherMethod);
}
private bool OtherMethod(int i)
{
   return i > 2;
}

2) Replacing traditional way of declaring method and then assign it to delegate by declaring method inline via anonymous method.
delegate bool SomeDelegate(int i);
private void SomeMethod()
{
 SomeDelegate sd = delegate(int i){return i > 2;}
}

3) Replacing anonymous method using Lambda Expression
delegate bool SomeDelegate(int i);
private void SomeMethod()
{
 SomeDelegate sd = (int i) => { return i > 2;}

}


Benefits of Lambda Expressions


- Save typing time via minimal syntax - write inline code block where delegates are expected. No need to specify return types and name explicitly.
- It provides support for expression tree.

Usage of Lambda Expressions


- Replacement of Anonymous Methods.
- It can be also be used for filtering, sorting, iterating in generic collection and LINQ.

To make an instance of an object globally available and guarantee that only one instance of the class

Singleton provides a global,
Making the class create a single instance of itself.
public class SampleSingleton   
{         //SingleTon   
        private static volatile SampleSingleton _instance;   
        private static object syncRoot = new Object();   
        public static SampleSingleton Instance   
        {   
            get  
            {   
                if (_instance == null)   
                {   
                    lock (syncRoot)   
                    {   
                        if (_instance == null)   
                        {   
                            _instance = new SampleSingleton();   
                        }   
                    }   
                }   
  
                return _instance;   
            }   
        }   
  
        public string getDisplay()   
        {   
            return "SingleTon";   
        }   
    }   
///Access singleton    
 SampleSingleton.Instance.getDisplay();  

Sunday, March 28, 2010

Convert number to word

Convert number to word



  Dim n As Long
         'The output is saved in variable strOutPut.
        Dim strOutPut As String = ""
        Dim l, r As Integer

        
        'Here 74 is considred as input.You may change as
        'per your requirement.
        n = 74
        'Get the floor value
        l = Math.Floor(n / 10)
        r = n Mod 10
        If l = 1 Then
            'For returning number from 10 to 19
            Select Case r
                Case 0
                    strOutPut = strOutPut & " Ten"
                Case 1
                    strOutPut = strOutPut & " Eleven"
                Case 2
                    strOutPut = strOutPut & " Twelve"
                Case 3
                    strOutPut = strOutPut & " Thirteen"
                Case 4
                    strOutPut = strOutPut & " Fourteen"
                Case 5
                    strOutPut = strOutPut & " Fifteen"
                Case 6
                    strOutPut = strOutPut & " Sixteen"
                Case 7
                    strOutPut = strOutPut & " Seventeen"
                Case 8
                    strOutPut = strOutPut & " Eighteen"
                Case 9
                    strOutPut = strOutPut & " Nineteen"
            End Select
        Else
            'For returning the number in multiple of 10.
            Select Case l
                Case 2
                    strOutPut = strOutPut & " Twenty"
                Case 3
                    strOutPut = strOutPut & " Thirty"
                Case 4
                    strOutPut = strOutPut & " Forty"
                Case 5
                    strOutPut = strOutPut & " Fifty"
                Case 6
                    strOutPut = strOutPut & " Sixty"
                Case 7
                    strOutPut = strOutPut & " Seventy"
                Case 8
                    strOutPut = strOutPut & " Eighty"
                Case 9
                    strOutPut = strOutPut & " Ninety"
            End Select
            'For returning single digit number.
            Select Case r
                Case 1
                    strOutPut = strOutPut & " One"
                Case 2
                    strOutPut = strOutPut & " Two"
                Case 3
                    strOutPut = strOutPut & " Three"
                Case 4
                    strOutPut = strOutPut & " Four"
                Case 5
                    strOutPut = strOutPut & " Five"
                Case 6
                    strOutPut = strOutPut & " Six"
                Case 7
                    strOutPut = strOutPut & " Seven"
                Case 8
                    strOutPut = strOutPut & " Eight"
                Case 9
                    strOutPut = strOutPut & " Nine"
            End Select
        End If
        MessageBox.Show(strOutPut)

Thursday, March 25, 2010

Craete Simple quiz Application in C#

1) copy this code in notepad and name the file as quiz.cs and keep in a folder named QuizApp
2) Now keep that folder in C: or D: drive
3) Open your VS 2005 Command prompt and give the path of folder where your code is lying.
4) When you reach that path type in csc quiz [quiz your .cs filename]
5) Now goto to your folder and check. .Exe would be generated. Just click on it and enjoy with the application. I have given my default username and password.

using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
public class app:Form
{
  Label log_name = new Label();
  TextBox logname = new TextBox();
  Label pass_name = new Label();
  TextBox passt_name = new TextBox(); 
  Button submit = new Button();
  int y=150;
  int x=100;
  int x1=225; 
         
  public app()
   {
     this.IsMdiContainer=true; //this will allow multiple window to be display.
     this.Text = "Home Page";// This will set Title for application window
     this.Size = new Size(550,400);
     this.MaximizeBox = false;//window can not be maximized by setting this property.
     this.BackColor = Color.Pink; 
     this.AcceptButton=submit;
     this.StartPosition = FormStartPosition.CenterScreen;// set window in the middle of screen.
     this.FormBorderStyle = FormBorderStyle.Fixed3D;// setting this property window can not be resize. 
     this.AutoScroll = true;//Scroll bar is activated if component placing exceeds the form dimension
     
     textBox1() ;// this function will display Login Form for user
    }
    public void textBox1()
     {
      log_name.Text = "Login Id :";//set label text to be displayed
      log_name.Location = new Point(x,y); //place label at mention position in the Form
      log_name.Size = new Size (112,23); //allocate space for label          
      log_name.Font = new Font ("Verdana", 10);
      log_name.ForeColor = Color.Red; //setting  forecolor for lable               
      this.Controls.Add(log_name);//Adding label into the form               
      
      logname.TabIndex = 0;
      logname.Location = new Point(x1,y);
      logname.Size = new Size (150,20);
      logname.Text="amit";
      logname.Font = new Font ("Arial", 10,FontStyle.Bold);
      logname.MaxLength = 15;// Only 15 or less than 15 characters can be enter in the textbox.
      logname.BorderStyle= System.Windows.Forms.BorderStyle.Fixed3D;
      this.Controls.Add( logname);               
      
      //Last name
      pass_name.Text = "Password :";
      pass_name.Location = new Point(x,y+50);  
      pass_name.Size = new Size (112,23);           
      pass_name.Font = new Font ("Verdana", 10);
      pass_name.ForeColor = Color.Red;                
      this.Controls.Add(pass_name);                                      
      
      passt_name.TabIndex = 1;
      passt_name.Location = new Point(x1,y+50);
      passt_name.Size = new Size (150,20);
      passt_name.PasswordChar = '*';//setting * to be displayed for the password charater entered by user
      passt_name.Text="amit";
      passt_name.Font = new Font ("Arial", 10,FontStyle.Bold);
      passt_name.BorderStyle= System.Windows.Forms.BorderStyle.Fixed3D;
      passt_name.MaxLength = 15;  
      this.Controls.Add(passt_name); 
      
      Button submit = new Button();
      submit.Text= "Submit";
      submit.Location= new Point(200,y+100);
      submit.Size = new Size(75,25);
      submit.Font= new Font("verdana",10,FontStyle.Bold);
      submit.BackColor=Color.Red;
      submit.ForeColor=Color.Yellow;
      submit.Click+= new EventHandler(submit_click);      
      this.Controls.Add(submit);
      
      Button reset = new Button();
      reset.Text= "Reset";
      reset.Location= new Point(300,y+100);
      reset.Size = new Size(75,25);
      reset.Font= new Font("verdana",10,FontStyle.Bold);
      reset.ForeColor=Color.Yellow; 
      reset.BackColor=Color.Red;
      reset.Click+= new EventHandler(submit_click);
      this.Controls.Add(reset);  
      
      Label Reg_name = new Label();
      Reg_name.Text = "For New Registration  :";
      Reg_name.Location = new Point(x1-25,y-100); //Set label position
      Reg_name.Size = new Size (175,23);           
      Reg_name.Font = new Font ("Verdana", 10);
      Reg_name.ForeColor = Color.Blue;                
      this.Controls.Add(Reg_name);//Add
      
      Button Reg = new Button();
      Reg.Text= "Registration";
      Reg.Location= new Point(400,y-100);
      Reg.Size = new Size(110,25);
      Reg.Font= new Font("verdana",10,FontStyle.Bold);
      Reg.ForeColor=Color.Yellow; 
      Reg.BackColor=Color.Red;
      Reg.Click+= new EventHandler(submit_click);
      this.Controls.Add(Reg);  
      }
      
    public void submit_click( object sender, EventArgs e)//this block of code will called when user clicked on the any button.
      {
  String b1 = ((Button)sender).Text;
  Console.WriteLine(" b1:"+b1);
   if(b1=="Registration")
    {
      logname.Text = "";
      passt_name.Text = "";
      Console.WriteLine(" in side Registration");       
      Client client1 = new Client(this);
      this.Hide();//this will hide login Form 
      client1.Show();// this will display Registration Form
    }
      
   if(b1=="Submit")
   {
   //if login name and password are correct then allow user to move ahead.
    if((logname.Text.Trim()=="deepika")&&(passt_name.Text.Trim()=="deepika"))// will check login name and password
      {
       MessageBox.Show("Form has been submited Successfully ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information);
       User frmTemp=   new User(this,logname);//will display Category select Form, passing main Form (this) as object     
             frmTemp.Show();//this will Category select Form 
             this.Hide();//this will hide login Form                
       }   
   else 
       {
        MessageBox.Show("Please enter correct Login Id as amit and Password as amit","Error Message",MessageBoxButtons.OK,MessageBoxIcon.Information);
        logname.Focus();
        logname.Text = "";
        }
   }
    if(b1=="Reset")//if user clicked on the reset this code will execute
     {
       logname.Text = "";//cleared all the field data
       passt_name.Text = "";
       logname.Focus();
     }               
              
       }            
    
    public static void Main()
     {
      Application.Run(new app());        
      }
   
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        try{
        
         MessageBox.Show("You are Closing this From ","Alert Message",MessageBoxButtons.OK,MessageBoxIcon.Exclamation); 
         }
       catch(Exception ){ }      
      }
      base.Dispose( disposing );
     }
         
}

// THIS CODE WILL DISPLAY CATEGORY FORM

public class User:Form 
{
 Panel panel1 = new Panel();
 ComboBox cb1 = new ComboBox();
 
 Panel panel2 = new Panel(); 
 Panel panel3 = new Panel();
 Panel panel4 = new Panel(); 
 
 
 Label Reg_name = new Label();
 Form window1;
 TextBox s;
 bool isTrue;
 int scor =0 ; //initialize score board variable.
 String s7="null";
  
 RadioButton radioButton1 = new RadioButton();
 RadioButton radioButton2 = new RadioButton();
 RadioButton radioButton3 = new RadioButton();
 
 RadioButton radioButton21 = new RadioButton();
 RadioButton radioButton22 = new RadioButton();
 RadioButton radioButton23 = new RadioButton();
 
 RadioButton radioButton31 = new RadioButton();
 RadioButton radioButton32 = new RadioButton();
 RadioButton radioButton33 = new RadioButton();  
 
 
public User(Form window,TextBox logname1)
{
  Console.WriteLine(" in side user text box : "+s);  
          
    window1 = window; //initializing variable send to this Form
    s= logname1;//initializing variable send to this Form
           
     this.Text = "Select Category";// This will set Title for application window
     this.Size = new Size(600,500);
     this.MaximizeBox = false;//window can not be maximized by setting this property.
     this.BackColor = Color.Yellow; 
     this.SuspendLayout();
     this.StartPosition = FormStartPosition.CenterScreen;// set window in the middle of screen.
     this.FormBorderStyle = FormBorderStyle.Fixed3D;// setting this property window can not be resize. 
           
     
     Reg_name.Text = "Hi Amit!";
     Reg_name.Location = new Point(10,25); //Set label position
     Reg_name.Size = new Size (100,25);           
     Reg_name.Font = new Font ("Verdana", 10,FontStyle.Bold);
     Reg_name.ForeColor = Color.Red;                
     this.Controls.Add(Reg_name);        
                     
                     
     panel1.Location = new Point(10,60);//crating panel on the From
     panel1.Size = new Size(575, 300);    
     panel1.BackColor = Color.Green; 
     this.Controls.Add(panel1);// Add the Panel control to the form.
            
     Label l_cb = new Label();//ComboBox label
     l_cb .Text = " Category :";
     l_cb .Location = new Point(10,25);  
     l_cb .Size = new Size (100,17);           
     l_cb .Font = new Font ("Verdana", 10);
     l_cb .ForeColor = Color.Blue;            
   
     cb1.Location = new Point(125,25);
     cb1 .Size = new Size (232,20);   
     cb1 .Font = new Font ("Verdana", 10);
     cb1.Text= " Select One Option ";
     cb1.Items.Add(" Select One Option "); //Adding items in the ComboBox.
     cb1.Items.Add("Software");  
     cb1.Items.Add("Hardware");  
     cb1.Items.Add("General");  
     cb1.Items.Add("Sports");  
     cb1.Items.Add("Java");      
     cb1.Items.Add("C#(Sharp)"); 
     cb1.Sorted=true;// setting sort property for ComboBox
             
     Button Reg1 = new Button();
     Reg1.Text= "Submit";
     Reg1.Location= new Point(250,250);
     Reg1.Size = new Size(75,25);
     Reg1.Font= new Font("verdana",10,FontStyle.Bold);
     Reg1.ForeColor=Color.Yellow; 
     Reg1.BackColor=Color.Red;
     Reg1.Click+= new EventHandler(submit1_click);
            
     Button bac = new Button();
     bac.Text= "Home Page";
     bac.Location= new Point(250,425);
     bac.Size = new Size(125,25);
     bac.Font= new Font("verdana",10,FontStyle.Bold);
     bac.ForeColor=Color.Yellow; 
     bac.BackColor=Color.Red;
     bac.Click+= new EventHandler(submit1_click);// when user clicked on the button mentioned event will call
     this.Controls.Add(bac); 
             
     // Add the Label and TextBox controls to the Panel.
       panel1.Controls.Add(l_cb );
       panel1.Controls.Add(cb1);
       panel1.Controls.Add(Reg1);    

    
}
  public void submit1_click( object sender, EventArgs e)// block of code will get call when user clicks on the submit
   {
     Boolean flag1 = true;
     
     String b1 = ((Button)sender).Text;
     s7 =cb1.Text; 
       if(b1=="Home Page")
  {
   this.Dispose();//Category Form will get dispose 
   window1.Show(); //Login form will get display, for this purpose i have passed (this) object to this constructor
         s.Focus();
         scor = 0;
         Console.WriteLine("Score board :"+scor);
   }
  else //when user clicked on th submit button 
   {
     if(s7!="General")
      {
         MessageBox.Show("For Demo Please select only General Category ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
         flag1 = false;
         cb1.Focus();       
             }
    
      if(flag1) //is flag is true 
       {
         this.Controls.Remove(panel1); //this remove panel added previously on the Category Form  
         this.Controls.Remove(Reg_name); // remove top label form the Category Form  
         
         showdata(s7);
        }
    }
    
     }
  public void showdata(String str)     
   {
     String b1 = str;
     
      this.Text = "View FAQS";//setting new title for Form
      Label wel = new Label();
      wel.Text = "Wel Come to the Category : "+b1+" !! ";
      wel.Location = new Point(100,25); //Set label position
      wel.Size = new Size (350,25);           
      wel.Font = new Font ("Verdana", 10,FontStyle.Bold);
      wel.ForeColor = Color.Red;                
      this.Controls.Add(wel);  
      
    showquestion();    
    
       }
       
    public void showquestion()
     {
         panel2.Location = new Point(50,60);
   panel2.Size = new Size(485, 320);  
   panel2.BackColor = Color.Pink; 
         this.Controls.Add(panel2);//newly created panel added to this Form
         
          Button Reg2 = new Button();
    Reg2.Text= "Next2";
    Reg2.Location= new Point(200,270);
    Reg2.Size = new Size(75,25);
    Reg2.Font= new Font("verdana",10,FontStyle.Bold);
    Reg2.ForeColor=Color.Yellow; 
    Reg2.BackColor=Color.Red;
    Reg2.Click+= new EventHandler(submit2_click);
    
    Label ques1 = new Label();
    ques1.Text = "Question 1: Who won the 1998 Soccer world Cup ?";
    ques1.Location = new Point(10,20); //Set label position
    ques1.Size = new Size (425,25);           
    ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ques1.ForeColor = Color.Red;                
          
          
          GroupBox groupBox1 =new GroupBox();//creating Group box for radio buttons
          groupBox1.Text = "Answer";
          groupBox1.Location= new Point(50,60);
    groupBox1.Size = new Size(400,175);
        
        
    radioButton1.Location= new Point(20,25);
    radioButton1.Size = new Size(50,25);
    radioButton1.CheckedChanged += new System.EventHandler(value);//Evwn will call when user select any check box
        
    Label ans1 = new Label();
    ans1.Text = " France ";
    ans1.Location = new Point(75,25); //Set label position
    ans1.Size = new Size (100,25);           
    ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans1.ForeColor = Color.Blue;  
        
        
    radioButton2.Location= new Point(20,75);
    radioButton2.Size = new Size(50,25);
    radioButton2.CheckedChanged += new System.EventHandler(value);
       
    Label ans2 = new Label();
    ans2.Text = " Brazil ";
    ans2.Location = new Point(75,75); //Set label position
    ans2.Size = new Size (100,25);           
    ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans2.ForeColor = Color.Blue; 
        
        
    radioButton3.Location= new Point(20,125);
    radioButton3.Size = new Size(50,25);
    radioButton3.CheckedChanged += new System.EventHandler(value);
        
    Label ans3 = new Label();
    ans3.Text = " Italy ";
    ans3.Location = new Point(75,125); //Set label position
    ans3.Size = new Size (100,25);           
    ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans3.ForeColor = Color.Blue;        
        
    // Add the RadioButtons to the GroupBox.
    groupBox1.Controls.Add(radioButton1);
    groupBox1.Controls.Add(radioButton2);
    groupBox1.Controls.Add(radioButton3);
    groupBox1.Controls.Add(ans1);
    groupBox1.Controls.Add(ans2);
    groupBox1.Controls.Add(ans3);
        
        // Add the GroupBox to the Form.
    Controls.Add(groupBox1);
         panel2.Controls.Add(Reg2);
         panel2.Controls.Add(ques1);
         panel2.Controls.Add(groupBox1);
        
     }
   public void submit2_click( object sender, EventArgs e)
    {
    
      if(isTrue) //if given answer is correct, flag will be true, and Score Board will be incremented
       {
         scor = scor + 1;
       }
       
       isTrue = false;
       Console.WriteLine(" value of score:"+ scor); 
       
   showquestion1();// this function will remove current pannel and insert new panel          
      
    }
       
   public void value(object sender, EventArgs e)
    {
     isTrue = radioButton1.Checked; //will set to true if correct answer checkbox is selected by user           
      
    }
    
    public void showquestion1()
      {
  panel2.Dispose(); //dispose current panel        
           
  
  panel3.Location = new Point(50,60);//create new panel
  panel3.Size = new Size(485, 320);
  //panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  panel3.BackColor = Color.Orange; 
  this.Controls.Add(panel3);//newly created panel added to Category Form
           
  Button Reg2 = new Button();
  Reg2.Text= "Next3";
  Reg2.Location= new Point(200,270);
  Reg2.Size = new Size(75,25);
  Reg2.Font= new Font("verdana",10,FontStyle.Bold);
  Reg2.ForeColor=Color.Yellow; 
  Reg2.BackColor=Color.Red;
        Reg2.Click+= new EventHandler(submit3_click);
      
  Label ques1 = new Label();
  ques1.Text = "Question 2: Which Country won the 1999 Cricket world Cup?";
  ques1.Location = new Point(10,20); //Set label position
  ques1.Size = new Size (425,40);           
  ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
  ques1.ForeColor = Color.Red;                
            

  GroupBox groupBox2 =new GroupBox();
  groupBox2.Text = "Answer";
  groupBox2.Location= new Point(50,60);
  groupBox2.Size = new Size(400,175);         
          
  radioButton21.Location= new Point(20,25);
  radioButton21.Size = new Size(50,25);
  radioButton21.CheckedChanged += new System.EventHandler(value2);
          
  Label ans1 = new Label();
  ans1.Text = " India ";
  ans1.Location = new Point(75,25); //Set label position
  ans1.Size = new Size (100,25);            
  ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
  ans1.ForeColor = Color.Blue;            
          
  radioButton22.Location= new Point(20,75);
  radioButton22.Size = new Size(50,25);
  radioButton22.CheckedChanged += new System.EventHandler(value2);
          
  Label ans2 = new Label();
  ans2.Text = " Australia ";
  ans2.Location = new Point(75,75); //Set label position
  ans2.Size = new Size (100,25);           
  ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
  ans2.ForeColor = Color.Blue; 
          
  radioButton23.Location= new Point(20,125);
  radioButton23.Size = new Size(50,25);
  radioButton23.CheckedChanged += new System.EventHandler(value2);
          
  Label ans3 = new Label();
  ans3.Text = " Pakistan ";
  ans3.Location = new Point(75,125); //Set label position
  ans3.Size = new Size (100,25);           
  ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
  ans3.ForeColor = Color.Blue;        
          
  // Add the RadioButtons to the GroupBox.
  groupBox2.Controls.Add(radioButton21);
  groupBox2.Controls.Add(radioButton22);
  groupBox2.Controls.Add(radioButton23);
  groupBox2.Controls.Add(ans1);
  groupBox2.Controls.Add(ans2);
  groupBox2.Controls.Add(ans3);
          
  // Add the GroupBox to the Form.
   Controls.Add(groupBox2); 
   panel3.Controls.Add(Reg2);
   panel3.Controls.Add(ques1);
   panel3.Controls.Add(groupBox2);
          
       }
  public void submit3_click( object sender, EventArgs e)
   {
    
      if(isTrue)
        {
          scor = scor + 1;
        }
         isTrue = false;
         Console.WriteLine(" value of score:"+ scor);     
        
        showquestion2();               
   }
              
  public void value2(object source, EventArgs e)
   {           
      isTrue = radioButton22.Checked;             
                
   }
   
    public void showquestion2()
     {
  panel3.Dispose();        
                 
  Panel panel4 = new Panel(); 
  panel4.SuspendLayout();
  panel4.Location = new Point(50,60);
  panel4.Size = new Size(485, 320);
  panel4.BackColor = Color.Orange; 
  this.Controls.Add(panel4);
                 
  Button Reg2 = new Button();
  Reg2.Text= "Next4";
  Reg2.Location= new Point(200,270);
  Reg2.Size = new Size(75,25);
  Reg2.Font= new Font("verdana",10,FontStyle.Bold);
  Reg2.ForeColor=Color.Yellow; 
  Reg2.BackColor=Color.Red;
  Reg2.Click+= new EventHandler(submit4_click);
            
  Label ques1 = new Label();
  ques1.Text = "Question 3: Who won the 20001 Wimbledon Grand Slam?";
  ques1.Location = new Point(10,20); //Set label position
  ques1.Size = new Size (475,25);           
  ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
  ques1.ForeColor = Color.Red;  
                  
  GroupBox groupBox3 =new GroupBox();
  groupBox3.Text = "Answer";
  groupBox3.Location= new Point(50,60);
  groupBox3.Size = new Size(400,175);               
  
  radioButton31.Location= new Point(20,25);
  radioButton31.Size = new Size(50,25);
  radioButton31.CheckedChanged += new System.EventHandler(value3);  
  
  Label ans1 = new Label();
  ans1.Text = " Andre Aggassi ";
  ans1.Location = new Point(75,25); //Set label position
  ans1.Size = new Size (250,25);            
  ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
  ans1.ForeColor = Color.Blue; 
                
  radioButton32.Location= new Point(20,75);
  radioButton32.Size = new Size(50,25);
  radioButton32.CheckedChanged += new System.EventHandler(value3);
                
        Label ans2 = new Label();
        ans2.Text = " Peat Sampras";
        ans2.Location = new Point(75,75); //Set label position
        ans2.Size = new Size (250,25);           
        ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
        ans2.ForeColor = Color.Blue;                
                
  radioButton33.Location= new Point(20,125);
  radioButton33.Size = new Size(50,25);
  radioButton33.CheckedChanged += new System.EventHandler(value3);
                
  Label ans3 = new Label();
  ans3.Text = " Goran Ivansevich ";
  ans3.Location = new Point(75,125); //Set label position
  ans3.Size = new Size (250,25);           
  ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
  ans3.ForeColor = Color.Blue;        
                
// Add the RadioButtons to the GroupBox.
        groupBox3.Controls.Add(radioButton31);
        groupBox3.Controls.Add(radioButton32);
        groupBox3.Controls.Add(radioButton33);
        groupBox3.Controls.Add(ans1);
        groupBox3.Controls.Add(ans2);
        groupBox3.Controls.Add(ans3);             
          
   panel4.Controls.Add(Reg2);
   panel4.Controls.Add(ques1);
   panel4.Controls.Add(groupBox3);
                
     }
   public void submit4_click( object sender, EventArgs e)
    {
      if(isTrue)
        {
    scor = scor + 1;
        }
        
      isTrue = false;                    
      Console.WriteLine(" value of score:"+ scor);   
      
      User1 f1= new User1(window1,s,scor,s7);//here new form is crated and passing some of the value to the constructor
      f1.Show();
      this.Hide();  
      
    }
                     
   public void value3(object source, EventArgs e)
    {
     isTrue = radioButton33.Checked;
     } 
  }


public class User1:Form
{
  //initializing values
  Form dumwin;
  int scoreb;
  TextBox tb1;
  String s1;
  bool isTrue1;
  Panel panel1 = new Panel();
  Panel panel2 = new Panel();
  Panel panel3 = new Panel();
  Panel panel4 = new Panel(); 
  Panel panel5 = new Panel(); 
  Panel panel6 = new Panel(); 
  Panel panel7 = new Panel(); 

  RadioButton radioButton11 = new RadioButton();
  RadioButton radioButton12 = new RadioButton();
  RadioButton radioButton13 = new RadioButton();

  RadioButton radioButton21 = new RadioButton();
  RadioButton radioButton22 = new RadioButton();
  RadioButton radioButton23 = new RadioButton();
  
  RadioButton radioButton31 = new RadioButton();
  RadioButton radioButton32 = new RadioButton();
  RadioButton radioButton33 = new RadioButton();

  RadioButton radioButton41 = new RadioButton();
  RadioButton radioButton42 = new RadioButton();
  RadioButton radioButton43 = new RadioButton();
 
  RadioButton radioButton51 = new RadioButton();
  RadioButton radioButton52 = new RadioButton();
  RadioButton radioButton53 = new RadioButton();

  RadioButton radioButton61 = new RadioButton();
  RadioButton radioButton62 = new RadioButton();
  RadioButton radioButton63 = new RadioButton();

  RadioButton radioButton71 = new RadioButton();
  RadioButton radioButton72 = new RadioButton();
  RadioButton radioButton73 = new RadioButton();

 public User1(Form window2 ,TextBox tb,int sb,String s)
  {    
   dumwin = window2;//assigning value to the variable on this New Form
   scoreb = sb;
   tb1 = tb; 
   s1= s;
           
     this.Text = "View FAQS";// This will set Title for application window
     this.Size = new Size(600,500);
     this.MaximizeBox = false;//window can not be maximized by setting this property.
     this.BackColor = Color.Yellow;
     this.StartPosition = FormStartPosition.CenterScreen;// set window in the middle of screen.
     this.FormBorderStyle = FormBorderStyle.Fixed3D;// setting this property window can not be resize. 
           
           
     Label wel = new Label();
     wel.Text = "Wel Come to the Category : "+s1+" !! ";
     wel.Location = new Point(100,25); //Set label position
     wel.Size = new Size (350,25);           
     wel.Font = new Font ("Verdana", 10,FontStyle.Bold);
     wel.ForeColor = Color.Red;                
     this.Controls.Add(wel); 
           
     Button bac = new Button();
     bac.Text= "Home Page";
     bac.Location= new Point(250,425);
     bac.Size = new Size(125,25);
     bac.Font= new Font("verdana",10,FontStyle.Bold);
     bac.ForeColor=Color.Yellow; 
     bac.BackColor=Color.Red;
     bac.Click+= new EventHandler(submit1_click);
     this.Controls.Add(bac); 
     
     showquest1();     
 }
     
  public void showquest1()
   {
            
    panel1.SuspendLayout();
    panel1.Location = new Point(50,60);
    panel1.Size = new Size(485, 320);
    panel1.BackColor = Color.Cyan; 
    this.Controls.Add(panel1);
     
    Button Reg2 = new Button();
    Reg2.Text= "Next5";
    Reg2.Location= new Point(200,270);
    Reg2.Size = new Size(75,25);
    Reg2.Font= new Font("verdana",10,FontStyle.Bold);
    Reg2.ForeColor=Color.Yellow; 
    Reg2.BackColor=Color.Red;
    Reg2.Click+= new EventHandler(submit1_click);
                
    Label ques1 = new Label();
    ques1.Text = "Question 4: Who won the 20001 F1 Championship ?";
    ques1.Location = new Point(10,20); //Set label position
    ques1.Size = new Size (475,25);           
    ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ques1.ForeColor = Color.Red;  
                      
    GroupBox groupBox =new GroupBox();
    groupBox.Text = "Answer";
    groupBox.Location= new Point(50,60);
    groupBox.Size = new Size(400,175);                
                    
    radioButton11.Location= new Point(20,25);
    radioButton11.Size = new Size(50,25);
    radioButton11.CheckedChanged += new System.EventHandler(value1);
    
    Label ans1 = new Label();
    ans1.Text = " David Coulthad ";
    ans1.Location = new Point(75,25); //Set label position
    ans1.Size = new Size (250,25);            
    ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans1.ForeColor = Color.Blue;    
                    
    radioButton12.Location= new Point(20,75);
    radioButton12.Size = new Size(50,25);
    radioButton12.CheckedChanged += new System.EventHandler(value1);
                    
    Label ans2 = new Label();
    ans2.Text = " Michael Schumacher";
    ans2.Location = new Point(75,75); //Set label position
    ans2.Size = new Size (250,25);           
    ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans2.ForeColor = Color.Blue;                
                    
    radioButton13.Location= new Point(20,125); 
    radioButton13.Size = new Size(50,25);
    radioButton13.CheckedChanged += new System.EventHandler(value1);
                    
    Label ans3 = new Label();
    ans3.Text = " Ralf Schumacher ";
    ans3.Location = new Point(75,125); //Set label position
    ans3.Size = new Size (250,25);           
    ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans3.ForeColor = Color.Blue;        
                    
 // Add the RadioButtons to the GroupBox.
 
    groupBox.Controls.Add(radioButton11);
    groupBox.Controls.Add(radioButton12);
    groupBox.Controls.Add(radioButton13);
    groupBox.Controls.Add(ans1);
    groupBox.Controls.Add(ans2);
    groupBox.Controls.Add(ans3);    
    
    panel1.Controls.Add(Reg2);
    panel1.Controls.Add(ques1);
    panel1.Controls.Add(groupBox);    
          
  }
        
public void submit1_click( object sender, EventArgs e)
  {     
    String b1 = ((Button)sender).Text;
    //Console.WriteLine(" b1:"+b1);

    if(b1=="Home Page")
      {
  this.Dispose();
   //Console.WriteLine("after disposing");
   dumwin.Show(); 
   tb1.Focus();
   scoreb = 0;
   Console.WriteLine("Score board :"+scoreb);
      }     
      
    if(isTrue1)
      scoreb = scoreb+1;
      Console.WriteLine("Score board :"+scoreb);
      
   showquest2();
   
   }  
        
public void value1(object source, EventArgs e)
  {
   isTrue1 = radioButton12.Checked;
   }      
     
 public void showquest2()
   {       
      panel1.Dispose();
      
      panel2.Location = new Point(50,60);
      panel2.Size = new Size(485, 320);
      panel2.BackColor = Color.Cyan; 
      this.Controls.Add(panel2);
           
      Button Reg2 = new Button();
      Reg2.Text= "Next6";
      Reg2.Location= new Point(200,270);
      Reg2.Size = new Size(75,25);
      Reg2.Font= new Font("verdana",10,FontStyle.Bold);
      Reg2.ForeColor=Color.Yellow; 
      Reg2.BackColor=Color.Red;
      Reg2.Click+= new EventHandler(submit2_click);                   
  
      Label ques1 = new Label();
      ques1.Text = "Question 5: Select correct date for WTC Terrorist Attack?";
      ques1.Location = new Point(10,20); //Set label position
      ques1.Size = new Size (475,25);           
      ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
      ques1.ForeColor = Color.Red;  
                            
      GroupBox groupBox =new GroupBox();
      groupBox.Text = "Answer";
      groupBox.Location= new Point(50,60);
      groupBox.Size = new Size(400,175);                
      
      radioButton21.Location= new Point(20,25);
      radioButton21.Size = new Size(50,25);
      radioButton21.CheckedChanged += new System.EventHandler(value2);
                          
      Label ans1 = new Label();
      ans1.Text = " 12 september";
      ans1.Location = new Point(75,25); //Set label position
      ans1.Size = new Size (250,25);            
      ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
      ans1.ForeColor = Color.Blue;       
                    
      radioButton22.Location= new Point(20,75);
      radioButton22.Size = new Size(50,25);
      radioButton22.CheckedChanged += new System.EventHandler(value2);
                          
      Label ans2 = new Label();
      ans2.Text = " 13 September";
      ans2.Location = new Point(75,75); //Set label position
      ans2.Size = new Size (250,25);           
      ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
      ans2.ForeColor = Color.Blue;                
                          
      radioButton23.Location= new Point(20,125);
      radioButton23.Size = new Size(50,25);
      radioButton23.CheckedChanged += new System.EventHandler(value2);
                          
      Label ans3 = new Label();
      ans3.Text = " 11 September ";
      ans3.Location = new Point(75,125); //Set label position
      ans3.Size = new Size (250,25);           
      ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
      ans3.ForeColor = Color.Blue;
      
      // Add the RadioButtons to the GroupBox.
      groupBox.Controls.Add(radioButton21);
      groupBox.Controls.Add(radioButton22);
      groupBox.Controls.Add(radioButton23);
      groupBox.Controls.Add(ans1);
      groupBox.Controls.Add(ans2);
      groupBox.Controls.Add(ans3);              
                    
       panel2.Controls.Add(Reg2);
       panel2.Controls.Add(ques1);
       panel2.Controls.Add(groupBox);     
                  
   }
               
 public void submit2_click( object sender, EventArgs e)
  {
    String b1 = ((Button)sender).Text; 
    
    if(isTrue1)
    scoreb = scoreb+1;
    isTrue1 = false;
    Console.WriteLine("Score board :"+scoreb);
  showquest3();
          
   }  
   
 public void value2(object source, EventArgs e)
  {
    isTrue1 = radioButton23.Checked;
  }  
           
 public void showquest3()
  {              
    panel2.Dispose();            
    
    panel3.Location = new Point(50,60);
    panel3.Size = new Size(485, 320);
    panel3.BackColor = Color.Cyan; 
    this.Controls.Add(panel3);
               
    Button Reg2 = new Button();
    Reg2.Text= "Next7";
    Reg2.Location= new Point(200,270);
    Reg2.Size = new Size(75,25);
    Reg2.Font= new Font("verdana",10,FontStyle.Bold);
    Reg2.ForeColor=Color.Yellow; 
    Reg2.BackColor=Color.Red;
    Reg2.Click+= new EventHandler(submit3_click);
                          
    Label ques1 = new Label();
    ques1.Text = "Question 6: Which is the Capital of New Zealand?";
    ques1.Location = new Point(10,20); //Set label position
    ques1.Size = new Size (475,25);           
    ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ques1.ForeColor = Color.Red;  
                                
    GroupBox groupBox =new GroupBox();
    groupBox.Text = "Answer";
    groupBox.Location= new Point(50,60);
    groupBox.Size = new Size(400,175);                
                              
    radioButton31.Location= new Point(20,25);
    radioButton31.Size = new Size(50,25);
    radioButton31.CheckedChanged += new System.EventHandler(value3);
                              
    Label ans1 = new Label();
    ans1.Text = " Wellignton";
    ans1.Location = new Point(75,25); //Set label position
    ans1.Size = new Size (250,25);            
    ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans1.ForeColor = Color.Blue;        
                              
    radioButton32.Location= new Point(20,75);
    radioButton32.Size = new Size(50,25);
    radioButton32.CheckedChanged += new System.EventHandler(value3);
               
    Label ans2 = new Label();
    ans2.Text = " Auckland";
    ans2.Location = new Point(75,75); //Set label position
    ans2.Size = new Size (250,25);           
    ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans2.ForeColor = Color.Blue;                
    
    radioButton33.Location= new Point(20,125);
    radioButton33.Size = new Size(50,25);
    radioButton33.CheckedChanged += new System.EventHandler(value3);
    
    Label ans3 = new Label();
    ans3.Text = " Canbera ";
    ans3.Location = new Point(75,125); //Set label position
    ans3.Size = new Size (250,25);           
    ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans3.ForeColor = Color.Blue;        
    
    // Add the RadioButtons to the GroupBox.
    groupBox.Controls.Add(radioButton31);
    groupBox.Controls.Add(radioButton32);
    groupBox.Controls.Add(radioButton33);
    groupBox.Controls.Add(ans1);
    groupBox.Controls.Add(ans2);
    groupBox.Controls.Add(ans3);              
    
    panel3.Controls.Add(Reg2);
    panel3.Controls.Add(ques1);
    panel3.Controls.Add(groupBox);    
    
 }
                   
 public void submit3_click( object sender, EventArgs e)
  {
  
     String b1 = ((Button)sender).Text;          
     
       if(isTrue1)
        scoreb = scoreb+1;
        isTrue1 = false;
        Console.WriteLine("Score board :"+scoreb);
   showquest4();
          
   }  
                   
 public void value3(object source, EventArgs e)
   {
     isTrue1 = radioButton23.Checked;
   }
   
 public void showquest4()
  {
  
    panel3.Dispose();
    
    panel4.Location = new Point(50,60);
    panel4.Size = new Size(485, 320);
    panel4.BackColor = Color.Cyan; 
    this.Controls.Add(panel4);
    
    Button Reg2 = new Button();
    Reg2.Text= "Next8";
    Reg2.Location= new Point(200,270);
    Reg2.Size = new Size(75,25);
    Reg2.Font= new Font("verdana",10,FontStyle.Bold);
    Reg2.ForeColor=Color.Yellow; 
    Reg2.BackColor=Color.Red;
    Reg2.Click+= new EventHandler(submit4_click);
    
    Label ques1 = new Label();
    ques1.Text = "Question 7: Which is the Capital of India?";
    ques1.Location = new Point(10,20); //Set label position
    ques1.Size = new Size (475,25);           
    ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ques1.ForeColor = Color.Red;  
    
    GroupBox groupBox =new GroupBox();
    groupBox.Text = "Answer";
    groupBox.Location= new Point(50,60);
    groupBox.Size = new Size(400,175);                
    
    radioButton41.Location= new Point(20,25);
    radioButton41.Size = new Size(50,25);
    radioButton41.CheckedChanged += new System.EventHandler(value4);
    
    Label ans1 = new Label();
    ans1.Text = " Delhi";
    ans1.Location = new Point(75,25); //Set label position
    ans1.Size = new Size (250,25);            
    ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans1.ForeColor = Color.Blue;  
    
    
    radioButton42.Location= new Point(20,75);
    radioButton42.Size = new Size(50,25);
    radioButton42.CheckedChanged += new System.EventHandler(value4);
    
    Label ans2 = new Label();
    ans2.Text = " Mumbai";
    ans2.Location = new Point(75,75); //Set label position
    ans2.Size = new Size (250,25);           
    ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans2.ForeColor = Color.Blue;                
    
    radioButton43.Location= new Point(20,125);
    radioButton43.Size = new Size(50,25);
    radioButton43.CheckedChanged += new System.EventHandler(value4);
    
    Label ans3 = new Label();
    
    ans3.Text = " Banglore ";
    ans3.Location = new Point(75,125); //Set label position
    ans3.Size = new Size (250,25);           
    ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans3.ForeColor = Color.Blue;        
    
    // Add the RadioButtons to the GroupBox.
    groupBox.Controls.Add(radioButton41);
    groupBox.Controls.Add(radioButton42);
    groupBox.Controls.Add(radioButton43);
    groupBox.Controls.Add(ans1);
    groupBox.Controls.Add(ans2);
    groupBox.Controls.Add(ans3);              
    
    panel4.Controls.Add(Reg2);
    panel4.Controls.Add(ques1);
    panel4.Controls.Add(groupBox);    
    
  }                
public void submit4_click( object sender, EventArgs e)
  {
  
    String b1 = ((Button)sender).Text;         
    
      if(isTrue1) 
      scoreb = scoreb+1;
      isTrue1 = false;
      Console.WriteLine("Score board :"+scoreb);
 showquest5();
      
   }   
   
public void value4(object source, EventArgs e)
  {
    isTrue1 = radioButton41.Checked;
   } 
   
 public void showquest5()
   {
     panel4.Dispose();
     
     panel5.Location = new Point(50,60);
     panel5.Size = new Size(485, 320);
     panel5.BackColor = Color.Cyan; 
     this.Controls.Add(panel5);
     
     Button Reg2 = new Button();
     Reg2.Text= "Next9";
     Reg2.Location= new Point(200,270);
     Reg2.Size = new Size(75,25);
     Reg2.Font= new Font("verdana",10,FontStyle.Bold);
     Reg2.ForeColor=Color.Yellow; 
     Reg2.BackColor=Color.Red;
     Reg2.Click+= new EventHandler(submit5_click);
     
     Label ques1 = new Label();
     ques1.Text = "Question 8: What is the date of Indian Parliament Attack?";
     ques1.Location = new Point(10,20); //Set label position
     ques1.Size = new Size (475,25);           
     ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
     ques1.ForeColor = Color.Red;  
     
     GroupBox groupBox =new GroupBox();
     groupBox.Text = "Answer";
     groupBox.Location= new Point(50,60);
     groupBox.Size = new Size(400,175);               
     
     radioButton51.Location= new Point(20,25);
     radioButton51.Size = new Size(50,25);
     radioButton51.CheckedChanged += new System.EventHandler(value5);
     
     Label ans1 = new Label();
     ans1.Text = " 9 December ";
     ans1.Location = new Point(75,25); //Set label position
     ans1.Size = new Size (250,25);           
     ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
     ans1.ForeColor = Color.Blue;  
     
     
     radioButton52.Location= new Point(20,75);
     radioButton52.Size = new Size(50,25);
     radioButton52.CheckedChanged += new System.EventHandler(value5);
     
     Label ans2 = new Label();
     ans2.Text = " 11 December";
     ans2.Location = new Point(75,75); //Set label position
     ans2.Size = new Size (250,25);           
     ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
     ans2.ForeColor = Color.Blue;                 
     
     radioButton53.Location= new Point(20,125);
     radioButton53.Size = new Size(50,25);
     radioButton53.CheckedChanged += new System.EventHandler(value5);
     
     Label ans3 = new Label();
     ans3.Text = " 13 December ";
     ans3.Location = new Point(75,125); //Set label position
     ans3.Size = new Size (250,25);           
     ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
     ans3.ForeColor = Color.Blue;       
     
     // Add the RadioButtons to the GroupBox.
     groupBox.Controls.Add(radioButton51);
     groupBox.Controls.Add(radioButton52);
     groupBox.Controls.Add(radioButton53);
     groupBox.Controls.Add(ans1);
     groupBox.Controls.Add(ans2);
     groupBox.Controls.Add(ans3);             
     
     panel5.Controls.Add(Reg2);
     panel5.Controls.Add(ques1);
     panel5.Controls.Add(groupBox);     
     
 }
 
public void submit5_click( object sender, EventArgs e)
  {
  
    String b1 = ((Button)sender).Text;         
    
      if(isTrue1)
       scoreb = scoreb+1;
       isTrue1 = false;
       Console.WriteLine("Score board :"+scoreb);
   showquest6();
       
  }  
  
public void value5(object source, EventArgs e)
  {
     isTrue1 = radioButton53.Checked;
   } 
   
public void showquest6()
 {
 
   panel5.Dispose();
   
    panel6.Location = new Point(50,60);
    panel6.Size = new Size(485, 320);
    panel6.BackColor = Color.Cyan;                                 this.Controls.Add(panel6); 
    
    Button Reg2 = new Button();
    Reg2.Text= "Next10";
    Reg2.Location= new Point(200,270);
    Reg2.Size = new Size(75,25);
    Reg2.Font= new Font("verdana",10,FontStyle.Bold);
    Reg2.ForeColor=Color.Yellow; 
    Reg2.BackColor=Color.Red;
    Reg2.Click+= new EventHandler(submit6_click);
    
    Label ques1 = new Label();
    ques1.Text = "Question 9:Who is Oscar winner this Year for the Best Actress?";
    ques1.Location = new Point(10,20); //Set label position
    ques1.Size = new Size (475,40);           
    ques1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ques1.ForeColor = Color.Red;  
    
    GroupBox groupBox =new GroupBox();
    groupBox.Text = "Answer";
    groupBox.Location= new Point(50,60);
    groupBox.Size = new Size(400,175);                
    
    radioButton61.Location= new Point(20,25);
    radioButton61.Size = new Size(50,25);
    radioButton61.CheckedChanged += new System.EventHandler(value6);
    
    Label ans1 = new Label();
    ans1.Text = " Catherina Zeta Jones";
    ans1.Location = new Point(75,25); //Set label position
    ans1.Size = new Size (250,25);            
    ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans1.ForeColor = Color.Blue;  
    
    
    radioButton62.Location= new Point(20,75);
    radioButton62.Size = new Size(50,25);
    radioButton62.CheckedChanged += new System.EventHandler(value6);
    
    Label ans2 = new Label();
    ans2.Text = " Judie Foster";
    ans2.Location = new Point(75,75); //Set label position
    ans2.Size = new Size (250,25);           
    ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans2.ForeColor = Color.Blue;                
    
    radioButton63.Location= new Point(20,125);
    radioButton63.Size = new Size(50,25);
    radioButton63.CheckedChanged += new System.EventHandler(value6);
    
    Label ans3 = new Label();
    ans3.Text = " Julie Robert ";
    ans3.Location = new Point(75,125); //Set label position
    ans3.Size = new Size (250,25);           
    ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans3.ForeColor = Color.Blue;        
    
    // Add the RadioButtons to the GroupBox.
    groupBox.Controls.Add(radioButton61);
    groupBox.Controls.Add(radioButton62);
    groupBox.Controls.Add(radioButton63);
    groupBox.Controls.Add(ans1);
    groupBox.Controls.Add(ans2);
    groupBox.Controls.Add(ans3); 
    
    panel6.Controls.Add(Reg2);
    panel6.Controls.Add(ques1);
    panel6.Controls.Add(groupBox);    
    
 }
 
public void submit6_click( object sender, EventArgs e)
  {
  
    String b1 = ((Button)sender).Text;         
    
    if(isTrue1)
     scoreb = scoreb+1;
     isTrue1 = false;
     Console.WriteLine("Score board :"+scoreb);
 showquest7();
    
    }  
    
public void value6(object source, EventArgs e)
    {
    isTrue1 = radioButton63.Checked;
     } 
     
public void showquest7()
   {
        
     panel6.Dispose();
     panel7.Location = new Point(50,60);
     panel7.Size = new Size(485, 320);
     panel7.BackColor = Color.Cyan; 
     this.Controls.Add(panel7); 
     
     Button Reg2 = new Button();
     Reg2.Text= "Score Board";
     Reg2.Location= new Point(200,270);
     Reg2.Size = new Size(125,25);
     Reg2.Font= new Font("verdana",10,FontStyle.Bold);
     Reg2.BackColor=Color.Red;
     Reg2.ForeColor=Color.Cyan; 
     
     Reg2.Click+= new EventHandler(submit7_click);
     
     Label ques1 = new Label();
     ques1.Text = "Question 10: Who is Oscar winner this Year for the Best Actor?";                           
     ques1.Location = new Point(10,20); //Set label position
     ques1.Size = new Size (475,40); 
     ques1.ForeColor = Color.Red; 
     ques1.Font = new Font ("Verdana", 10,FontStyle.Bold); 
    
    GroupBox groupBox =new GroupBox();
    groupBox.Text = "Answer";
    groupBox.Location= new Point(50,60);
    groupBox.Size = new Size(400,175);   
    
    radioButton71.Location= new Point(20,25);
    radioButton71.Size = new Size(50,25);
    radioButton71.CheckedChanged += new System.EventHandler(value7);
  
    Label ans1 = new Label();
    ans1.Text = " Tom Hank";
    ans1.Location = new Point(75,25); //Set label position
    ans1.Size = new Size (250,25);            
    ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans1.ForeColor = Color.Blue;  
                              
    radioButton72.Location= new Point(20,75);
    radioButton72.Size = new Size(50,25);
    radioButton72.CheckedChanged += new System.EventHandler(value7);
    
    Label ans2 = new Label();
    ans2.Text = " Harison Ford ";
    ans2.Location = new Point(75,75); //Set label position
    ans2.Size = new Size (250,25);           
    ans2.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans2.ForeColor = Color.Blue;                
    
    radioButton73.Location= new Point(20,125);
    radioButton73.Size = new Size(50,25);
    radioButton73.CheckedChanged += new System.EventHandler(value7);
    
    Label ans3 = new Label();
    ans3.Text = "Russel Crow";
    ans3.Location = new Point(75,125); //Set label position
    ans3.Size = new Size (250,25);           
    ans3.Font = new Font ("Verdana", 10,FontStyle.Bold);
    ans3.ForeColor = Color.Blue;        
    
    // Add the RadioButtons to the GroupBox.
    groupBox.Controls.Add(radioButton71);
    groupBox.Controls.Add(radioButton72);
    groupBox.Controls.Add(radioButton73);
    groupBox.Controls.Add(ans1);
    groupBox.Controls.Add(ans2);
    groupBox.Controls.Add(ans3);              
    
    panel7.Controls.Add(Reg2);
    panel7.Controls.Add(ques1);
    panel7.Controls.Add(groupBox); 
    }
                                         
 public void submit7_click( object sender, EventArgs e)
   {                        
     String b1 = ((Button)sender).Text;          
     if(isTrue1)
     scoreb = scoreb+1;
     isTrue1 = false;
     Console.WriteLine("Score board :"+scoreb);
 scoreboard();
    }  
    
public void value7(object source, EventArgs e)
   {
     isTrue1 = radioButton73.Checked;
   }
   
   
public void scoreboard ()
 {
   panel7.Dispose();
   
   Label ans1 = new Label();
   ans1.Text = "Your Score is : "+ scoreb;
   ans1.Location = new Point(200,75); //Set label position
   ans1.Size = new Size (250,25);           
   ans1.Font = new Font ("Verdana", 10,FontStyle.Bold);
   ans1.ForeColor = Color.Blue;  
   
   this.Text= "Score Board";
   this.Controls.Add(ans1);
 }
}


public class Client:Form
 {
   Form app1;
   TextBox Ft_name = new TextBox();
   TextBox Lt_name = new TextBox();
   TextBox emait = new TextBox();
   TextBox t_add = new TextBox();
   TextBox t_pass = new TextBox();
   TextBox t_pho = new TextBox();
   ComboBox cb = new ComboBox();
   Button submit = new Button();
   
   public Client(Form app)
     {
       app1 = app;
         
       this.Text = "Client GUI";// This will set Title for application window
       this.Size = new Size(400,500);
       this.MaximizeBox = false;//window can not be maximized by setting this property.
       this.BackColor = Color.Pink; 
       this.StartPosition = FormStartPosition.CenterScreen;// set window in the middle of screen.
       this.FormBorderStyle = FormBorderStyle.Fixed3D;// setting this property window can not be resize. 
       this.AutoScroll = true;
       this.AcceptButton=submit;
       
    textBox() ;
      }
      
      
    public void textBox()
     {
       Console.WriteLine("Inside textBox function");
      
       Label Fl_name = new Label();
       Fl_name.Text = "First Name :";
       Fl_name.Location = new Point(10,10); //Set label position
       Fl_name.Size = new Size (112,23);           
       Fl_name.Font = new Font ("Verdana", 10,FontStyle.Italic);
       Fl_name.ForeColor = Color.Red;                
       this.Controls.Add(Fl_name);//Adding label into the form
       
        Ft_name.TabIndex = 0;
        Ft_name.Location = new Point(125,10);
        Ft_name.Size = new Size (232,20);
        Ft_name.Font = new Font ("Arial", 10,FontStyle.Bold);
        Ft_name.MaxLength = 15;// Only 15 or less than 15 characyters can be enter in the textbox.
        Ft_name.BorderStyle= System.Windows.Forms.BorderStyle.Fixed3D;
        this.Controls.Add( Ft_name);
        
        Label Ll_name = new Label();//Last name
        Ll_name.Text = "Last Name :";
        Ll_name.Location = new Point(10,45);  
        Ll_name.Size = new Size (112,23);           
        Ll_name.Font = new Font ("Verdana", 10);
        Ll_name.ForeColor = Color.Red;                
        this.Controls.Add(Ll_name);
        
        Lt_name.TabIndex = 1;
        Lt_name.Location = new Point(125,45);
        Lt_name.Size = new Size (232,20);
        Lt_name.Font = new Font ("Arial", 10,FontStyle.Bold);
        Lt_name.BorderStyle= System.Windows.Forms.BorderStyle.Fixed3D;
        Lt_name.MaxLength = 15;  
        this.Controls.Add(Lt_name); 
        
        
        Label email = new Label();//Email
        email.Text = "Email ID :";
        email.Location = new Point(10,75);  
        email.Size = new Size (112,23);           
        email.Font = new Font ("Verdana", 10);
        email.ForeColor = Color.Red;                
        this.Controls.Add(email);
        
        emait.TabIndex = 2;
        emait.Location = new Point(125,75);
        emait.Size = new Size (232,20);
        emait.Font = new Font ("Arial", 10,FontStyle.Bold);
        emait.BorderStyle= System.Windows.Forms.BorderStyle.Fixed3D;
        emait.MaxLength = 40;         
        this.Controls.Add(emait); 
        
        
        Label l_add = new Label();//Address 
        l_add.Text = "Address :";
        l_add.Location = new Point(10,110);  
        l_add.Size = new Size (112,23);           
        l_add.Font = new Font ("Verdana", 10);
        l_add.ForeColor = Color.Red;                
        this.Controls.Add(l_add);
        
        
        t_add.TabIndex = 2;
        t_add.Location = new Point(125,110);
        t_add.Size = new Size (232,20);
        t_add.Font = new Font ("Arial", 10,FontStyle.Bold);
        t_add.BorderStyle= System.Windows.Forms.BorderStyle.Fixed3D;
        t_add.MaxLength = 50; 
        this.Controls.Add(t_add); 
        
        Label l_pass = new Label();//Password
        l_pass.Text = "Password :";
        l_pass.Location = new Point(10,145);  
        l_pass.Size = new Size (112,23);           
        l_pass.Font = new Font ("Verdana", 10);
        l_pass.ForeColor = Color.Red;                
        this.Controls.Add(l_pass);
        
        t_pass.TabIndex = 3;
        t_pass.Location = new Point(125,145);
        t_pass.Size = new Size (232,20);
        t_pass.Font = new Font ("Arial", 10,FontStyle.Bold);
        t_pass.PasswordChar = '*';// setting "*" to display for entered data in the text box.
        t_pass.BorderStyle= System.Windows.Forms.BorderStyle.Fixed3D;
        t_pass.MaxLength = 12; 
        this.Controls.Add(t_pass); 
        
        Label l_pho = new Label();//Phone
        l_pho.Text = "Phone Number :";
        l_pho.Location = new Point(10,180);  
        l_pho.Size = new Size (118,23);           
        l_pho.Font = new Font ("Verdana", 10);
        l_pho.ForeColor = Color.Red;                
        this.Controls.Add(l_pho);
        
        t_pho.TabIndex = 4;
        t_pho.Location = new Point(125,180);
        t_pho.Size = new Size (232,20);
        t_pho.Font = new Font ("Arial", 10,FontStyle.Bold);
        t_pho.BorderStyle= System.Windows.Forms.BorderStyle.Fixed3D;
        t_pho.MaxLength = 12; 
        this.Controls.Add(t_pho); 
        
        Label l_sub = new Label();//Check box label
        
        l_sub.Text = "Subcription :";
        l_sub.Location = new Point(10,215);  
        l_sub.Size = new Size (112,23);           
        l_sub.Font = new Font ("Verdana", 10);
        l_sub.ForeColor = Color.Red;                
        this.Controls.Add(l_sub);
        
        Label l_rb1 = new Label();// RadioButton 1 label
        l_rb1.Text = " Weekly ";
        l_rb1.Location = new Point(140,230);  
        l_rb1.Size = new Size (60,17);           
        l_rb1.Font = new Font ("Verdana", 10);
        l_rb1.ForeColor = Color.Blue;    
        this.Controls.Add(l_rb1);             
        
        RadioButton rb1=new  RadioButton();
        rb1.TabIndex =5;
        rb1.Location = new Point(205,228);     
        rb1.Checked = true;                
        this.Controls.Add(rb1);             
        
        Label l_rb2 = new Label();// RadioButton  2
        l_rb2.Text = " Monthly ";
        l_rb2.Location = new Point(140,255);  
        l_rb2.Size = new Size (66,17);           
        l_rb2.Font = new Font ("Verdana", 10);
        l_rb2.ForeColor = Color.Blue;                
        this.Controls.Add(l_rb2);          
        
        RadioButton rb2=new  RadioButton();
        rb2.TabIndex =6;
        rb2.Location = new Point(205,255);              
        this.Controls.Add(rb2);
        
        Label l_rb3 = new Label();// RadioButton 3
        l_rb3.Text = " Yearly ";
        l_rb3.Location = new Point(140,285);  
        l_rb3.Size = new Size (66,17);           
        l_rb3.Font = new Font ("Verdana", 10);
        l_rb3.ForeColor = Color.Blue;                
        this.Controls.Add(l_rb3);
        
        RadioButton rb3 = new RadioButton();
        rb3.TabIndex =7;
        rb3.Location = new Point(205,282);             
        this.Controls.Add(rb3); 
        
        Label l_tech = new Label();
        l_tech.Text = "Technology :";
        l_tech.Location = new Point(10,310);
        l_tech.Size = new Size(112,23);                    
        l_tech.Font = new Font ("Verdana", 10);
        l_tech.ForeColor = Color.Red;                
        this.Controls.Add(l_tech);
        
        Label l_chk1 = new Label();//Check box label
        l_chk1.Text = "Java ";
        l_chk1.Location = new Point(125,325);  
        l_chk1.Size = new Size (50,17);           
        l_chk1.Font = new Font ("Verdana", 10);
        l_chk1.ForeColor = Color.Blue;                 
        this.Controls.Add(l_chk1);
        
        CheckBox chk1=new CheckBox();
        chk1.TabIndex = 8;
        chk1.Location = new Point(185,322); 
        chk1.Width = 35 ;              
        chk1.Checked= true;
        this.Controls.Add(chk1);
        
        Label l_chk2 = new Label();//Check box label--vertical
        l_chk2.Text = "C Sharp(C#) ";
        l_chk2.Location = new Point(125,355);  
        l_chk2.Size = new Size (60,17);           
        l_chk2.Font = new Font ("Verdana", 10);
        l_chk2.ForeColor = Color.Blue;                
        this.Controls.Add(l_chk2);
        
        CheckBox chk2=new CheckBox();
        chk2.TabIndex = 9;
        chk2.Location = new Point(185,352); 
        chk2.Width = 35 ; 
        this.Controls.Add(chk2);
        
        Label hl_chk1 = new Label();//Check box label--horizontal
        hl_chk1.Text = " ASP ";
        hl_chk1.Location = new Point(250,325);  
        hl_chk1.Size = new Size (60,17);           
        hl_chk1.Font = new Font ("Verdana", 10);
        hl_chk1.ForeColor = Color.Blue;                
        this.Controls.Add(hl_chk1);
        
        CheckBox chkh1=new CheckBox();
        chkh1.TabIndex = 9;
        chkh1.Location = new Point(310,322); 
        chkh1.Width = 35 ;
        this.Controls.Add(chkh1); 
        
        Label hl_chk2 = new Label();//Check box label--horizontal
        hl_chk2.Text = " VB ";
        hl_chk2.Location = new Point(250,355);  
        hl_chk2.Size = new Size (60,17);           
        hl_chk2.Font = new Font ("Verdana", 10);
        hl_chk2.ForeColor = Color.Blue;                
        this.Controls.Add(hl_chk2);
        
        CheckBox chkh2=new CheckBox();
        chkh2.TabIndex = 10;
        chkh2.Location = new Point(310,352); 
        chkh2.Width = 35 ;
        this.Controls.Add(chkh2);  
        
        Label l_cb = new Label();//ComboBox label
        l_cb .Text = " Experience :";
        l_cb .Location = new Point(10,380);  
        l_cb .Size = new Size (100,17);           
        l_cb .Font = new Font ("Verdana", 10);
        l_cb .ForeColor = Color.Red;                
        this.Controls.Add(l_cb );
        
        
        cb.Location = new Point(125,380);
        cb .Size = new Size (232,20); 
        cb .Font = new Font ("Verdana", 10);
        cb.Text= " Select One Option ";
        cb.Items.Add("Freshers");  
        cb.Items.Add("Less than 6 Months");  
        cb.Items.Add("From  6 Months To 2 Years");  
        cb.Items.Add("From  2 Months To 5 Years");  
        cb.Items.Add("From  5 Months To 10 Years");  
        cb.Items.Add("Above 10 Years");  
        this.Controls.Add(cb );
        
        
        submit.Text= "Submit";
        submit.Location= new Point(100,430);
        submit.Size = new Size(75,25);
        submit.Font= new Font("verdana",10,FontStyle.Bold);
        submit.BackColor=Color.Red;
        submit.ForeColor=Color.Yellow;
        submit.Click+= new EventHandler(submit_click);        
        this.Controls.Add(submit);
        
        Button reset = new Button();
        reset.Text= " Reset";
        reset.Location= new Point(200,430);
        reset.Size = new Size(75,25);
        reset.Font= new Font("verdana",10,FontStyle.Bold);
        reset.ForeColor=Color.Yellow; 
        reset.BackColor=Color.Red;
        reset.Click+= new EventHandler(reset_click);
        this.Controls.Add(reset);                   
     }
     
  public void submit_click( object sender, EventArgs e)
    {
   
     Boolean flag = true;
                       
      String s =Ft_name.Text;
      if(s=="")
       {
         MessageBox.Show("Please enter First Name ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
         flag = false;
         Ft_name.Focus();
        }
      else
       {
        String s1 =Lt_name.Text;
        
        if(s1=="")
          {
           MessageBox.Show("Please enter Last Name ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
           flag = false;
           Lt_name.Focus();
          }
        else
         {
          String s2 =t_add.Text;   
   
          if(s2=="")
           {
             MessageBox.Show("Please enter Address ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
             flag = false;
             t_add.Focus();            
           }  
         else
          {
            String s3 =t_pass.Text;  
         
      if(s3=="")
       {
         MessageBox.Show("Please enter Password ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
         flag = false;
         t_pass.Focus();      
             }  
          
           else
            {
             String s4 =t_pho.Text;   
      
        if(s4=="")
         {
          MessageBox.Show("Please enter Phone Number ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
          flag = false;
          t_pho.Focus();        
               } 
             else
              {
                 String s5 =emait.Text;   
    
          if(s5=="")
            {
      MessageBox.Show("Please enter Email Id ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
      flag = false;
      emait.Focus();        
                  }
                else
                  if(emait.Text.IndexOf(".") == -1 || emait.Text.IndexOf("@") == -1)
                    {
                     MessageBox.Show("Please check for . and @ in the Email Id ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
         flag = false;
         emait.Focus();
                    }
                  else
                   {
                    String s6 =cb.Text;   
       
        if(s6==" Select One Option ")
         {
          MessageBox.Show("Please select proper Experience  ","Confirmation Message",MessageBoxButtons.OK,MessageBoxIcon.Information); 
                flag = false;
          cb.Focus();       
                     }
                   }            
                 }                  
         }
       }
     }
  }
     
      if(flag)
      {
        
        this.Dispose();
        Console.WriteLine("after disposing");
        app1.Show();      
        Label message = new Label();
        message.Text = "Form has been submited Successfully :";
        message.Location = new Point(110,5); //Set label position
        message.Size = new Size (300,20);           
        message.Font = new Font ("Verdana", 10,FontStyle.Italic);
        message.ForeColor = Color.Green;                
        app1.Controls.Add(message);//Adding label into the form          
        
        } 
     } 
     
    public void reset_click( object sender, EventArgs e)
     {
       Console.WriteLine(" In side Reset");
       Ft_name.Text =""; 
       Lt_name.Text ="";
       emait.Text ="";
       t_add.Text ="";
       t_add.Text ="";
       t_pass.Text ="";
       t_pho.Text ="";
       cb.Text= "Select One Option";
       Ft_name.Focus();       
      }      
  
}