Click here to Skip to main content
14,268,557 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100