Your Ads Here

Showing posts with label learing. Show all posts
Showing posts with label learing. Show all posts

Wednesday, 2 May 2012

Application.DoEvents Method in C#.NET


It Shows the description for the working of Application.DoEvents in C#.NET
It Processes all Windows messages currently in the message queue.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

‘Declaration
Application.DoEvents();

When you run a Windows Form, it creates the new form, which then waits for events to handle. Each time the form handles an event, it processes all the code associated with that event. All other events wait in the queue. While your code handles the event, your application does not respond. For example, the window does not repaint if another window is dragged on top.
If you call DoEvents in your code, your application can handle the other events. For example, if you have a form that adds data to a ListBox and add DoEvents to your code, your form repaints when another window is dragged over it. If you remove DoEvents from your code, your form will not repaint until the click event handler of the button is finished executing. 

Caution
Calling this method causes the current thread to be suspended while all waiting window messages are processed. If a message causes an event to be triggered, then other areas of your application code may execute. This can cause your application to exhibit unexpected behaviors that are difficult to debug. If you perform operations or computations that take a long time, it is often preferable to perform those operations on a new thread. For more information about asynchronous programming,

Wednesday, 8 February 2012

lists of the important classes and enumerations in theSystem.Drawing.Drawing2D namespace.


Graphics and Graphics paths 

The GraphicsState and GraphicsContainer classes report information about the current Graphics object. GraphicsPath classes represent a series of lines and curves. The GraphicsPathIterator and PathData classes provide detailed information about the contents of a GraphicsPath object.
Matrix and transformation related types
The Matrix class represents a matrix for geometric transforms. The MatrixOrder enumeration specifies the order for matrix transformations.
Brush classes
The PathGradientBrush and HatchBrush classes enable you to fill shapes with either a gradient, or hatch pattern, respectively.
Enumeration related to lines
The LineCap and CustomLineCap enumerations enable you to specify cap styles for a line. The, LineJoin enumeration enables you to specify how two lines are joined in a path. The PenAlignment enumeration enables you specify the alignment of the drawing tip, when you draw a line. The PenType enumeration specifies the pattern a line should be filled with.
Enumerations related to filling shapes and paths
The HatchStyle enumeration specifies fill styles for a HatchBrush. The Blend class specifies a blend pattern for a LinearGradientBrush. The FillMode enumeration specifies the fill style for a GraphicsPath.


 
Class
Description
Public class
AdjustableArrowCap
Represents an adjustable arrow-shaped line cap. This class cannot be inherited.
Public class
Blend
Defines a blend pattern for a LinearGradientBrush object. This class cannot be inherited.
Public class
ColorBlend
Defines arrays of colors and positions used for interpolating color blending in a multicolor gradient. This class cannot be inherited.
Public class
CustomLineCap
Encapsulates a custom user-defined line cap.
Public class
GraphicsContainer
Represents the internal data of a graphics container. This class is used when saving the state of a Graphics object using the BeginContainer and EndContainer methods. This class cannot be inherited.
Public class
GraphicsPath
Represents a series of connected lines and curves. This class cannot be inherited.
Public class
GraphicsPathIterator
Provides the ability to iterate through subpaths in a GraphicsPath and test the types of shapes contained in each subpath. This class cannot be inherited.
Public class
GraphicsState
Represents the state of a Graphics object. This object is returned by a call to the Save methods. This class cannot be inherited.
Public class
HatchBrush
Defines a rectangular brush with a hatch style, a foreground color, and a background color. This class cannot be inherited.
Public class
LinearGradientBrush
Encapsulates a Brush with a linear gradient. This class cannot be inherited.
Public class
Matrix
Encapsulates a 3-by-3 affine matrix that represents a geometric transform. This class cannot be inherited.
Public class
PathData
Contains the graphical data that makes up a GraphicsPath object. This class cannot be inherited.
Public class
PathGradientBrush
Encapsulates a Brush object that fills the interior of a GraphicsPath object with a gradient. This class cannot be inherited.
Public class
RegionData
Encapsulates the data that makes up a Region object. This class cannot be inherited.

 
Enumeration
Description
Public enumeration
CombineMode
Specifies how different clipping regions can be combined.
Public enumeration
CompositingMode
Specifies how the source colors are combined with the background colors.
Public enumeration
CompositingQuality
Specifies the quality level to use during compositing.
Public enumeration
CoordinateSpace
Specifies the system to use when evaluating coordinates.
Public enumeration
DashCap
Specifies the type of graphic shape to use on both ends of each dash in a dashed line.
Public enumeration
DashStyle
Specifies the style of dashed lines drawn with a Pen object.
Public enumeration
FillMode
Specifies how the interior of a closed path is filled.
Public enumeration
FlushIntention
Specifies whether commands in the graphics stack are terminated (flushed) immediately or executed as soon as possible.
Public enumeration
HatchStyle
Specifies the different patterns available for HatchBrush objects.
Public enumeration
InterpolationMode
The InterpolationMode enumeration specifies the algorithm that is used when images are scaled or rotated.
Public enumeration
LinearGradientMode
Specifies the direction of a linear gradient.
Public enumeration
LineCap
Specifies the available cap styles with which a Pen object can end a line.
Public enumeration
LineJoin
Specifies how to join consecutive line or curve segments in a figure (subpath) contained in a GraphicsPath object.
Public enumeration
MatrixOrder
Specifies the order for matrix transform operations.
Public enumeration
PathPointType
Specifies the type of point in a GraphicsPath object.
Public enumeration
PenAlignment
Specifies the alignment of a Pen object in relation to the theoretical, zero-width line.
Public enumeration
PenType
Specifies the type of fill a Pen object uses to fill lines.
Public enumeration
PixelOffsetMode
Specifies how pixels are offset during rendering.
Public enumeration
QualityMode
Specifies the overall quality when rendering GDI+ objects.
Public enumeration
SmoothingMode
Specifies whether smoothing (antialiasing) is applied to lines and curves and the edges of filled areas.
Public enumeration
WarpMode
Specifies the type of warp transformation applied in a Warp method.
Public enumeration
WrapMode
Specifies how a texture or gradient is tiled when it is smaller than the area being filled.

Monday, 6 February 2012

Make a countdown timer in C#.NET


This example shows how to make a countdown timer in C#.NET
Keywords: countdown timer, timer, alarm, CSharp.NET, C#.NET

If you enter a duration in the format h:mm:ss and click the button, the following code converts your text into a TimeSpan and adds it to the current time. It saves the result in m_StopTime and enables the timer1 timer.

private void button1_Click(object sender, EventArgs e)
        {
            TimeSpan duration = TimeSpan.Parse(textBox1.Text);
            m_StopTime = DateTime.Now.Add(duration);
            
           timer1.Enabled = true;
        }

When the timer fires, it calculates the difference between the current time and the desired stop time and displays the time remaining in the label lblRemaining. Then if the total seconds remaining is zero, the program maximizes its form and makes its form topmost so it appears above all other forms, hopefully attracting your attention.


private void timer1_Tick(object sender, EventArgs e)
        {
            TimeSpan remaining = m_StopTime.Subtract(DateTime.Now);
            remaining = new TimeSpan(remaining.Hours, remaining.Minutes, remaining.Seconds);
            if (remaining.TotalSeconds < 0)
                remaining = TimeSpan.Zero;

            label1.Text = remaining.ToString();

            if (remaining.TotalSeconds <= 0)
            {
                this.WindowState = FormWindowState.Maximized;
                this.TopMost = true;
                timer1.Enabled = false;
            }
        }

 
Here the full code.

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

namespace testc
{

    public partial class Form1 : Form
    {
        System.DateTime m_StopTime = default(System.DateTime);
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            TimeSpan duration = TimeSpan.Parse(textBox1.Text);
            m_StopTime = DateTime.Now.Add(duration);
            
           timer1.Enabled = true;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            TimeSpan remaining = m_StopTime.Subtract(DateTime.Now);
            remaining = new TimeSpan(remaining.Hours, remaining.Minutes,
                remaining.Seconds);
            if (remaining.TotalSeconds < 0)
                remaining = TimeSpan.Zero;

            label1.Text = remaining.ToString();

            if (remaining.TotalSeconds <= 0)
            {
                this.WindowState = FormWindowState.Maximized;
                this.TopMost = true;
                timer1.Enabled = false;
            }
        }
    }
}