Can't find how to get new window (form) which will behave like "Find and replace" window in VB IDE 2008, where window is allways on top and I can work on it but I can also work with underlayed code bit find and replace don't hide when I set focus to code window.
The best solution will be if I would be oopen more than one such window.
This is how I try but opened window is modal!
Dim fl As New myWindow
With fl
.StartPosition = FormStartPosition.Manual
.aCallerLocation = Me.Location
End With
Dim ret As Integer = fl.ShowDialog(Me)
fl.Close()
fl = Nothing
Showing the form as a dialog form, is not necessary to make the form stay in front of the primary form. Using the ShowDialog method causes the form to be modal. What makes it stay in front is the fact that you are passing Me for the owner parameter. You can still pass an owner form, even if you are just calling the non-modal Show method:
Dim fl As New myWindow()
' ...
fl.Show(Me)
That way, the new form will stay in front of the primary form, but it will not be modal. Therefore, both forms will be usable and you can show as many of those non-modal child forms in front of the primary form as you like.
Related
I'm making an extremely simple app which has multiple screens (as Panels) that are hidden/shown clicking buttons on a left sidebar.
I have a PNLHome, PNLServerSettings, PNLScripts, and PNLSettings as the main panels.
Each of the Panels .Name properties are "PNLHome", "PNLServerSettings", ....etc.
I want to be able to change the "Start Up Screen" based on the selection you make in a ComboBox in PNLSettings, so when you launch the app, the Panel that is immediately showing is based on that ComboBox selection.
I have the ComboBox items in place and I have a function that hides all panels and shows the one you pass into it:
showPanel(PNLHome) for example which will essentially just show the Panel you give it, all this is working fine. This showPanel() is triggered upon clicking one of the main buttons on the left sidebar
What I want is to pass a Control.Name string into my showPanel() func, then I want to store this .Name string into My.Settings via a "Save/Apply" button in the Settings Panel which I can set up easily.
Since I will be passing the .Name String into my showPanel() function, I need to be able to reference the Panel I'm showing by it's name rather than the Object ID itself (I'm not sure if it's called an ID but it's the 'name' declaring the Panel via a "DIM WithEvents PNLHome As Panel" declaration.
To summarize the question; Can I reference the PNLHome by its .Name Property?
Otherwise can I store the ID of PNLHome directly in My.Settings instead? I could easily pass My.Settings.StartPanel into my showPanel() func.
Just use the Controls collection to find the control.
Private Function GetPanel(PanelName As String) As Panel
Dim SomePanel As Panel = CType(Controls(PanelName), Panel)
Return SomePanel
End Function
I have made this simple invoice control worksheet in excel and I use VBA to make it easier to visualize and add new items. I have made dozens of other VBA programmed Worksheets, and all of them have a "New" active x button, programmed just like this:
Private Sub ButtNew2_Click()
Dim Guia As Worksheet
Dim UltLin As Integer
Set Guia = Workbooks("Notas Fiscais.xlsm").Worksheets("SaĆda")
UltLin = Guia.UsedRange.Rows.Count + 1
Guia.Application.Goto Reference:="R" & UltLin & "C1"
FormNotasSaida.Show
FormNotasSaida.BoxDataEmiss.SetFocus
End Sub
Simple as that. Just select the first blank line so that the form loads blank. It works fine in any other Workbook. But in this one, if and every time I click this button, after closing the form, the next time (and only once) I load the form again in any possible way (either double clicking an item, pressing the "Show" button or pressing the "New" button again), it loads either blank or showing the last launched item (case you did so).
After closing it, I can click wherever or press the "Show" button whenever, they work fine, as they always have. The problem occurs exclusively once, after pressing the "New" button.
What am I possibly doing wrong, specially knowing that this method works perfectly in all other workbooks?
FormNotasSaida.Show
FormNotasSaida.BoxDataEmiss.SetFocus
Forms are a special kind of class modules with a designer and a predeclared ID attribute. This "predeclared ID" is what's at play here: you're using/reusing the default global instance of the class, and [unless you close it with the X button in the control box,] never unload it so you're always showing the same form.
A best practice is to create a new instance of the form every time you use it:
Set frm = New FormNotasSaida
frm.Show
frm.BoxDataEmiss.SetFocus
I have a WinForm application that have an automatic logout after some time without activity performed by the user, that application have some dialog box like
SearchCustomer.ShowDialog()
If the user left that dialog opened and the time expire the user is automatically logged out but that dialog box remains opened, so anybody can use that dialog even with the user logged out.
There's any way to close those dialog box from main Form?
Edit:
There's another Dialog box opened in a different way
AddCustomer.Show()
AddCustomer.BringToFront()
Edit 2 Solution based on jmcilhinney answer
For Each openForm In openForms
Dim H1 As Integer = openForm.GetHashCode()
Dim H2 As Integer = Me.GetHashCode()
If H1 <> H2 Then 'No igual
openForm.Close()
End If
Next
I haven't tested but I would think that you should be able to do something along these lines:
Dim openForms = My.Application.OpenForms.Cast(Of Form)().ToArray()
For Each openForm In openForms
openForm.Close()
Next
Here is an option.
Open your form with the ownership attribute.
AddCustomer.Show(Me)
'This open the form and gives the referring form ownership.
'It Also gives focus to the child form, keeping it on top of the referring form
When the referring form closes, so does the child form.
Using VB.Net (Windows Application)
I have one main form(Data entry form), i creating many form at run time.
Code for creating a multiple form at run time.
Button1 click
If IsNothing(frm) OrElse frm.IsDisposed Then
newfrm = New frmEntry
End If
newfrm.Show()
I have popup windows for selcting the value in the Data entry form.
Code for selcting the value from popup windows
Popup Window code
If e.KeyCode = Keys.Enter Then
frmEntry.txtbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
The above popup window code is working for Data Entry Form, but it is not working for new forms (at run time)
When i select the value from popup windows means, it is appearing in frmentry textbox, not in newfrm textbox.
Popup windows selected value should appear in current active form.
What wrong in my code.
Need VB.Net Code Help
If the form you open the popup from is what you need to change values in, have you considered passing a reference to the opening form to the popup when you open it? So that you have direct access to the form that has the controls that will need updated?
This constructor in the popup window:
Private mOpeningForm As frmEntry
Public Sub New(OpeningForm As frmEntry)
InitializeComponent()
mOpeningForm = OpeningForm
End Sub
This modified to use the reference to the form sent to the popup form:
If e.KeyCode = Keys.Enter Then
mOpeningForm.txtbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
This in the form when the window is being created at runTime:
If IsNothing(mEntryForm) OrElse mEntryForm.IsDisposed Then
mEntryForm= New frmEntry(me)
End If
mEntryForm.Show()
At the top level of the Data Form Class (The one creating the popups)
private mEntryForm as frmEntry
That will allow you to have a reference to the Instance of frmEntry from anywhere in the data form class. (Note that I changed the name of the popup form instance in for the button click event code too)
I have 3 forms, one frmMain - main form, second is frmUserType- childform, and the last frmCreateUserType. In the main form I have a menu item to open my frmUserType, In this form I have a button to open another form which is my frmCreateUserType, In this form I have a button to add records then update the listview in frmUserType. The problem is the listview will not access with my add button control in frmCreateUserType. I tried not to used mdiparent declaration for my frmMain and frmUserType as children and it works, so meaning that the problem is showing my frmUserType as childform?I am using vb.net 2008
Any suggestion would greatly appreciated
Thans in advance
Code to open my second form (frmUserType)
Dim frmChildUserType As New frmUserType
frmChildUserType.MdiParent = Me
frmChildUserType.WindowState = FormWindowState.Maximized
frmChildUserType.Show()
Code for my add button to update the listview in frmUserType
frmUserType.lsvUserType.Items.Clear()
FillListViewUserType("SELECT * FROM pr_user_type", frmUserType.lsvUserType)
You're creating a new instance as:
Dim frmChildUserType As New frmUserType
But in your code:
frmUserType.lsvUserType.Items.Clear()
FillListViewUserType("SELECT * FROM pr_user_type", frmUserType.lsvUserType)
You're not accessing that instance but is instead using the default instance of frmUserType. So I think you're updating a different instance of the ListView than what you think.
If you change your code to instead be:
frmChildUserType.lsvUserType.Items.Clear()
FillListViewUserType("SELECT * FROM pr_user_type", frmChildUserType.lsvUserType)
I think it would work as you expect.
If you don't know what a default instance is, you can find a blog about them here (I think they're a bad idea).