You don't ever draw on the form. You do everything related to the screen in the Form_Refresh() Event of your Form, or PB if that's what you want to draw on.
Once you get the hang of it, it works pretty well.
To draw in real-time, you can use a timer:
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Add another row to the grid and update the screen.
matrix.AddRow()
matrix.Draw(Me.PictureBox1.CreateGraphics(), Me.PictureBox1.BackColor)
End Sub
i wrote a simple code for you using GDI+ that paint a blue line on the form by overriding OnPaint and you can draw curves with red color in the form also.
here is the code.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DrawLine
{
public partial class Form1 : Form
{
bool isDrawing = false;
Point prevLoc;
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
Pen RedPen = new Pen(Color.Blue, 3);
Point[] p = { new Point(20, 20), new Point(100, 100) };
g.DrawLines(RedPen, p);
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 2);
if (isDrawing)
{
using (Graphics g = this.CreateGraphics())
{
g.DrawLine(p, prevLoc, e.Location);
prevLoc = e.Location;
}
}
p.Dispose();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
isDrawing = true;
prevLoc = e.Location;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
isDrawing = false;
}
}
}
i have attached a sample image.
Note: my code is not an ultimate solution i spent a few minutes on it just to give you the clue.
Please rate my post if it was helpful for you.
Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.