Simply, how do i draw on a form?
I googled, but not what i wanted. I thought I had a link or sample project, but apparently I lost it.
Like MS paint, but just straight onto the form. Not any line making or shapes, like free hand.
Printable View
Simply, how do i draw on a form?
I googled, but not what i wanted. I thought I had a link or sample project, but apparently I lost it.
Like MS paint, but just straight onto the form. Not any line making or shapes, like free hand.
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
Quote:
D:\VisualStudio2008\VB RTM Samples\Application Samples\Game
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.
i have attached a sample image.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;
}
}
}
Note: my code is not an ultimate solution i spent a few minutes on it just to give you the clue.
Toraj +1