开发者

vb.net tabpage using a form for tabpanels issues

I have a simple vb.net form a tabpanel strip, and then a seperate form which is loaded for the tabpage.

Here is the code for the button that dynamically creates new tabs:

    Dim tempTab As New TabPage
    initTab(tempTab)
    xt.TabPages.Add(tempTab)
    xt.SelectedIndex = xt.TabCount - 1

Here is the code for the "initTab":

    Dim tmpTab As New MainTab
    tmpTab.Dock = DockStyle.Fill
    tmpTab.Panel1.Dock = DockStyle.Fill
    tab.Controls.Add(tmpTab)
    tab.Text = "Untitled"
    tab.Name = " "

I can easily set the f开发者_运维百科ocus of any tab by entering following which sets the focus for example to the last tab:

xt.SelectedIndex = xt.TabCount - 1

Now the issue is, how can I set the focus to a textbox on the custom form (in my example labeled "MainTab")? I've tried virtually everything I can google and I can't seem to find any example of how to setfocus or even set/get anything from the MainTab form.

Anyone can help me?


Erm, turning a form into a child control takes some surgery. You have to set its TopLevel property to false, hide the border, make it visible. I don't see it in the code snippet, is MainTab actually a form?

Anyhoo, you cannot use the Focus() method on a control until it is visible. Odds are good that it isn't visible yet in your code snippet. Use the Select() method instead. Say:

 tmpTab.TextBox1.Select()

Or just set the TabIndex property of the first control that should get the focus to 0 in the designer.


xt.Controls(xt.SelectedIndex).Controls("TEXTBOXNAME").Focus()

Just make sure that you set the Name property of the textbox you want to have focus (in this case the name would be TEXTBOXNAME) if you do it like this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜