So, I have noticed that getting the TAB key to work with a rhino plugins is tough for me.
But I also noticed that RhinoNest also has the same problem. So I am hoping someone here has the key to fix this and could share it.
This is what I have found so far. Below is the main menu for my plugin.
Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result
' TODO: start here modifying the behaviour of your command.
' ---
Dim mainForm As MainMenu
mainForm = New MainMenu()
mainForm.setDoc = doc
mainForm.Show(RhinoApp.MainApplicationWindow())
Return Result.Success
End Function
I use .Show(), because that seems the best way to work for me.
If I use .ShowDialog(), I can use the tab key, but ShowDialog is not what I need.
I even tried to use Application.Run, but Rhino runs on the main thread and any rhinocommon wont run unless I use some sort of thread management.
This is how I show a form from my main menu form.
Private Sub bomButton_Click(sender As Object, e As EventArgs) Handles bomButton.Click
Dim textureObject = rs.ObjectsByName("TEXTURE")
Dim bomManager As BOMManagerForm
bomManager = New BOMManagerForm()
If (textureObject IsNot Nothing) Then
bomManager.Show(MainMenu.ActiveForm)
bomManager.StartBOMManager()
Else
MsgBox("RhinoDek did not detect that the BOM was inserted.")
End If
End Sub
Has anyone gotten the tab key to work with a rhino plugin?? What is it that I am doing wrong?
I’ve tried setting the focus with form.Activate, I’ve tried different owners inside Show() but I still can’t get this to work.
I have read the info on using a hook, but I am trying to find a faster way around it. I also have to make this plugin… future proof. In case something happens to me and the company needs someone else to work on it. So I can’t add to much craziness too it.
I have started this little thing… I’ll just post the code to show where I am going with it. I have around 4 years in programming in game dev, so I am applying those skills into make this auto tab work with out hooks.
Private Sub Tab_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Dim ctrl As Control
For Each ctrl In GroupBox1.Controls
If Keys.Tab Then
If ctrl.GetType() Is GetType(TextBox) Then
ctrl.Focus()
End If
End If
Next ctrl
End Sub
It’s not perfect, as of now, it only goes to the very last textbox in the groupbox… but hey… at least I got it to move with the tab key
But it is odd, I sent out a rs.Print(ctrl.ToString()) to see what its getting… and for some reason it spits out the entire list at once. Not sure whats up with that. It should only iterate through each ctrl one by one. I’ll have more time to work on it tomorrow.
Thanks for the support
Edit,
I might throw this in a loop and just step through it with a counter… just brain storming. thoughts?
Edit all of that… wow… I pulled almost 60 hours this week… so I am not thinking correctly lol.
For OBVIOUS reasons, that for each loop wont work… let me sleep. I know what to do. I’ll share my findings, cuase I know there are LOTS of devs that would like this as a more simple work around.
Dim ctrlList As New ArrayList
Dim ctrlListCount As Integer
Dim ctrlCount As Integer
Public Function StartNewProjectForm(ByVal doc As RhinoDoc) As Result
For Each ctrl In GroupBox1.Controls
If ctrl.GetType() = GetType(TextBox) Then
ctrlList.Add(ctrl)
End If
Next ctrl
ctrlListCount = ctrlList.Count()
Return Result.Success
End Function
Private Sub Tab_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If ctrlCount < ctrlListCount Then
If e.KeyCode.Equals(Keys.Tab) Then
ctrlList(ctrlCount).Focus()
ctrlCount = ctrlCount + 1
End If
Else
ctrlCount = 0
End If
End Sub
It works… but it’s backwards in the tab order.
I also thought of another way to do this, but I don’t know how. My other thought is setting the tag on all input boxes to “text” or something like that. Storing all those in an array, and index them everytime you press tab.