2010-09-22 5 views
0

Comment détecter si la valeur Autoscrollposition change dans le panneau1?Détecter la modification de la valeur Autoscrollposition dans le panneau

Par exemple,

textbox1 et TextBox2.

qui a été ajouté dans panel1. La propriété autoscroll est définie sur true.

Je ne suis intéressé que par la détection de la modification de l'auto-incrustation de panneau.

Ce qui précède pour les zones de texte dynamiques qui sont incrémentées.

Logiciel utilisé: C#, Visual Studio 2005.

Répondre

1

Le composant requis pour cela. est:

  1. ListBox1
  2. ListBox2
  3. Panneau
  4. Bouton.

L'espace de noms pour la classe:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.Collections; 

Voici le code complet de la solution:

namespace detectpanelvalue 
{ 

public partial class Form1 : Form 

{ 

    private Point tbpoint = new Point(10, 14); 

    private Point tbbpoint = new Point(300, 14); 

    private ArrayList arylst; 

    private ArrayList arylst1; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     panel1.Paint += new PaintEventHandler(panel1_Paint); 

    } 

    void panel1_Paint(object sender, PaintEventArgs e) 
    { 
     System.Drawing.Point pnlpt; 
     pnlpt = panel1.AutoScrollPosition; 
     if (tbpoint !=null || pnlpt != null) 
     { 
      pnlpt = tbpoint; 
     } 
     arylst1 = new ArrayList(); 
     arylst1.Add(pnlpt); 

    } 

    private void runtime() 
    { 
     foreach (Point pt in arylst) 
     { 
      listBox1.Items.Add(pt); 

     } 

     foreach (Point ptt in arylst1) 
     { 
      listBox2.Items.Add(ptt); 

     } 
    } 


    private void button1_Click(object sender, EventArgs e) 
    { 
     TextBox tb = new TextBox(); 
     tb.Location = tbpoint; 
     this.panel1.Controls.Add(tb); 
     tbpoint.Y += 30; 
     TextBox bb = new TextBox(); 
     bb.Location = tbbpoint; 
     this.panel1.Controls.Add(bb); 
     tbbpoint.Y += 30; 
     arylst = new ArrayList(); 
     arylst.Add(tbpoint); 
     runtime(); 

    } 
} 
} 

Il est utile pour régler le panneau AutoScrollPosition.

+0

@Roger merci en fait j'ai été confus sur modifier. Maintenant j'ai compris. – mahesh

Questions connexes