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

C#

 
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 
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 
Thanks Giff. Ur ideas fulfill my requirements. I have added foreach statement in my paint and its works.

Final and full code
        Image image;
        Bitmap mybitmap;
        Rectangle rect;
        List<Rectangle> rectangles = new List<Rectangle>();
        Graphics g;
private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            OpenFD.FileName = "";
            OpenFD.Title = "open image";
            OpenFD.InitialDirectory = "C";
            OpenFD.Filter = "JPEG|*.jpg|Bmp|*.bmp|All Files|*.*.*";
            if (OpenFD.ShowDialog() == DialogResult.OK)
            {
string file = "";
                file = OpenFD.FileName;
                 image = Image.FromFile(file);
                 pictureBox1.Image = image;
                 sz = image.Size;
                 pictureBox1.Size = sz;
                 pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;//this not needed if we give original image size to picturebox
                
            }

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_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();
                   
                }
                
            }
        }


private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            
              
                if (mybitmap == null)
                {
                    return;
                }

                
                    using (g = Graphics.FromImage(mybitmap))
                    {
                        Pen pen = new Pen(Color.Black);
                        foreach (Rectangle r in rectangles)
                        {
                            e.Graphics.DrawRectangle(pen, r);
                            label1.Top = rect.Top; label1.Left = rect.Left; label1.Width = rect.Width;
                            label1.Height = rect.Height;
                            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, r);
                            
                        }
                        
            }
            

                 
        }


private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
                        
            SaveFileDialog SaveFD1 = new SaveFileDialog();
            SaveFD1.FileName = "";
            SaveFD1.InitialDirectory = "C";
            SaveFD1.Title = "save file Name";
            SaveFD1.Filter = "JPG|*.jpg|Bmp|*.bmp";


            if (mybitmap != null)
            {

                if (SaveFD1.ShowDialog() == DialogResult.OK)
                {
                    if (SaveFD1.FileName == "")
                        return;
                    else
                    {

                        System.IO.Stream filename = (System.IO.FileStream)SaveFD1.OpenFile();
                            using (g = Graphics.FromImage(pictureBox1.Image))
                            {
                                foreach (Rectangle r1 in rectangles)
                        {
                            g.DrawImage(mybitmap,0, 0);
                        }

                            }
      
                         pictureBox1.Image.Save(filename, ImageFormat.Jpeg);
                           

                        }
}
}
}

private void textBox1_TextChanged(object sender, EventArgs e)
        {
            label1.Text = textBox1.Text;
         
        }

private void button1_Click(object sender, EventArgs e)
        {
            fontDialog1.ShowDialog();
            label1.Font = fontDialog1.Font;
            Invalidate();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            label1.ForeColor = colorDialog1.Color;
            Invalidate();
        }


This code will draw rectangles with the text given in the textbox at the position where the user likes.



Thanks once again Giff......and i worked with code given by u and it also working fine and for time being i need to stick with my code. Don't mistake me.

modified on Thursday, June 3, 2010 3:03 AM

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 
AnswerRe: declare string[] Pin
Anıl Yıldız31-May-10 11:37
Anıl Yıldız31-May-10 11:37 
AnswerRe: declare string[] Pin
AussieLew31-May-10 13:42
AussieLew31-May-10 13:42 

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.