Alex,
Can focus is false because the all controls are not visible at the moment
the Load is being raised.
If you want to specify teh button that will have initialif the focus at this
very moment you can assign the button to the ActiveControl property. It also
works if you set the tab indices correctly
You say that the main pane has index 1 it makes mi thing that something
else has index 0 and this is what gets the focus.
--
Stoitcho Goutsev (100) [C# MVP]
Axel Dahmen said:
Thanks for trying to help me.
I'm not using a Tab control. I was referring to the TabIndex property
of
the
Button control (myBtn.TabIndex = ...)
The tab index determines the sequence of controls within the same
hierarchy
level getting focus when hitting the <TAB> key.
Axel
-------
I assume you are using the TabControl.
This seems to be a bug, because the button gets the focus simply by
assigning the tab index when outside the tab page. When the button is
inside
the tab page the only way i could find to set its focus is the follosing
(but i don't like it at all...).
private void Form1_Load(object sender, System.EventArgs e) {
tabControl1.SelectedIndex=1;
tabControl1.SelectedIndex=0;
}
private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e) {
if(tabControl1.TabIndex==0) button1.Focus();
}
Despite the appearences it doesn't visually show the change between
the
tab
pages, but displays the main page selected from the beggining and the
button
with the focus. I know it is not very clean, but it works and it seems an
acceptable workaround if this is really a bug.
Please someone correct me if this is not a bug or if there is some other
(cleaner) way to achieve this.
Hi,
I've programmed a simple form having some panes and one button.
There
is
a
basic thing I can't find a solution for:
1) I gave the button a TabIndex of 0.
The main pane has a TabIndex of 1.
Still the button doesn't get the focus when the form opens.
Why?
I tried to give focus to the button at Form_Load(), but CanFocus is
false
at that time.
TIA,
Axel Dahmen