Saturday, July 19, 2014

How to move a Form by Dragging the Mouse over MainForm? - Visual C#

Today, i will tell you a Program to move a Form ( preferably Windows Form Application, although it can be made in WPF too) by dragging the mouse.
Here's how to do it:

1. STEP 1 - Create New WFA


If you know how to create a WFA, then Go to Step 2
  • Open Visual Studio, and Click "New Project"
  • Go to Templates > Visual C# > Windows.
  • Select Windows Form Application from the List

2. STEP 2- Adding Code
  • Go to View Menu> Properties.
  • Click on the MainForm, Properties Window will now show properties of the MainForm
  • Click on Events  ,Add 
    MouseMove
     Event.
  • Use the Following code

bool Mouse_Cord_Stored = false;
int X_Coordinate;
int Y_Coordinate;
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    switch (e.Button)
    {
        //To Let user move the Form1 when Left mouse button is pressed
        case (MouseButtons.Left): 
            {
                switch (Mouse_Cord_Stored)
                {
                    case false:
                        {
                     //If Mouse Coordinates are not stored, then to store them.
                            X_Coordinate = e.X;
                            Y_Coordinate = e.Y;
                            Mouse_Cord_Stored = true;
                            break;
                        }
                    case true:
                        {
//Move the Form using ActiveForm.Location if mouse coordinates are stored
Form1.ActiveForm.Location = 
                new Point(Form1.ActiveForm.Location.X + e.X - X_Coordinate,
                Form1.ActiveForm.Location.Y + e.Y - Y_Coordinate);
                            break;
                        }
                }
                break;
            }

        default:
            {
                switch (Mouse_Cord_Stored)
                {
                    case true:
                        {
                            Mouse_Cord_Stored = false;
                            break;
                        }
                }
                break;
            }
    }
}

Output:
Output of this Program will be a Windows Form, which can be moved by dragging MainForm

Friday, July 18, 2014

Which is the Best Book for learning C#

Which is the Best Book for learning C#?
Well, there are lots of books available in the market each has an edge over others. However after reviewing many books, i found this one to be the best:



c# in nutshell

               C# 5.0 in a Nutshell, 5th EditionThe Definitive Reference



Download Complete e-Book (PDF) C# 5.0 in Nutshell:


"C# 4.0 in a Nutshell is one of the few books I keep on my desk as a quick reference. It is a book I recommend." - Scott Guthrie, Corporate Vice President, Microsoft
Why to Buy
In the tradition of O'Reilly Nutshell guides, C# 5.0 in a Nutshell is simply the best one volume introduction and reference to the C# language availability today!
Key Features
  • The bestselling Nutshell from O'Reilly
  • Completely updated for C# 5.0
  • Highly acclaimed book and authors
  • Comprehensive and complete single reference
  • C# 5.0 in a Nutshell will build on the success of C# 3.0 in a Nutshell, providing concise and thorough information on the language and core framework in one straightforward and accessible volume.
  • C# 5.0 in a Nutshell will also feature a "What's new in C# 5.0" section, which will be of appeal to developers moving from previous C# versions.
  • Part of the book's appeal is that it's highly orthogonal in coverage - there's no "heart" around which other topics receive less attention
  • The readers will get excited primarily about the speed and ease to which they can gain information across a wide variety of topics

AUDIENCE

Anyone learning or using the C# programming language will find this book useful - either in by itself or with other C# books. Readers at all levels will be able to use this book as a reference, and readers with some prior background in C# or another programming language will be able to read this book sequentially to learn the language.
When you have a question about how to use C# 5.0 or the .NET CLR, this highly acclaimed bestseller has precisely the answers you need. Uniquely organized around concepts and use cases, this fifth edition includes in-depth coverage of concurrency and asynchrony new to C# 5.0 as well as continued coverage of parallel programming, code contracts, dynamic programming, security and COM interoperability. You'll also find updated information on language enhancements such as Caller Info Attributes, ReadOnlyDictionary, Web Sockets, and the new HttpClient class. This handy book has all you need to stay on track with C# 5.0.
  • Get up to speed on C# language basics, including syntax, types, and variables
  • Explore advanced topics such as unsafe code and preprocessor directives
  • Learn C# 5.0 features such as concurrency and asynchrony
  • Work with .NET 4.5's rich set of features for parallel programming, code contracts, and the code security model
  • Understand .NET topics, including XML, collections, I/O and networking, memory management, reflection, attributes, security, and native interoperability

About the Author



Ben Albahari is the founder of Take On It. He was a Program Manager at Microsoft for 5 years, where he worked on several projects, including the .NET Compact Framework and ADO.NET.

He was the cofounder of Genamics, a provider of tools for C# and J++ programmers, as well as software for DNA and protein sequence analysis. He is a co-author of C# Essentials, the first C# book from O'Reilly, and of previous editions of C# in a Nutshell.
Joseph is currently a freelance consultant.

Buy C# 5.0 in a Nutshell?
Click Here to Buy this Book Online 
This Book is also available at leading e-Shopping websites like Amazon, Flipkart,SnapDeal and HomeShop18. 
Download Complete e-Book (PDF) C# 5.0 in Nutshell:  
Table of Contents
  1. Chapter 1 Introducing C# and the .NET Framework

    1. Object Orientation

    2. Type Safety

    3. Memory Management

    4. Platform Support

    5. C#’s Relationship with the CLR

    6. The CLR and .NET Framework

    7. C# and Windows Runtime

    8. What’s New in C# 5.0

    9. What’s New in C# 4.0

    10. What’s New in C# 3.0

  2. Chapter 2 C# Language Basics

    1. A First C# Program

    2. Syntax

    3. Type Basics

    4. Numeric Types

    5. Boolean Type and Operators

    6. Strings and Characters

    7. Arrays

    8. Variables and Parameters

    9. Expressions and Operators

    10. Statements

    11. Namespaces

  3. Chapter 3 Creating Types in C#

    1. Classes

    2. Inheritance

    3. The object Type

    4. Structs

    5. Access Modifiers

    6. Interfaces

    7. Enums

    8. Nested Types

    9. Generics

  4. Chapter 4 Advanced C#

    1. Delegates

    2. Events

    3. Lambda Expressions

    4. Anonymous Methods

    5. try Statements and Exceptions

    6. Enumeration and Iterators

    7. Nullable Types

    8. Operator Overloading

    9. Extension Methods

    10. Anonymous Types

    11. Dynamic Binding

    12. Attributes

    13. Caller Info Attributes (C# 5)

    14. Unsafe Code and Pointers

    15. Preprocessor Directives

    16. XML Documentation

  5. Chapter 5 Framework Overview

    1. The CLR and Core Framework

    2. Applied Technologies

  6. Chapter 6 Framework Fundamentals

    1. String and Text Handling

    2. Dates and Times

    3. Dates and Time Zones

    4. Formatting and Parsing

    5. Standard Format Strings and Parsing Flags

    6. Other Conversion Mechanisms

    7. Globalization

    8. Working with Numbers

    9. Enums

    10. Tuples

    11. The Guid Struct

    12. Equality Comparison

    13. Order Comparison

    14. Utility Classes

  7. Chapter 7 Collections

    1. Enumeration

    2. The ICollection and IList Interfaces

    3. The Array Class

    4. Lists, Queues, Stacks, and Sets

    5. Dictionaries

    6. Customizable Collections and Proxies

    7. Plugging in Equality and Order

  8. Chapter 8 LINQ Queries

    1. Getting Started

    2. Fluent Syntax

    3. Query Expressions

    4. Deferred Execution

    5. Subqueries

    6. Composition Strategies

    7. Projection Strategies

    8. Interpreted Queries

    9. LINQ to SQL and Entity Framework

    10. Building Query Expressions

  9. Chapter 9 LINQ Operators

    1. Overview

    2. Filtering

    3. Projecting

    4. Joining

    5. Ordering

    6. Grouping

    7. Set Operators

    8. Conversion Methods

    9. Element Operators

    10. Aggregation Methods

    11. Quantifiers

    12. Generation Methods

  10. Chapter 10 LINQ to XML

    1. Architectural Overview

    2. X-DOM Overview

    3. Instantiating an X-DOM

    4. Navigating and Querying

    5. Updating an X-DOM

    6. Working with Values

    7. Documents and Declarations

    8. Names and Namespaces

    9. Annotations

    10. Projecting into an X-DOM

  11. Chapter 11 Other XML Technologies

    1. XmlReader

    2. XmlWriter

    3. Patterns for Using XmlReader/XmlWriter

    4. XmlDocument

    5. XPath

    6. XSD and Schema Validation

    7. XSLT

  12. Chapter 12 Disposal and Garbage Collection

    1. IDisposable, Dispose, and Close

    2. Automatic Garbage Collection

    3. Finalizers

    4. How the Garbage Collector Works

    5. Managed Memory Leaks

    6. Weak References

  13. Chapter 13 Diagnostics and Code Contracts

    1. Conditional Compilation

    2. Debug and Trace Classes

    3. Code Contracts Overview

    4. Preconditions

    5. Postconditions

    6. Assertions and Object Invariants

    7. Contracts on Interfaces and Abstract Methods

    8. Dealing with Contract Failure

    9. Selectively Enforcing Contracts

    10. Static Contract Checking

    11. Debugger Integration

    12. Processes and Process Threads

    13. StackTrace and StackFrame

    14. Windows Event Logs

    15. Performance Counters

    16. The Stopwatch Class

  14. Chapter 14 Concurrency & Asynchrony

    1. Introduction

    2. Threading

    3. Tasks

    4. Principles of Asynchrony

    5. Asynchronous Functions in C# 5.0

    6. Asynchronous Patterns

    7. Obsolete Patterns

  15. Chapter 15 Streams and I/O

    1. Stream Architecture

    2. Using Streams

    3. Stream Adapters

    4. Compression Streams

    5. Working with Zip Files

    6. File and Directory Operations

    7. File I/O in Windows Runtime

    8. Memory-Mapped Files

    9. Isolated Storage

  16. Chapter 16 Networking

    1. Network Architecture

    2. Addresses and Ports

    3. URIs

    4. Client-Side Classes

    5. Working with HTTP

    6. Writing an HTTP Server

    7. Using FTP

    8. Using DNS

    9. Sending Mail with SmtpClient

    10. Using TCP

    11. Receiving POP3 Mail with TCP

    12. TCP in Windows Runtime

  17. Chapter 17 Serialization

    1. Serialization Concepts

    2. The Data Contract Serializer

    3. Data Contracts and Collections

    4. Extending Data Contracts

    5. The Binary Serializer

    6. Binary Serialization Attributes

    7. Binary Serialization with ISerializable

    8. XML Serialization

  18. Chapter 18 Assemblies

    1. What’s in an Assembly

    2. Strong Names and Assembly Signing

    3. Assembly Names

    4. Authenticode Signing

    5. The Global Assembly Cache

    6. Resources and Satellite Assemblies

    7. Resolving and Loading Assemblies

    8. Deploying Assemblies Outside the Base Folder

    9. Packing a Single-File Executable

    10. Working with Unreferenced Assemblies

  19. Chapter 19 Reflection and Metadata

    1. Reflecting and Activating Types

    2. Reflecting and Invoking Members

    3. Reflecting Assemblies

    4. Working with Attributes

    5. Dynamic Code Generation

    6. Emitting Assemblies and Types

    7. Emitting Type Members

    8. Emitting Generic Methods and Types

    9. Awkward Emission Targets

    10. Parsing IL

  20. Chapter 20 Dynamic Programming

    1. The Dynamic Language Runtime

    2. Numeric Type Unification

    3. Dynamic Member Overload Resolution

    4. Implementing Dynamic Objects

    5. Interoperating with Dynamic Languages

  21. Chapter 21 Security

    1. Permissions

    2. Code Access Security (CAS)

    3. Allowing Partially Trusted Callers

    4. The Transparency Model

    5. Sandboxing Another Assembly

    6. Operating System Security

    7. Identity and Role Security

    8. Cryptography Overview

    9. Windows Data Protection

    10. Hashing

    11. Symmetric Encryption

    12. Public Key Encryption and Signing

  22. Chapter 22 Advanced Threading

    1. Synchronization Overview

    2. Exclusive Locking

    3. Locking and Thread Safety

    4. Non-Exclusive Locking

    5. Signaling with Event Wait Handles

    6. The Barrier Class

    7. Lazy Initialization

    8. Thread-Local Storage

    9. Interrupt and Abort

    10. Suspend and Resume

    11. Timers

  23. Chapter 23 Parallel Programming

    1. Why PFX?

    2. PLINQ

    3. The Parallel Class

    4. Task Parallelism

    5. Working with AggregateException

    6. Concurrent Collections

    7. BlockingCollection<T>

  24. Chapter 24 Application Domains

    1. Application Domain Architecture

    2. Creating and Destroying Application Domains

    3. Using Multiple Application Domains

    4. Using DoCallBack

    5. Monitoring Application Domains

    6. Domains and Threads

    7. Sharing Data Between Domains

  25. Chapter 25 Native and COM Interoperability

    1. Calling into Native DLLs

    2. Type Marshaling

    3. Callbacks from Unmanaged Code

    4. Simulating a C Union

    5. Shared Memory

    6. Mapping a Struct to Unmanaged Memory

    7. COM Interoperability

    8. Calling a COM Component from C#

    9. Embedding Interop Types

    10. Primary Interop Assemblies

    11. Exposing C# Objects to COM

  26. Chapter 26 Regular Expressions

    1. Regular Expression Basics

    2. Quantifiers

    3. Zero-Width Assertions

    4. Groups

    5. Replacing and Splitting Text

    6. Cookbook Regular Expressions

    7. Regular Expressions Language Reference

  1. Colophon

Please do not forget to share this post