Click here to Skip to main content
15,889,403 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help ploting Excel graph in C# Pin
Henry Minute31-May-10 1:23
Henry Minute31-May-10 1:23 
GeneralRe: Help ploting Excel graph in C# Pin
Mc_Topaz31-May-10 2:29
Mc_Topaz31-May-10 2:29 
GeneralRe: Help ploting Excel graph in C# Pin
Henry Minute31-May-10 2:51
Henry Minute31-May-10 2:51 
Questiondarw rectangle modification.... [modified] Pin
Nivas8230-May-10 22:42
Nivas8230-May-10 22:42 
AnswerRe: darw rectangle modification.... Pin
OriginalGriff30-May-10 23:00
mveOriginalGriff30-May-10 23:00 
GeneralRe: darw rectangle modification.... Pin
Nivas8231-May-10 18:53
Nivas8231-May-10 18:53 
GeneralRe: darw rectangle modification.... Pin
OriginalGriff31-May-10 22:13
mveOriginalGriff31-May-10 22:13 
GeneralRe: darw rectangle modification.... Pin
Nivas821-Jun-10 22:17
Nivas821-Jun-10 22:17 
Have change the code little bit. Instead of mouse move event used Mouse click event.

On using mouse move event it calls every time when mouse move on the picture box. so list rectangle count gets increased. for this i used mouse click event.

When list rectangle added in Mouse down event, it's only get the values for height and width of the rectangle (if use (0,0,e.X,e.Y))and also rectangle always starts from top left corner (not able to start the rectangle point where user likes) and it's gets only X and Y values (if use(e.X, e.Y,0,0))

to over come this I used the list rectangle in the mouse click event, so I get all values.



List<Rectangle> rectangles = new List<Rectangle>();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (stayToolStripMenuItem.Checked == true)
            {

                if (mybitmap == null)
                {
                    mybitmap = new Bitmap(sz.Width, sz.Height);

                }
                rect = new Rectangle(e.X, e.Y, 0, 0);
                this.Invalidate();

            }
             
        }

       
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            if (stayToolStripMenuItem.Checked == true)
            {
                button1.Visible = true;
                button2.Visible = true;

                if (mybitmap == null)
                {
                    return;
                }

                
                    using (g = Graphics.FromImage(mybitmap))
                    {

                        using (Pen pen = new Pen(Color.Red, 2))
                        {
                            //g.Clear(Color.Transparent);


                            e.Graphics.DrawRectangle(pen, rect);
                            label1.Top = rect.Top; label1.Left = rect.Left; label1.Width = rect.Width;
                            label1.Height = rect.Height;


                            if (label1.TextAlign == ContentAlignment.TopLeft)
                            {
                                e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect);
                                g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect);
                                g.DrawRectangle(pen, rect);

                            }

                        }

                    }

private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            
                if (e.Button == MouseButtons.Left)
                
                {
                    rect = new Rectangle(rect.Left, rect.Top, e.X - rect.Left, e.Y - rect.Top);
                    rectangles.Add(rect);
                    pictureBox1.Invalidate();
                    f = 0;

                }

           
        }


thanks Griff for advising to use list rectangles.

What ever rectangle I draw get saved in the list rectangles and get saved when i saved the work (could see all the drawn rectangles when i opened the saved file).

Now the problem is, when I draw a new rectangle the previous one get disappeared (on run time. However this added in list rectangle).

How to display all the rectangles drawn on run time, so user can know how many rectangles drawn and where.
GeneralRe: darw rectangle modification.... Pin
OriginalGriff1-Jun-10 22:59
mveOriginalGriff1-Jun-10 22:59 
AnswerRe: darw rectangle modification.... [modified] Pin
Nivas822-Jun-10 19:18
Nivas822-Jun-10 19:18 
GeneralRe: darw rectangle modification.... Pin
Nivas827-Jun-10 21:39
Nivas827-Jun-10 21:39 
AnswerRe: darw rectangle modification.... Pin
Luc Pattyn31-May-10 1:57
sitebuilderLuc Pattyn31-May-10 1:57 
GeneralRe: darw rectangle modification.... Pin
Nivas8231-May-10 19:02
Nivas8231-May-10 19:02 
GeneralRe: darw rectangle modification.... Pin
Luc Pattyn1-Jun-10 1:48
sitebuilderLuc Pattyn1-Jun-10 1:48 
QuestionA Question Of Focus and Tab Indices [Solved] Pin
Roger Wright30-May-10 22:20
professionalRoger Wright30-May-10 22:20 
AnswerRe: A Question Of Focus and Tab Indices Pin
Henry Minute30-May-10 23:10
Henry Minute30-May-10 23:10 
GeneralRe: A Question Of Focus and Tab Indices [modified] Pin
Roger Wright30-May-10 23:20
professionalRoger Wright30-May-10 23:20 
GeneralRe: A Question Of Focus and Tab Indices Pin
OriginalGriff30-May-10 23:27
mveOriginalGriff30-May-10 23:27 
GeneralRe: A Question Of Focus and Tab Indices Pin
Henry Minute30-May-10 23:30
Henry Minute30-May-10 23:30 
GeneralRe: A Question Of Focus and Tab Indices Pin
Luc Pattyn31-May-10 2:02
sitebuilderLuc Pattyn31-May-10 2:02 
Questiondeclare string[] Pin
jojoba201130-May-10 20:31
jojoba201130-May-10 20:31 
AnswerRe: declare string[] Pin
Vikram A Punathambekar30-May-10 20:34
Vikram A Punathambekar30-May-10 20:34 
AnswerRe: declare string[] Pin
Abhinav S30-May-10 20:43
Abhinav S30-May-10 20:43 
QuestionRe: declare string[] Pin
jojoba201130-May-10 20:52
jojoba201130-May-10 20:52 
AnswerRe: declare string[] Pin
Luc Pattyn31-May-10 2:04
sitebuilderLuc Pattyn31-May-10 2:04 

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.