Problema con OnPaint

martedì 06 giugno 2006 - 17.52

kiara83 Profilo | Junior Member

[CODE] protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Pen blackPen = new Pen(Color.Black); e.Graphics.DrawRectangle(blackPen, this.rectLocation.X, (Height/2)+5, 10, 5); } private void LBimm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if(LBimm.Items.Count==0) return; PropImmagini SelectedImm = (PropImmagini)LBimm.Items[LBimm.IndexFromPoint(e.X,e.Y)]; DragDropEffects dde1=DoDragDrop(SelectedImm, DragDropEffects.All); } private void lineaIntervallo_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { PropImmagini ImmLabe = (PropImmagini)e.Data.GetData(typeof (PropImmagini)); this.rectLocation = this.PointToClient(new Point(e.X, e.Y)); } private void lineaIntervallo_DragOver(object sender, System.Windows.Forms.DragEventArgs e) { e.Effect = DragDropEffects.Copy; }[/CODE]

Qualcuno sa dirmi perchè il metodo Onpaint alla fine non mi disegna nessun rettangolo???

Brainkiller Profilo | Guru

>Qualcuno sa dirmi perchè il metodo Onpaint alla fine non mi disegna
>nessun rettangolo???

Eh bisogna vedere cosa fa il resto dell'applicazione.
Eh ma verifica che coordinate X,Y stai usando perchè se sono negative, non saranno mai visibili.
Ciao

David De Giacomi
Microsoft MVP
http://blogs.dotnethell.it/david/

kiara83 Profilo | Junior Member

No non sono negative, ho già controllato.
Io non so proprio come fare ad associare al drag&drop la creazione di un rettangolo.
Come faccio a disegnare un rettangolo???

Brainkiller Profilo | Guru

>No non sono negative, ho già controllato.
>Io non so proprio come fare ad associare al drag&drop la creazione
>di un rettangolo.
>Come faccio a disegnare un rettangolo???

Se ti spieghi meglio forse si capisce meglio
Il codice che hai postato disegna un Rettangolo, naturalmente mettendo coordinate positive. Se le tue coordinate sono positive devi verificare se l'evento OnPaint viene richiamato. Metti un breakpoint dentro l'evento e vai in debug e vedi cosa succede.

Ciao
David De Giacomi
Microsoft MVP
http://blogs.dotnethell.it/david/

kiara83 Profilo | Junior Member

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); } } }
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5