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...
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...)
//Graphics _Image; // get the bitmap
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);
t.Enabled = true;
t.Interval = TIMER_INTERVAL;
void t_Tick(object sender, EventArgs e)
g = Graphics.FromImage(_Image);
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;
SCAN_POINT_X = 1;
//private Image drawGraph
public Image DrawGraph
... and the form itself...
public partial class FrmMain : Form
private void FrmMain_Load(object sender, EventArgs e)
Osciloscope = new Osciloscope(Scope, true, 5);
//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!
// EDIT: There's no scroling text in current code as I left it out for simplicity...
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.