Click here to Skip to main content
15,894,343 members
Home / Discussions / C#
   

C#

 
Questiontextbox change event Pin
Erdinc2715-Oct-10 2:07
Erdinc2715-Oct-10 2:07 
AnswerRe: textbox change event Pin
Not Active15-Oct-10 2:15
mentorNot Active15-Oct-10 2:15 
GeneralRe: textbox change event Pin
Erdinc2715-Oct-10 2:28
Erdinc2715-Oct-10 2:28 
GeneralRe: textbox change event Pin
Not Active15-Oct-10 2:32
mentorNot Active15-Oct-10 2:32 
GeneralRe: textbox change event Pin
Erdinc2715-Oct-10 2:38
Erdinc2715-Oct-10 2:38 
QuestionMessage Removed Pin
14-Oct-10 23:18
Pawan Kiran14-Oct-10 23:18 
AnswerRe: How to Prompt a Message When Cell Value is changed and Leaves CurrentRow Without Saving? Pin
Henry Minute15-Oct-10 0:32
Henry Minute15-Oct-10 0:32 
Questionhow to draw a rectangle on the picture box Pin
ash_ng14-Oct-10 22:49
ash_ng14-Oct-10 22:49 
This is my code.I was asked to draw a rectangle on the picture box.When i run the program,i can only draw the rectangle on the form but not the picture box.Kindly assist as i am a first timer to C#.

C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        Boolean bHaveMouse;
        Point ptOriginal = new Point();
        Point ptLast = new Point();

        // Called when the left mouse button is pressed. 
        public void MyMouseDown(Object sender, MouseEventArgs e)
        {
            // Make a note that we "have the mouse".
            bHaveMouse = true;
            // Store the "starting point" for this rubber-band rectangle.
            ptOriginal.X = e.X;
            ptOriginal.Y = e.Y;
            // Special value lets us know that no previous
            // rectangle needs to be erased.
            ptLast.X = -1;
            ptLast.Y = -1;
        }
        // Convert and normalize the points and draw the reversible frame.
        private void MyDrawReversibleRectangle(Point p1, Point p2)
        {
            Rectangle rc = new Rectangle();

            // Convert the points to screen coordinates.
            p1 = PointToScreen(p1);
            p2 = PointToScreen(p2);
            // Normalize the rectangle.
            if (p1.X < p2.X)
            {
                rc.X = p1.X;
                rc.Width = p2.X - p1.X;
            }
            else
            {
                rc.X = p2.X;
                rc.Width = p1.X - p2.X;
            }
            if (p1.Y < p2.Y)
            {
                rc.Y = p1.Y;
                rc.Height = p2.Y - p1.Y;
            }
            else
            {
                rc.Y = p2.Y;
                rc.Height = p1.Y - p2.Y;
            }
            // Draw the reversible frame.
            ControlPaint.DrawReversibleFrame(rc,
                            Color.Black, FrameStyle.Thick);
           
        }
        // Called when the left mouse button is released.
        public void MyMouseUp(Object sender, MouseEventArgs e)
        {
            // Set internal flag to know we no longer "have the mouse".
            bHaveMouse = false;
             //If we have drawn previously, draw again in that spot
            // to remove the lines.
           // if (ptLast.X != -1)
           // {
            //    Point ptCurrent = new Point(e.X, e.Y);
             //   MyDrawReversibleRectangle(ptOriginal, ptLast);
           // }
            // Set flags to know that there is no "previous" line to reverse.
            ptLast.X = -1;
            ptLast.Y = -1;
           ptOriginal.X = -1;
            ptOriginal.Y = -1;
        }
        // Called when the mouse is moved.
        public void MyMouseMove(Object sender, MouseEventArgs e)
        {
            Point ptCurrent = new Point(e.X, e.Y);
            // If we "have the mouse", then we draw our lines.
            if (bHaveMouse)
            {
                // If we have drawn previously, draw again in
                // that spot to remove the lines.
                if (ptLast.X != -1)
                {
                  MyDrawReversibleRectangle(ptOriginal, ptLast);
                }
                // Update last point.
                ptLast = ptCurrent;
                // Draw new lines.
                MyDrawReversibleRectangle(ptOriginal, ptCurrent);
            }
        }
        // Set up delegates for mouse events.
        protected override void OnLoad(System.EventArgs e)
        {
            MouseDown += new MouseEventHandler(MyMouseDown);
            MouseUp += new MouseEventHandler(MyMouseUp);
            MouseMove += new MouseEventHandler(MyMouseMove);
            bHaveMouse = false;
        }

       

    }
}

AnswerRe: how to draw a rectangle on the picture box Pin
Henry Minute14-Oct-10 23:19
Henry Minute14-Oct-10 23:19 
GeneralRe: how to draw a rectangle on the picture box Pin
ash_ng14-Oct-10 23:30
ash_ng14-Oct-10 23:30 
GeneralRe: how to draw a rectangle on the picture box Pin
Henry Minute14-Oct-10 23:44
Henry Minute14-Oct-10 23:44 
AnswerRe: how to draw a rectangle on the picture box Pin
Pete O'Hanlon14-Oct-10 23:41
mvePete O'Hanlon14-Oct-10 23:41 
QuestionForm loses focus [modified] Pin
electriac14-Oct-10 13:05
electriac14-Oct-10 13:05 
AnswerRe: Form loses focus Pin
fjdiewornncalwe14-Oct-10 13:17
professionalfjdiewornncalwe14-Oct-10 13:17 
GeneralRe: Form loses focus Pin
electriac14-Oct-10 13:24
electriac14-Oct-10 13:24 
GeneralRe: Form loses focus Pin
Nish Nishant14-Oct-10 13:33
sitebuilderNish Nishant14-Oct-10 13:33 
GeneralRe: Form loses focus Pin
fjdiewornncalwe14-Oct-10 13:35
professionalfjdiewornncalwe14-Oct-10 13:35 
GeneralRe: Form loses focus Pin
electriac14-Oct-10 14:00
electriac14-Oct-10 14:00 
GeneralRe: Form loses focus [modified] Pin
fjdiewornncalwe14-Oct-10 14:08
professionalfjdiewornncalwe14-Oct-10 14:08 
GeneralRe: Form loses focus Pin
electriac14-Oct-10 14:14
electriac14-Oct-10 14:14 
GeneralRe: Form loses focus Pin
OriginalGriff15-Oct-10 2:03
mveOriginalGriff15-Oct-10 2:03 
GeneralRe: Form loses focus Pin
fjdiewornncalwe15-Oct-10 4:32
professionalfjdiewornncalwe15-Oct-10 4:32 
QuestionRe: Form loses focus Pin
Luc Pattyn15-Oct-10 2:19
sitebuilderLuc Pattyn15-Oct-10 2:19 
AnswerRe: Form loses focus Pin
electriac15-Oct-10 2:35
electriac15-Oct-10 2:35 
GeneralRe: Form loses focus Pin
Luc Pattyn15-Oct-10 2:46
sitebuilderLuc Pattyn15-Oct-10 2:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.