Click here to Skip to main content
15,913,722 members
Home / Discussions / C#
   

C#

 
Questionreguest Pin
balanandakumar27-Apr-09 18:57
balanandakumar27-Apr-09 18:57 
GeneralRe: reguest Pin
Spunky Coder27-Apr-09 19:10
Spunky Coder27-Apr-09 19:10 
QuestionWebReference woes Pin
bytecrusader27-Apr-09 18:20
bytecrusader27-Apr-09 18:20 
QuestionMethod Overriding and Method Overloading Differnce with simple example Pin
Rameez Raja27-Apr-09 16:31
Rameez Raja27-Apr-09 16:31 
AnswerRe: Method Overriding and Method Overloading Differnce with simple example Pin
adatapost27-Apr-09 16:52
adatapost27-Apr-09 16:52 
AnswerRe: Method Overriding and Method Overloading Differnce with simple example Pin
PIEBALDconsult27-Apr-09 17:27
mvePIEBALDconsult27-Apr-09 17:27 
GeneralRe: Method Overriding and Method Overloading Differnce with simple example Pin
Rameez Raja27-Apr-09 19:51
Rameez Raja27-Apr-09 19:51 
GeneralDynamic Image Resizing for Line Chart Generator Pin
Caio198527-Apr-09 16:17
Caio198527-Apr-09 16:17 
Hello,

I'm trying to create a chart generator where random numbers define the chart coordinates.
As new values are added on the chart, the scrollbar appears and then scrolls automatically, pointing to the end of the chart, so the user can see the last data inserted.
The problem is that I'm inserting new values on the picturebox's image but after the scroll exceeds the original picturebox's size, it start repeating the image, instead of displaying the new values - it becomes just like a repeating scene on loop. I don't know what I can in order to solve that, I'd like to have the new values displayed on the image as the scroll continues.

The source code is below (sorry, but I don't know how to place it formatted here...):

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;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        private const int WM_SCROLL = 276; // Horizontal scroll
        private const int WM_VSCROLL = 277; // Vertical scroll
        private const int SB_LINEUP = 0; // Scrolls one line up
        private const int SB_LINELEFT = 0;// Scrolls one cell left
        private const int SB_LINEDOWN = 1; // Scrolls one line down
        private const int SB_LINERIGHT = 1;// Scrolls one cell right
        private const int SB_PAGEUP = 2; // Scrolls one page up
        private const int SB_PAGELEFT = 2;// Scrolls one page left
        private const int SB_PAGEDOWN = 3; // Scrolls one page down
        private const int SB_PAGERIGTH = 3; // Scrolls one page right
        private const int SB_PAGETOP = 6; // Scrolls to the upper left
        private const int SB_LEFT = 6; // Scrolls to the left
        private const int SB_PAGEBOTTOM = 7; // Scrolls to the upper right
        private const int SB_RIGHT = 7; // Scrolls to the right
        private const int SB_ENDSCROLL = 8; // Ends scroll

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
   
        List<point> pointList = new List<point>();

        Graphics graphics;
        Pen pen;
        Random random = new Random();
        int current = 0;
        Point oldPoint = new Point();
        Point newPoint = new Point();
        Color bgColor;
        Bitmap newBitmap;

        public Form1()
        {
            InitializeComponent();

            bgColor = Color.White;
            pen = new Pen(Color.Black);
            newBitmap = new Bitmap(pbChart.Width, pbChart.Height, PixelFormat.Format24bppRgb);
            graphics = Graphics.FromImage(newBitmap);
            graphics.Clear(bgColor);

            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        }

        void drawPoint(int px, int py)
        {
            newPoint.X = px;
            newPoint.Y = py;

            if (pointList.Count != 0)
            {
                oldPoint = pointList.Last();
            }
            else
            {
                oldPoint = newPoint;
            }

            pointList.Clear();

            pointList.Add(oldPoint);
            pointList.Add(newPoint);

            if (px > pbChart.Width)
            {
                pbChart.Width += (px - pbChart.Width);
                SendMessage(panel1.Handle, WM_SCROLL, (IntPtr)SB_RIGHT, IntPtr.Zero);
            }

            graphics.DrawCurve(pen, pointList.ToArray());

            pbChart.BackgroundImage = newBitmap;

            pbChart.Refresh();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            drawPoint(current, random.Next(0, pbChart.Height));
            current += 5;
        }

        private void btnPlayPause_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled)
                timer1.Stop();
            else
                timer1.Start();
        }
    }
}</point></point>


I guess that after the width is increased, the graphics width keeps the old one, so it does not show the new values, but I don't know how to overcome that, if that is the root cause of the problem.

Thanks in advance,

Regards,
Caio.
QuestionMouse Over Event (C Sharp) Pin
misCafe27-Apr-09 15:33
misCafe27-Apr-09 15:33 
AnswerRe: Mouse Over Event (C Sharp) Pin
TannerB27-Apr-09 16:52
TannerB27-Apr-09 16:52 
GeneralRe: Mouse Over Event (C Sharp) Pin
misCafe27-Apr-09 18:34
misCafe27-Apr-09 18:34 
GeneralRe: Mouse Over Event (C Sharp) Pin
12Code27-Apr-09 20:34
12Code27-Apr-09 20:34 
GeneralRe: Mouse Over Event (C Sharp) Pin
misCafe30-Apr-09 0:00
misCafe30-Apr-09 0:00 
QuestionOverloading a return value to a property in a webcontrol. Ambiguous Match Found Error. Pin
Andre Vianna27-Apr-09 14:32
Andre Vianna27-Apr-09 14:32 
QuestionHow to change language at runtime Pin
maxgit_100027-Apr-09 11:36
maxgit_100027-Apr-09 11:36 
AnswerRe: How to change language at runtime Pin
Rolando CC27-Apr-09 11:49
professionalRolando CC27-Apr-09 11:49 
QuestionHow to write simple com service in C# ? Pin
Yanshof27-Apr-09 11:25
Yanshof27-Apr-09 11:25 
AnswerRe: How to write simple com service in C# ? Pin
adatapost27-Apr-09 17:03
adatapost27-Apr-09 17:03 
QuestionCertificate Management / SslStream encryption Pin
guest100127-Apr-09 11:08
guest100127-Apr-09 11:08 
AnswerRe: Certificate Management / SslStream encryption Pin
guest100128-Apr-09 19:41
guest100128-Apr-09 19:41 
Questionftp key_press_evevt(help) Pin
T_Teef27-Apr-09 10:33
T_Teef27-Apr-09 10:33 
AnswerRe: ftp key_press_evevt(help) Pin
Rolando CC27-Apr-09 10:54
professionalRolando CC27-Apr-09 10:54 
GeneralRe: ftp key_press_evevt(help) Pin
T_Teef27-Apr-09 11:33
T_Teef27-Apr-09 11:33 
QuestionBinary files Pin
hamziak27-Apr-09 10:26
hamziak27-Apr-09 10:26 
AnswerRe: Binary files Pin
Rolando CC27-Apr-09 10:47
professionalRolando CC27-Apr-09 10:47 

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.