Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
AnswerRe: Help to get only IPv4 address Pin
Richard Deeming8-Oct-19 8:54
mveRichard Deeming8-Oct-19 8:54 
GeneralRe: Help to get only IPv4 address Pin
mniceguy819-Oct-19 3:51
mniceguy819-Oct-19 3:51 
GeneralRe: Help to get only IPv4 address Pin
Richard Deeming9-Oct-19 7:36
mveRichard Deeming9-Oct-19 7:36 
GeneralRe: Help to get only IPv4 address Pin
mniceguy819-Oct-19 7:41
mniceguy819-Oct-19 7:41 
QuestionDoes the Visual studio C#.net have a progressBar and a control line ? Pin
Member 24584676-Oct-19 23:34
Member 24584676-Oct-19 23:34 
AnswerRe: Does the Visual studio C#.net have a progressBar and a control line ? Pin
Afzaal Ahmad Zeeshan6-Oct-19 23:44
professionalAfzaal Ahmad Zeeshan6-Oct-19 23:44 
GeneralRe: Does the Visual studio C#.net have a progressBar and a control line ? Pin
Member 24584677-Oct-19 16:41
Member 24584677-Oct-19 16:41 
QuestionDrawing from a Class library to a pictureBox Pin
Ali Zigon6-Oct-19 5:27
Ali Zigon6-Oct-19 5:27 
Hi there!

I'm playing around with graphics in C#. I've managed to create a simple application using graphic object to draw some lines and scroling text to a pictureBox. Now I've decided to put my code into a Class (like for further re-use... and mostly for the learning purposes!), but I'm stuck on how to get the graphics back from Class to my pictureBox. The problem (I think!) lies as I'm doing all my drawings in the timer_tick event...

Here's the current code I'm using...
CLASS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Windows.Forms;

namespace Osciloscope
{
    
    public class Osciloscope
    {
        int SCOPE_WIDTH, SCOPE_HEIGHT; // the width and the height of the osciloscope screen
        int SCOPE_HORIZONTAL_CENTER, SCOPE_VERTICAL_CENTER; //center point of the screen
        int SCAN_POINT_X; //number of points in the line (the width of the scope)
        int SCAN_POINT_Y; //as above but vertical (input...)
        int SCAN_POINT_X_NEW;
        int SCAN_POINT_Y_NEW;


        //Image PictureBox;
        //Graphics _Image; // get the bitmap
                                //Timer t;

        int TIMER_INTERVAL;
        Bitmap _Image;
        Graphics g;
        Pen p;

        public Osciloscope(PictureBox picture, bool Run, int Interval)
        {
            SCOPE_HEIGHT = picture.Height;
            SCOPE_WIDTH = picture.Width;
            TIMER_INTERVAL = Interval;
             //calculate mid point if the scope
            SCOPE_HORIZONTAL_CENTER = SCOPE_WIDTH / 2;
            SCOPE_VERTICAL_CENTER = SCOPE_HEIGHT / 2;
            SCAN_POINT_X = 1;// leftmost point on the screen (start scan)
            SCAN_POINT_Y = SCOPE_VERTICAL_CENTER; //the line runs in the middle of the screen

            //_Image = img;
            _Image= new Bitmap(SCOPE_HEIGHT, SCOPE_WIDTH);
            Timer t = new Timer();
            t.Tick += new EventHandler(t_Tick);
            if (Run)
            {
                t.Enabled = true;
                t.Interval = TIMER_INTERVAL;
                t.Start();
            }
            else
            {
                t.Stop();
            }

        }

        void t_Tick(object sender, EventArgs e)
        {
            g = Graphics.FromImage(_Image);
            //g.Clear(Color.Blue);
            
            p = new Pen(Color.Green, 2f);

            SCAN_POINT_X_NEW = SCAN_POINT_X + 1;
            SCAN_POINT_Y_NEW = SCAN_POINT_Y; //Math.Sin(SCAN_POINT_X);
            // draw the line
            g.DrawLine(p, SCAN_POINT_X, SCAN_POINT_Y, SCAN_POINT_X_NEW, SCAN_POINT_Y_NEW);

            //bmp = _Image;
            //DrawGraph = _Image;
            // = _scope;
            
            p.Dispose();
            g.Dispose();

            SCAN_POINT_X++;
            if(SCAN_POINT_X==SCOPE_WIDTH)
            {
                SCAN_POINT_X = 1;
            }

        }

        //private Image drawGraph
public Image DrawGraph
        {
            get
            {
                return _Image;
            }
        }
    }
}


... and the form itself...

namespace Osciloscope
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        Osciloscope Osciloscope;
        private void FrmMain_Load(object sender, EventArgs e)
        {
            Osciloscope = new Osciloscope(Scope, true, 5);
            Scope.Image= Osciloscope.DrawGraph;
            //Osciloscope.Image = Scope;
            //Scope.Image = Osciloscope.Image;
           //
        }

    }
}


As I said: I just can't figure out how to get the drawing into the pictureBox... (Scope is the name of the pictureBox!)

Any help woul be highly appreciated!

Regards!

// EDIT: There's no scroling text in current code as I left it out for simplicity...
AnswerRe: Drawing from a Class library to a pictureBox Pin
Richard MacCutchan6-Oct-19 5:48
mveRichard MacCutchan6-Oct-19 5:48 
GeneralRe: Drawing from a Class library to a pictureBox Pin
Ali Zigon6-Oct-19 6:19
Ali Zigon6-Oct-19 6:19 
GeneralRe: Drawing from a Class library to a pictureBox Pin
Richard MacCutchan6-Oct-19 7:08
mveRichard MacCutchan6-Oct-19 7:08 
GeneralRe: Drawing from a Class library to a pictureBox Pin
Ali Zigon6-Oct-19 8:37
Ali Zigon6-Oct-19 8:37 
GeneralRe: Drawing from a Class library to a pictureBox Pin
Richard MacCutchan6-Oct-19 22:17
mveRichard MacCutchan6-Oct-19 22:17 
GeneralRe: Drawing from a Class library to a pictureBox Pin
Ali Zigon7-Oct-19 3:31
Ali Zigon7-Oct-19 3:31 
QuestionReading Access Into SQL - OLE Provider Errors Pin
Kevin Marois4-Oct-19 5:27
professionalKevin Marois4-Oct-19 5:27 
AnswerRe: Reading Access Into SQL - OLE Provider Errors Pin
Richard MacCutchan4-Oct-19 5:42
mveRichard MacCutchan4-Oct-19 5:42 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Kevin Marois4-Oct-19 6:46
professionalKevin Marois4-Oct-19 6:46 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Richard MacCutchan4-Oct-19 6:54
mveRichard MacCutchan4-Oct-19 6:54 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Kevin Marois4-Oct-19 7:20
professionalKevin Marois4-Oct-19 7:20 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Richard MacCutchan4-Oct-19 7:30
mveRichard MacCutchan4-Oct-19 7:30 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Kevin Marois4-Oct-19 7:40
professionalKevin Marois4-Oct-19 7:40 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Richard MacCutchan4-Oct-19 22:37
mveRichard MacCutchan4-Oct-19 22:37 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Eddy Vluggen5-Oct-19 9:17
professionalEddy Vluggen5-Oct-19 9:17 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Kevin Marois6-Oct-19 6:25
professionalKevin Marois6-Oct-19 6:25 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Eddy Vluggen6-Oct-19 6:52
professionalEddy Vluggen6-Oct-19 6:52 

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.