Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
AnswerRe: Access Gmail contacts through C # Pin
Pete O'Hanlon14-Jun-16 21:04
mvePete O'Hanlon14-Jun-16 21:04 
GeneralRe: Access Gmail contacts through C # Pin
Member 1253942924-Jun-16 1:52
Member 1253942924-Jun-16 1:52 
NewsIcon c# library Pin
Matthew Hazlett14-Jun-16 10:37
Matthew Hazlett14-Jun-16 10:37 
GeneralWrong forum Pin
Richard Deeming14-Jun-16 11:18
mveRichard Deeming14-Jun-16 11:18 
GeneralRe: Icon c# library Pin
BillWoodruff14-Jun-16 16:06
professionalBillWoodruff14-Jun-16 16:06 
Questionhow to create three moving cars from different directions meeting at the junction Pin
Member 1252666814-Jun-16 5:22
Member 1252666814-Jun-16 5:22 
AnswerRe: how to create three moving cars from different directions meeting at the junction Pin
Simon_Whale14-Jun-16 5:30
Simon_Whale14-Jun-16 5:30 
AnswerRe: how to create three moving cars from different directions meeting at the junction PinPopular
OriginalGriff14-Jun-16 6:19
mveOriginalGriff14-Jun-16 6:19 
GeneralRe: how to create three moving cars from different directions meeting at the junction Pin
Kenneth Haugland14-Jun-16 6:52
mvaKenneth Haugland14-Jun-16 6:52 
GeneralRe: how to create three moving cars from different directions meeting at the junction Pin
OriginalGriff14-Jun-16 8:14
mveOriginalGriff14-Jun-16 8:14 
GeneralRe: how to create three moving cars from different directions meeting at the junction Pin
Kenneth Haugland14-Jun-16 8:30
mvaKenneth Haugland14-Jun-16 8:30 
GeneralRe: how to create three moving cars from different directions meeting at the junction Pin
OriginalGriff14-Jun-16 8:47
mveOriginalGriff14-Jun-16 8:47 
AnswerRe: how to create three moving cars from different directions meeting at the junction Pin
Pete O'Hanlon14-Jun-16 6:23
mvePete O'Hanlon14-Jun-16 6:23 
AnswerRe: how to create three moving cars from different directions meeting at the junction Pin
Matthew Hazlett15-Jun-16 9:58
Matthew Hazlett15-Jun-16 9:58 
QuestionError in listing open windows Pin
srikrishnathanthri13-Jun-16 20:08
srikrishnathanthri13-Jun-16 20:08 
AnswerRe: Error in listing open windows Pin
Richard MacCutchan13-Jun-16 21:03
mveRichard MacCutchan13-Jun-16 21:03 
GeneralRe: Error in listing open windows Pin
srikrishnathanthri13-Jun-16 23:49
srikrishnathanthri13-Jun-16 23:49 
GeneralRe: Error in listing open windows Pin
Pete O'Hanlon14-Jun-16 0:37
mvePete O'Hanlon14-Jun-16 0:37 
AnswerRe: Error in listing open windows Pin
KumarArunR10-May-17 20:03
KumarArunR10-May-17 20:03 
QuestionRX - Creating a Retry with a timer, and catch the exceptions Pin
Kenneth Haugland13-Jun-16 8:45
mvaKenneth Haugland13-Jun-16 8:45 
QuestionSQL Server 2005 query that uses the IIF with style date bool ? Pin
Member 245846711-Jun-16 22:44
Member 245846711-Jun-16 22:44 
AnswerRe: SQL Server 2005 query that uses the IIF with style date bool ? Pin
OriginalGriff11-Jun-16 23:14
mveOriginalGriff11-Jun-16 23:14 
GeneralRe: SQL Server 2005 query that uses the IIF with style date bool ? Pin
Member 245846712-Jun-16 17:08
Member 245846712-Jun-16 17:08 
GeneralRe: SQL Server 2005 query that uses the IIF with style date bool ? Pin
OriginalGriff12-Jun-16 20:23
mveOriginalGriff12-Jun-16 20:23 
QuestionMouse click poisition vary after stretching the image c# Pin
Shithun NK10-Jun-16 23:09
Shithun NK10-Jun-16 23:09 
Below code need to implement to measure the angle in a image. but after stretching the image found the mouse click position and line starting position is not correct.

Line starts some points after the mouse click point. if the image is not stretched no issues


C#
private void pictureBox1_VisibleChanged(object sender, EventArgs e)
        {
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            

        }
       
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            MouseEventArgs me = (MouseEventArgs)e;
            if (me.Button == System.Windows.Forms.MouseButtons.Right)
            {
                switch (clickProgress)
                {
                    case 1:
                        pts[2] = pts[0];
                        pts[1] = pts[0];
                        clickProgress--;
                        break;
                    case 2:
                        pts[2] = pts[0];
                        clickProgress--;
                        break;
                    case 3:
                        clickProgress--;
                        break;
                }
            }
            if (me.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (clickProgress < 3)
                {
                    pts[clickProgress] = me.Location;
                    if (clickProgress == 0)
                    {
                        pts[1] = pts[0];
                        pts[2] = pts[0];
                    }
                    clickProgress++;
                }
            }

            updateBitmap();
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (clickProgress > 0 && clickProgress < 3)
                pts[clickProgress] = e.Location;

            updateBitmap();
        }


        private void updateBitmap()
        {
            if (pictureBox1.Image == null)
            {
                Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                
                pictureBox1.Image = bmp;
                
            }

            using (Graphics g = Graphics.FromImage(pictureBox1.Image))
            {
                g.Clear(Color.Black);
                
               
                if (pic != null)
                {
                    int width = pictureBox1.Width;
                    int height = pictureBox1.Height;

                    float scaleW = pictureBox1.Width * 1.0f / width;
                    float scaleH = pictureBox1.Height * 1.0f / height;
                    float scale = scaleW;
                    if (scale > scaleH)
                        scale = scaleH;

                    int nw = (int)(scale * width);
                    int nh = (int)(scale * height);

                    if (picScaled == null)
                    {
                        RectangleF sourceRect = new RectangleF(0, 0, width, height);
                        RectangleF destinationRect = new RectangleF(0, 0, nw, nh);
                        picScaled = new Bitmap(nw, nh);

                        Graphics gi = Graphics.FromImage(picScaled);
                        gi.DrawImage(
                            pic,
                            destinationRect,
                            sourceRect,
                            GraphicsUnit.Pixel);
                        gi.Dispose();
                    }
                    {
                        RectangleF sourceRect = new RectangleF(0, 0, nw, nh);

                        RectangleF destinationRect = new RectangleF(
                            pictureBox1.Width / 2 - nw / 2,
                            pictureBox1.Height / 2 - nh / 2,
                            nw,
                            nh);

                        g.DrawImage(
                            picScaled,
                            destinationRect,
                            sourceRect,
                            GraphicsUnit.Pixel);
                    }
                }

                Pen greenPen = new Pen(Brushes.Green);
                greenPen.Width = 3.0F;
                Pen redPen = new Pen(Brushes.Red);
                redPen.Width = 3.0F;

                if (clickProgress > 0)
                    g.DrawLine(greenPen, pts[0], pts[1]);

                if (clickProgress > 1)
                    g.DrawLine(redPen, pts[0], pts[2]);

                redPen.Dispose();
                greenPen.Dispose();
            }
            pictureBox1.Invalidate();

            if (clickProgress > 1)
            {

                Point p0 = new Point(pts[1].X - pts[0].X, pts[1].Y - pts[0].Y);
                Point p1 = new Point(pts[2].X - pts[0].X, pts[2].Y - pts[0].Y);

                ///make these doubles to not overflow
                double l0 = (p0.X * p0.X + p0.Y * p0.Y);
                double l1 = (p1.X * p1.X + p1.Y * p1.Y);

                double d = ((double)p0.X * p1.X + (double)p0.Y * p1.Y) / Math.Sqrt(l0 * l1);

                if (d > +1) d = +1;//limit against roundoff errors
                if (d < -1) d = -1;//limit against roundoff errors

                if (l0 > 0 && l1 > 0)
                    label1.Text = (Math.Acos(d) * 180 / Math.PI).ToString("0.0", System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                label1.Text = "";
            }
        }

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.