views:

48

answers:

1

How to detect if the Autoscrollposition value changes in the panel1?

For example,

textbox1 and textbox2.

which added in panel1. The autoscroll property is set to true.

I am only interested in detecting when the value of panel autoscrollposition changes.

The above for dynamic textboxes which are incremented.

Software in use: C#, Visual Studio 2005.

+1  A: 

The Component required for it. is:

  1. ListBox1
  2. ListBox2
  3. Panel
  4. Button.

The Namespace for Class:

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;

Here is the Complete Solution Code:

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();

    }
}
}

It is helpful for adjust the panel autoscrollposition.

mahesh
@Roger thanks actually i was confused on edit. Now i got it.
mahesh