Dunque cho cambiato delle cose.
Ho creato un nuovo componente e all'interno ho definito il metodo onpaint che mi dà la forma rettangolare al componente.
Poi nel mio form ho associato all'evanto drag&drop questo:
rectangle myRect = new rectangle();
this.Controls.Add(myRect);
mi dà questi errori:
-The best overloaded method match for 'System.Windows.Forms.Control.ControlCollection.Add(System.Windows.Forms.Control)' has some invalid arguments
-cannot convert from 'LineaFlusso.rectangle' to 'System.Windows.Forms.Control'
Probabilmente ho sbagliato nel creare il mio componente rectangle.
Metto il codice che ho messo nel mio componente:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace LineaFlusso
{
public class rectangle : System.ComponentModel.Component
{
private System.ComponentModel.Container components = null;
string nomeImm;
public Point strRect
{
set
{
Point p1 = (Point)value;
}
get
{
return strRect;
}
}
public rectangle(System.ComponentModel.IContainer container)
{
container.Add(this);
InitializeComponent();
}
public rectangle()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
protected void OnPaint(PaintEventArgs pe)
{
Graphics g = pe.Graphics;
Pen blackPen = new Pen(Color.Black);
g.DrawRectangle(blackPen, strRect.X, strRect.Y, 10, 5);
}
}
}