Your Ads Here

Friday, 4 May 2012

Rotate Picture in PictureBox 90 degree using C#.NET


It shows to rotate image in picturebox to rotate 90 degree using C#.NET
Keywords: Rotation, rotate, 90, degree, .NET, image, CSharp.NET

For this add two controls
1)      PictureBox ( image must be added either through backgroundimage property or image property)
2)      Button

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 textcsharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int width = 0;
            int height = 0;
            int X = 0;
            int Y = 0;

            // Make a Bitmap representing the input background Image
            Bitmap img_bitmap_In = new Bitmap(pictureBox1 .BackgroundImage);
            width = img_bitmap_In.Width;
            height = img_bitmap_In.Height;

            // Make the output bitmap.
            Bitmap img_bitmap_Out = new Bitmap(height, width);

            // Copy the pixel values.
            for (X = 0; X <= width - 1; X++)
            {
                for (Y = 0; Y <= height - 1; Y++)
                {
                    img_bitmap_Out.SetPixel(height - Y - 1, X, img_bitmap_In.GetPixel(X, Y));
                }
            }

            // Display the result.
            pictureBox1.BackgroundImage = img_bitmap_Out;

        }

     
    }
}




 Note: If you have any suggestion, please contact sivodayatech@dotnetdevelopertool.com

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,

TextBox accepts only integer values using C#.NET


It shows to access only integer values using C#.NET
Keywords: Integer, textbox, .NET, CSharp.NET

Write the code in keypress event of textbox

if (!char.IsControl(e.KeyChar)
         && !char.IsDigit(e.KeyChar)
         && e.KeyChar != '.')
            {
                e.Handled = true;
            }
            // only allow one decimal point
            if (e.KeyChar == '.'
                && (sender as TextBox).Text.IndexOf('.') > -1)
            {
                e.Handled = true;
            }
 
Here the complete Code to accept only integer value

 
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 textcsharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar)
         && !char.IsDigit(e.KeyChar)
         && e.KeyChar != '.')
            {
                e.Handled = true;
            }
            // only allow one decimal point
            if (e.KeyChar == '.'
                && (sender as TextBox).Text.IndexOf('.') > -1)
            {
                e.Handled = true;
            }
        }
    }
}

Note: Be a follower to our site to promote us.  
Contact us:sivodayatech@dotnetdevelopertool.com