When i login into my application and i get to the menu form, after the form triggers the form.shown after 1 second timer i start an update procedure.
This procedure calls another form which is on top the menu form, and does certain things.
This update form can also be called from a button that is on the menu form.
The problem here is when i call this form from the button the taskbar is hidden and also the menu form which is at the back is unclickable(I set my application to be full screen so taskbar is not visible). When the update form opens from the timer the taskbar appears, and the menu form which is at the back is clickable, and the user can click buttons from the parent form.
I tried setting focus on the update form after is loaded from the processes of windows but it didn't change anything.
I dont want to show the taskbar nor have clickable parent form.
Any idea why is this happening and how can i fix it?
Here is how i call my form from timer and from the button:
Private Sub TimerDelayedStart_Tick(ByVal sender As Object, ByVal e As Timers.ElapsedEventArgs)
TimerDelayedStart.Stop()
LoadUpdateDatabase()
End Sub
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
LoadUpdateDatabase()
End Sub
Private Sub LoadUpdateDatabase()
Try
fUpdateDatabase = New frmUpdateDatabase
With fUpdateDatabase
.ShowDialog()
Cursor = Cursors.Default
End With
Catch ex As Exception
End Try
End Sub
Related
I have problem about close() or dispose() function with my barcode reader (Windows Embedded Compact 7). In this case I can only hide() form.
I tried to show Form2 as dialogue but after I clicked the close button (to hide this form and go back to Form1) It made all of my application close
In Form1 (Main):
Public Sub showForm2()
Dim secForm As New Form2
secForm.ShowDialog()
End Sub
In Form2:
'close button
Private Sub closebt_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles closebt.Click
Me.Hide()
End Sub
Form can't be hidden if it is shown as Dialog. If you want to hide the form then use form.show() rather than form.ShowDialog(). Also here is a link
http://www.vbforums.com/showthread.php?759061-How-can-i-hide-my-second-form-dialog-without-bliking-form-not-closing-my-first-form
Go to properties page of the project. In the Application tab, there is a setting:
Shutdown mode
When startup form closes
When last form closes
Choose "When last form closes" to prevent closing the application when your main form closes.
in the index form add in form closing the fallow code:
Form1.Dispose()
I have two forms in my project (Form1.vb with screen called "MainPanel", and From2.vb with screen called "frmTestSelect"). I have a button on the MainPanel that opens frmTestSelect. frmTestSelect is a much smaller screen/form than MainPanel. When both forms are open, I want a user to be able to click on the MainPanel form, thus closing the frmTestSelect screen. As of right now, when I click on the MainPanel, all it does is bring MainPanel into focus but leaves the FrmTestSelect screen open in the background. I want to close it if MainPanel's focus or any of it's object's focus is true. What is the simplest way to do this? Thank you.
Dim frmTestSelect As Form2 = Nothing
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
frmTestSelect = New Form2
frmTestSelect.Show()
End Sub
Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles Me.Activated
If frmTestSelect IsNot Nothing Then
frmTestSelect.Close()
End If
End Sub
Update: Changed Form1 event to Activated so that it closes Form2 even if a control on Form1 was clicked.
You can keep a reference to the live instance of frmTestSelect in MainPanel (in a member variable for example), and invoke .Close() on it if MainPanel gets focus.
If you make MainPanel an MDIParent, and frmTestSelect an MDIChild (by specifying .MDIParent = MainPanelInstance), you can access all MDIChildren of MainPanel any time you gain focus, and close said children.
That said, if you go the MDIParent route, the child form will never get "hidden" behind its parent.
Is there a simple way to Activate the form when any controls in the form is clicked like datagirdview, panel, menustrip, button, textbox, label, etc....
it happens that my project can show many different form and it's hard for me to activate one form when it's on the back of the active form. I need to clicked the border of the form to activate it.
most likely your problem arises because your form is MDI child.. you'll have to click the menu bar to activate the form.. but if you have a borderless form, clicking on controls wont activate the form.. again, this usually happens on MDI but it shouldnt happen on a regular winform.. unless you have other running events in the background that interferes with the process.
You question is not clear at all, and I don't know what you are trying to archieve, but for executing something with a click event you have to add the handler for every control.
If you are declaring it not dinamically just:
Private Sub ControlsClick(sender As Object, e As EventArgs) _
Handles Panel1.Click, Button1.Click, TextBox2.Click ' etc.
Me.Activate 'Or Whatever
End Sub
You have to add the handler for each control. The same if you do it dinamically:
Private Sub InitializeClickHandlers(sender As Control, Optional bChilds As Boolean = True)
For Each elem As Control In sender.Controls
AddHandler elem.Click, AddressOf ControlsClick(elem, New EventArgs)
If bChilds AndAlso elem.Controls.Count > 0 Then
Call InitializeClickHandlers(sender)
End If
Next
End Sub
Then, for every control in the form, you call it like: Call InitializeClickHandlers(Me)
Or, for every control inside a panel: Call InitializeClickHandlers(Panel1)
In the main form "frmMain.vb" I have a button that when it is clicked runs the following code:
Dim myform as New frmMyDialog
myform.ShowDialog()
On the "frmMyDialog.vb" form the user can start a public function of the main form and I need to hide the dialog until the function ends, so I wrote this code:
Private Sub btnStartProcess_Click(sender As System.Object, e As System.EventArgs) Handles btnStartProcess.Click
'hide the dialog
Me.Hide()
'start the sub of the main form
frmMain.TestSub()
'close the dialog
Me.Close()
End Sub
However, when the dialog becomes hidden, the main form is minimized. How can I hide the dialog without also hiding the main form?
(The "formBorderStyle" property of "frmMyDialog.vb" is "FixedDialog", I don't know if it can help.)
I have a Visual Studio, Visual Basic form that includes an OK button and a Cancel button.
What I want to do is have the OK button save the options that the user chooses and of course the Cancel button discarding them and returning them to their previous values.
But what I'm noticing is that as I'm debugging the form, the values are being saved regardless of whichever button I'm choosing. On the form's properties, I have declared that indeed the CancelBtn is the CancelBtn and that the OK button is the OK button, but the values are still being saved regardless.
Is there a better way to do what I would like this form to do?
EDIT:
Here's the code so far for the two buttons, both are being set to close the window. AcceptOption should save the values and CancelOption should just close the form. I'm sorry if this isn't done well but the FAQ's that I found only mention changing the properties of each button and nothing about the code.:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles AcceptOptionBtn.Click
' Save the Options
Me.Close()
' Close the form
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles CancelOptionBtn.Click
' Close the form
Me.Close()
End Sub
Don't change "the values" until the user clicks the Save button.
The form should be preloaded with a copy of the values you would like to update.
The Cancel button should just close the form.
The Save button should cause "the values", not the forms copy, to be updated.
EDIT:-
In regard to this question, there is nothing wrong with the code you have posted. Are the right handlers being called for the right button clicks? Are the form's AcceptButton and CancelButton properties set to the right buttons?
What data are your editing controls bound to, if at all?
There's nothing magical about OK and Cancel buttons. They're just... buttons. If you save your data every time a change is made, the Cancel button won't magically "unsave" them. Though if you save changes in the OK button's Click event handler, then clicking the Cancel button obviously won't save your changes. To help you further we'd need to know how you save your data.
Edit:
From looking at your code, I think you're passing data directly to your form, without performing a copy of your objects. Therefore if you modify this data, it will also be changed in the parent form. By working with a copy of your data in this form, any changes which aren't saved will be correctly discarded.
Your event handler for the cancel button should look like this:
Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Your event handler for the OK button should look like this:
Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
SaveSettings 'call a routine to save the settings the user has entered
Me.Close()
End Sub
It is as simple as that!
If you open your form like
myForm.showdialog()
you don't have to define the handler for the close button click event, it is automatically handled; just set the 'DialogResult' property for the button
btnCancel.DialogResult = DialogResult.Cancel
Also if you want to close the form when ESC is pressed then set the 'CancelButton' property for the form:
myForm.CancelButton = btnCancel
On the other hand if you open the form like
myForm.Show()
you do need to specify the action(s) to take on the close button click event as indicated here, ie:
Private Sub BtnCancelClick(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnCancel.Click
Close()
End Sub
I was having the same issues. As soon as I use My.Settings.Blabla = Blabla.value, it gets saved even if I haven't used My.Settings.Save() which makes My.Settings.Save() completely pointless as far as I can tell.
I ended up taking up Jordell's advice: Don't change "the values" until the user clicks the Save button but it wasn't too clear for me how to go about it.
I ended up using temporary variables in all my settings subs instead of the user My.Settings.UserConfigs. Only when I was in the OK sub did I call
My.Settings.UserConfigSetting = temporary_UserCofigValue
Here is an example from the code I was working on:
Private Sub btnOptionsThemeLB_Back_Update_Click(sender As System.Object, e As System.EventArgs) Handles btnOptionsThemeLB_Back_Update.Click
If (tempOptionsThemeLB_Back = Nothing) Then
tempOptionsThemeLB_Back = Me.btnOptionsThemeLB_Back.BackColor
End If
tempOptionsThemeLB_Back = RGBToColor(txtbOptionsThemeLB_Back_Red.Text, txtbOptionsThemeLB_Back_Green.Text, txtbOptionsThemeLB_Back_Blue.Text, tempOptionsThemeLB_Back)
Me.btnOptionsThemeLB_Back.BackColor = tempOptionsThemeLB_Back
End Sub
And only withing the Ok sub did I call My.Settings.
'Theme Section
My.Settings.colorBtnBack = tempOptionsThemeLB_Back