Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What my code should do: Inside a panel1, I put many linklabels , and I want when the program starts, to jump to last linklabel used/clicked. For that i use
panel1.AutoScrollPosition = new Point(0, 2000);
I tried 3 events where i put my code to execute, and only in the button event it executes. In the Form1() and Form1_Load event my code is not executing at all, and i tried diferent debuging techniques i know under my sleeves.

What I have tried:

        public Form1()
        {
            InitializeComponent();

//.................................
                for (int i = 0; i < line.Length; i++)
                {
                    LinkLabel linklabel = new LinkLabel();
                    linklabel.Location = new Point(0, 22 * (i + 1));
                    panel1.Controls.Add(linklabel); 
//.................................
                }

            //scroll to last position:
            panel1.AutoScrollPosition = new Point(0, 2000);
            Refresh();
            button1.PerformClick();
            Application.DoEvents();
        }



private void Form1_Load(object sender, EventArgs e)
{
    panel1.AutoScrollPosition = new Point(0, 2000);
    Refresh();
    button1.PerformClick();
    Application.DoEvents();
}



private void button1_Click(object sender, EventArgs e)
{
    panel1.AutoScrollPosition = new Point(0, 2000); //only here is working !
}
Posted
Updated 12-Aug-19 20:09pm

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900