|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Form Focus Issue2005. I have two forms. One is a form with a TreeView control on it (used as a menu - kindof a favorites list) and the other is a form with a WebBrowser control on it. The TreeView_Click event fires up the other form with the link passed to it via the Node. If the user clicks the TreeView and the form is already open with that link in it, it is supposed to set focus to the appropriate form. This does occur, but it appears that when the Click event completes, the form with the TreeView control on it gets the focus back. So other than the TreeView form, the proper WebBrowser form is at the front. How do I get the form with the TreeView to remain behind the properly selected WebBrowser form? Any suggestions would be appreciated. Mark Dahl isn't it just me.sendtoback? form inherits from control so this should work.
tm Show quoteHide quote "Fr15ky" <shilohs***@gmail.com> wrote in message news:1138233037.705474.159400@f14g2000cwb.googlegroups.com... > First of all, I am using the .NET 2.0 framework with Visual Studio > 2005. > > I have two forms. One is a form with a TreeView control on it (used as > a menu - kindof a favorites list) and the other is a form with a > WebBrowser control on it. > > The TreeView_Click event fires up the other form with the link passed > to it via the Node. If the user clicks the TreeView and the form is > already open with that link in it, it is supposed to set focus to the > appropriate form. This does occur, but it appears that when the Click > event completes, the form with the TreeView control on it gets the > focus back. So other than the TreeView form, the proper WebBrowser form > is at the front. > > How do I get the form with the TreeView to remain behind the properly > selected WebBrowser form? > > Any suggestions would be appreciated. > > Mark Dahl > Fr15ky,
I am not aware how long you are working already with VBNet. Quiet anoying however logical is that in Net, when you change an item in an event, it is possible that it triggers its own or another event. (This happens especially with the combobox, listbox and treeview) That can change the behaviour. Are you sure that it is not that. I hope this helps, Cor Toff,
I will try doing that, I was able to have it work the first time I click the link by doing a WebBrowserForm.BringToFront, WebBrowserForm.Activate, and WebBrowserForm.Focus in the WebBrowser controls _Navigated Event. But once the form has been loaded, this event no longer runs as I am just setting focus (activating, bringing to the front) the appropriate WebBrowserForm. In my quick trial, however, this did not work (or I am not finding the last event that is causing the Navigator form to get the focus back. Cor, Honestly, I am new to .NET. I have only really been working on .NET for about 2 weeks. It is obviously event oriented, because this problem is specific to the MouseDown event but the KeyDown event of the TreeView works properly. Do you have an event that you believe would work properly for Toff's suggestion? I would prefer an event that can be tied to the TreeView. Thanks for the responses and the help. Mark Dahl Fr15Ky,
And you are sure that there (as I wrote) is not any instruction more triggered that is done in your treeview form? Did you debug your program? Cor Cor,
Here is the ONLY code around the navigator: Private Sub tvwNavigator_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tvwNavigator.KeyDown If e.KeyCode = Keys.Enter Then If Not tvwNavigator.SelectedNode.Equals(Nothing) Then ProcessNavigatorClick(tvwNavigator.SelectedNode) End If End If End Sub Private Sub tvwNavigator_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwNavigator.MouseDown tvwNavigator.SelectedNode = tvwNavigator.GetNodeAt(e.X, e.Y) ProcessNavigatorClick(tvwNavigator.SelectedNode) End Sub Other than the above code, the form only has a _Load event that fills the TreeView, a mnuNavExit_Click event that closes the application and a mnuNavLargeIcons_Click event that will change the ImageList for the TreeView. So I don't know if there is anything else I should check. Mark Dahl FR15Ky,
> tvwNavigator.SelectedNode = tvwNavigator.GetNodeAt(e.X, e.Y) In my idea will this give an action as the form get painted again.Can you remove it and see what happens? Cor Cor,
Nope that didn't work and now I have even more problems, because the SelectedNode is not the right one. Mark Dahl Hi Mark,
Why do you use tvwNavigator.MouseDown? There is an event called AfterSelect that fires after a node in a treeview is selected. To get the newly selected node just query the argument ByVal e As System.Windows.Forms.TreeViewEventArgs of this event for e.Node. Using mousedown as you have may well return nothing for GetNodeAt(e.X, e.Y) if the coordinates do not map to a node. This probably wont solve your initial problem however so can you show us the code for ProcessNavigatorClick() You said above that there is no more code on the treeview form and yet i dont see any kind of type/instance qualifier for ProcessNavigatorClick() so i can only assume its Me.ProcessNavigatorClick? TM Show quoteHide quote "Fr15ky" <shilohs***@gmail.com> wrote in message news:1138301969.803375.227330@g44g2000cwa.googlegroups.com... > Cor, > > Nope that didn't work and now I have even more problems, because the > SelectedNode is not the right one. > > Mark Dahl > Toff,
Microsoft suggested that event too. And I originally used code from Microsoft's site to process the link. The problem is that if you select a Node then close the form that was opened by that click. Then click the same Node again, the AfterSelect code does not fire. Using AfterSelect still had the same problem, so I will show you a little more of the code involved here. This code is in a module called NavigatorProcesses Class myTreeNode Inherits TreeNode Public FilePath As String Public RollOverText As String Sub New(ByVal fp As String) MyBase.New() Dim strTemp() As String strTemp = Split(fp, "||") FilePath = strTemp(0) Me.Text = strTemp(1) RollOverText = strTemp(2) End Sub End Class Public Sub ProcessNavigatorClick(ByVal NavigatorClickSelect As TreeNode) Dim nodeCount As Integer = NavigatorClickSelect.GetNodeCount(True) If nodeCount > 0 Then If NavigatorClickSelect.ImageIndex = 0 Then NavigatorClickSelect.ImageIndex = 1 Else NavigatorClickSelect.ImageIndex = 0 End If NavigatorClickSelect.SelectedImageIndex = NavigatorClickSelect.ImageIndex NavigatorClickSelect.Toggle() Else Dim myNode As myTreeNode myNode = CType(NavigatorClickSelect, myTreeNode) If myNode.FilePath <> "NULL" Then OpenWebManageScreen(myNode.FilePath, Navigator) End If End If End Sub Public Sub OpenWebManageScreen(ByVal NavigateTo As String, ByVal Parent As Form) Dim WebManage As New WebManager If Not PerformFormAction(NavigateTo, -1, "A") Then WebManage.URLStart = NavigateTo WebManage.Show() End If End Sub Public Function PerformFormAction(ByVal FormName As String, Optional ByVal FormID As Long = 0, Optional ByVal FormAction As String = "") As Boolean '------------------------------------------------------------ ' Procedure: FormAction ' Purpose: To find open / existing forms and perform a specific action on the form ' 'S' - Call Search on Form should be a sub on the form called 'Search' or 'RefreshData' ' 'R' - Refresh the Form should be a sub on the form called 'RefreshData' ' 'C' - Clear the Form should be a sub on the form called 'ClearForm' ' 'I' - Check IsDirty on Form should be a sub on the form called 'IsDirty' ' 'A' - Activate the Form should bring the form to the front '------------------------------------------------------------ PerformFormAction = False If System.Windows.Forms.Application.OpenForms.Count > 0 Then For Each frm As Form In My.Application.OpenForms If frm.Name = FormName Then Select Case FormAction Case "A" System.Windows.Forms.Application.OpenForms(FormName).Focus() End Select PerformFormAction = True End If Next End If End Function Please do let me know if you see a logic flaw or something I am doing here that could be causing the problem. I have posted this in the Microsoft forums, but your help has been much better so far. Mark Dahl Hi Mark
Ive taken a quick look. I will look at little harder in a couple of hours. It looks like you use the navigateTo parameter as a url to navigate to and then pass this varibale in as a form name as well? Dim myNode As myTreeNode > myNode = CType(NavigatorClickSelect, myTreeNode) OpenWebManageScreen this passes thisUrl not form name into> If myNode.FilePath <> "NULL" Then > OpenWebManageScreen(myNode.FilePath, Navigator) > End If ProcessNavigatorClick So in ProcessNavigatorClick this code If System.Windows.Forms.Application.OpenForms.Count > 0 Then > For Each frm As Form In My.Application.OpenForms doesn't find the form to focus because you have passed in a Url rather than> If frm.Name = FormName Then > Select Case FormAction > Case "A" a form name? Please confirm this with the debugger.... otherwise i will have a better look later. tm Show quoteHide quote "Fr15ky" <shilohs***@gmail.com> wrote in message news:1138317770.329442.212380@g43g2000cwa.googlegroups.com... > Toff, > > Microsoft suggested that event too. And I originally used code from > Microsoft's site to process the link. The problem is that if you select > a Node then close the form that was opened by that click. Then click > the same Node again, the AfterSelect code does not fire. Using > AfterSelect still had the same problem, so I will show you a little > more of the code involved here. This code is in a module called > NavigatorProcesses > > Class myTreeNode > Inherits TreeNode > Public FilePath As String > Public RollOverText As String > > Sub New(ByVal fp As String) > MyBase.New() > > Dim strTemp() As String > strTemp = Split(fp, "||") > > FilePath = strTemp(0) > Me.Text = strTemp(1) > RollOverText = strTemp(2) > End Sub > End Class > > Public Sub ProcessNavigatorClick(ByVal NavigatorClickSelect As > TreeNode) > Dim nodeCount As Integer = > NavigatorClickSelect.GetNodeCount(True) > If nodeCount > 0 Then > If NavigatorClickSelect.ImageIndex = 0 Then > NavigatorClickSelect.ImageIndex = 1 > Else > NavigatorClickSelect.ImageIndex = 0 > End If > NavigatorClickSelect.SelectedImageIndex = > NavigatorClickSelect.ImageIndex > NavigatorClickSelect.Toggle() > Else > Dim myNode As myTreeNode > myNode = CType(NavigatorClickSelect, myTreeNode) > If myNode.FilePath <> "NULL" Then > OpenWebManageScreen(myNode.FilePath, Navigator) > End If > End If > End Sub > > Public Sub OpenWebManageScreen(ByVal NavigateTo As String, ByVal > Parent As Form) > Dim WebManage As New WebManager > > If Not PerformFormAction(NavigateTo, -1, "A") Then > WebManage.URLStart = NavigateTo > WebManage.Show() > End If > End Sub > > Public Function PerformFormAction(ByVal FormName As String, > Optional ByVal FormID As Long = 0, Optional ByVal FormAction As String > = "") As Boolean > '------------------------------------------------------------ > ' Procedure: FormAction > ' Purpose: To find open / existing forms and perform a specific > action on the form > ' 'S' - Call Search on Form should be a sub on > the form called 'Search' or 'RefreshData' > ' 'R' - Refresh the Form should be a sub on > the form called 'RefreshData' > ' 'C' - Clear the Form should be a sub on > the form called 'ClearForm' > ' 'I' - Check IsDirty on Form should be a sub on > the form called 'IsDirty' > ' 'A' - Activate the Form should bring the > form to the front > '------------------------------------------------------------ > > PerformFormAction = False > > If System.Windows.Forms.Application.OpenForms.Count > 0 Then > For Each frm As Form In My.Application.OpenForms > If frm.Name = FormName Then > Select Case FormAction > Case "A" > > System.Windows.Forms.Application.OpenForms(FormName).Focus() > End Select > PerformFormAction = True > End If > Next > End If > End Function > > Please do let me know if you see a logic flaw or something I am doing > here that could be causing the problem. > > I have posted this in the Microsoft forums, but your help has been much > better so far. > > Mark Dahl > Toff,
First of all, thank you for all your help! Second, I do change the name of the form to the URL that is passed to the form. My reason for doing this has to do with how my.application.openforms works. According to this site, http://msdn2.microsoft.com/en-us/library/microsoft.visualbasic.applicationservices.windowsformsapplicationbase.openforms.aspx (at least originally - it appears that the comment was removed) it had said you could only access the form by it's Index (which I would not know) and the Name property. So here is the code from the WebManager: Private Sub WebManager_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load LoadComplete = False Me.Icon = ApplicationIcon Me.Name = URLStart wbrWebManager.Navigate(New Uri(URLStart)) LoadComplete = True End Sub Thanks again. Mark Dahl Hi Mark,
Ok i cant see anything specific from the code you've supplied. What are your property settings is the treeview form set to TopMost or something? tm "Fr15ky" <shilohs***@gmail.com> wrote in message http://msdn2.microsoft.com/en-us/library/microsoft.visualbasic.applicationservices.windowsformsapplicationbase.openforms.aspxnews:1138380899.608870.100050@f14g2000cwb.googlegroups.com... > Toff, > > First of all, thank you for all your help! > > Second, I do change the name of the form to the URL that is passed to > the form. My reason for doing this has to do with how > my.application.openforms works. According to this site, > Show quoteHide quote > (at least originally - it appears that the comment was removed) it had > said you could only access the form by it's Index (which I would not > know) and the Name property. So here is the code from the WebManager: > > Private Sub WebManager_Load(ByVal sender As Object, ByVal e As > System.EventArgs) Handles Me.Load > LoadComplete = False > > Me.Icon = ApplicationIcon > Me.Name = URLStart > wbrWebManager.Navigate(New Uri(URLStart)) > > LoadComplete = True > End Sub > > Thanks again. > > Mark Dahl > Toff, Cor and anyone else interested,
>From the Microsoft forum, someone suggested using the MouseMove event to actually process the click (this is apparently the last Mouse eventthat is processed) and this worked. So to show you what changed, here is the code: Private Sub tvwNavigator_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tvwNavigator.KeyDown Try If e.KeyCode = Keys.Enter Then If Not tvwNavigator.SelectedNode.Equals(Nothing) Then ProcessNavigatorClick(tvwNavigator.SelectedNode) End If End If Catch ex As Exception End Try End Sub Private Sub tvwNavigator_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwNavigator.MouseDown Try tvwNavigator.SelectedNode = tvwNavigator.GetNodeAt(e.X, e.Y) _SiteSelected = True Catch ex As Exception End Try End Sub Private Sub tvwNavigator_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwNavigator.MouseMove Try If _SiteSelected Then _SiteSelected = False ProcessNavigatorClick(tvwNavigator.SelectedNode) End If Catch ex As Exception End Try End Sub Hope that helps anyone else out there that has this problem. Mark Dahl
Web activation
Using Classes as List Items i can't round SystemIndexOutOfRangeException error using Generics dynamically (?) File upload to website and rezise at the same time ADO.NET 2.0 TableAdapter Configuration Wizard Using a delegate FileSystemWatcher UNC Path Invalid Launch a program and a function by File Type |
|||||||||||||||||||||||