how to set focus for last added ctrl in TableLayoutPanel
am using TableLayoutPanel to show the images.. here dy开发者_开发知识库namically i ll add lot image into TableLayoutPanel .. here i need to focus the last added image .... i don't know how to do this please help me....
you can activate the last control by Control.Select() property.
I'm assuming you're using the Panel control to display the images and that your current code looks similar to this:
in your OnLoad for the form...
Panel panel=null;
foreach(Image i in images)
{
panel =new Panel();
panel.BackgroundImage=i;
panel.TabStop=true;
tableLayoutPanel1.Controls.Add(panel);
}
panel.Focus();
- With that code, the focus is never set correctly!
Why?
It appears a form need to be activated before focus can be set.
With some minor tweaks the focus will set correctly
first keep track of the last panel at the form level.
Second override the forms OnActivated event and call panel.Focus() in there. It's still safe to construct and add inside the OnLoad override, or load event.
精彩评论