I have a winform that I use to navigate through my excel workbook. The form opens on the Workbook Open event. All works fine, but I just noticed that if my application is open and I open any other, say IE, my winform remains on top and does not hide. Is there a way to tell my form to hide when my workbook or the application lose focus?
I have searched MSDN and the web and could not really find anything?
Private Sub NavigationForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'This procedure runs when the form loads. The procedure displays
'the form on the upper left hand corner of the main screen.
'It also disables and hids the btnHideForm button.
Me.Location = New Point(0, 0)
With btnHideForm
.Visible = True
.Enabled = True
End With
End Sub
Public Class ThisWorkbook
Private Sub ThisWorkbook_Startup() Handles Me.Startup
Dim navForm As New frmNavigation
navForm.Show()
End Sub
This is the code running on form load and on the workbook open
Related
TabControl
I am trying to create a quiz with tabs for each question. I want to prevent the user from clicking the above tabs to navigate and instead can only press the next button which moves onto the next tab.
I tried setting the enabled as false and then setting enabled as true inside the next button but that does not seem to work.
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
TabControl1.SelectTab(1)
End Sub
This is the piece of code which moves onto the next tab. This works fine when enabled is set to true
How do I stop a new tab from opening google.com automaticaly in visual basic. I need a blank url textbox
This is my code for new tab
Private Sub AddTabToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddTabToolStripMenuItem.Click
Dim tab As New TabPage
Dim newtab As New tab
newtab.Show()
newtab.TopLevel = False
newtab.Dock = DockStyle.Fill
tab.Controls.Add(newtab)
Form1.TabControl1.TabPages.Add(tab)
Form1.TabControl1.SelectedTab = tab
And this is the code when form loads
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim t As New TabPage
Dim newtab As New tab
newtab.Show()
newtab.TopLevel = False
newtab.Dock = DockStyle.Fill
t.Controls.Add(newtab)
TabControl1.TabPages.Add(t)
End Sub
If you wanted you could allow the user to set their own homepage.
Simply create a button, or an item in the drop down bar that says "Set Homepage"
Create a new setting for your web browser called homePage, set it to string. Do nothing else.
Next create a new form called Homepage and link it to the button you created in step one by double clicking the button and putting
homepage.show()
in the code for that button.
On the other form you created you need a text box, and a button that says save.
double click the button and put this code in the button's code block.
textbox1.text = my.settings.homePage
my.settings.save()
Finally on your original browser form, under form1_load put this line of code
webbrowser1.navigate(my.settings.homePage)
That should work, it did for my browser at least
It won't open a page until you actually set it to open a page. Somewhere in your code you have something that will look similar to
webbrowser1.navigate("www.google.com")
Most likely within your form_load event. Just delete that.
I have 2 forms on my application. I have the main form that opens TopMost, CenterScreen and Maximized. Then I have another form on this screen that pops open when I press a button. That second screen has a button that navigates to another screen, so when I press that button the second form closes, and the main form is suppose to close as well and the selected sheet open up.
However, the second screen closes fine, but my main screen remains open and active, while the called sheet opens but does not enable. I track down what was happening and the issue is that form all code runs, but the main screen does not seem to want to close. Here is my code:
Private Sub btnOpenDashboard_Click(sender As Object, e As EventArgs) Handles btnOpenDashboard.Click
Dim welcomeForm As New frmWelcomePage
If lblReportTitle.Text = "Employee Dashboard" Then
Me.Close() 'This works
welcomeForm.Close() 'This one remains open and active
Globals.dsbEmployeeBoard.Select() 'This one opens but is not enabled
End If
End Sub
I assume from your description that you already have a welcome form created and displayed before the form with the button is displayed.
This line of code:
"Dim welcomeForm As New frmWelcomePage"
is creating a new copy of the Welcome Page and closing it.
Instead of creating a new one, you need to reference the original one that is open.
If I recall correctly, you should be able to just remove that line and use frmWelcomPage.Close.
You need to pass a reference of your first form (Form1) to the second form (Form2), so that in the second form you can close the first form, like this:
Public Class Form2 Inherits Form
Private _form1 As Form1
Public Sub New(form1 As Form1)
Me.Form1 = form1
End Sub
End Class
Private Sub btnOpenDashboard_Click(sender As Object, e As EventArgs) Handles btnOpenDashboard.Click
If lblReportTitle.Text = "Employee Dashboard" Then
_form1.Close()
End If
End Sub
Then when you instantiate Form2, you would pass a reference to Form1, like this:
Dim form2 As New Form2(Me)
Note: Me is the instance of Form1.
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 windows form project with a main form. There is a textbox leave event that opens a new form. In that new forms load event i have a combobox item loop that populates the combobox items. It works perfectly fine if run on the main form but doesnt work on the second form. Why doesn't the comboboxes on the secondary form populate when that form is opened via a textbox_leave event from the main form?
this is the leave event
Private Sub tbChartTitle_Leave(sender As Object, e As System.EventArgs) Handles tbChartTitle.Leave
If Not tbChartTitle.Text = Nothing Then
frmTitleAttributes.Show()
End If
End Sub
This is the code that populates one of the comboboxes on the second form (it works if run on a combobox on the main form)
Private Sub frmTitleAttributes_Load(sender As Object, e As System.EventArgs) Handles Me.Load
InitializeComponent()
AddFonts()
End Sub
Private Sub AddFonts()
' Get the installed fonts collection.
Dim allFonts As New Drawing.Text.InstalledFontCollection
' Get an array of the system's font familiies.
Dim fontFamilies() As FontFamily = allFonts.Families
' Display the font families.
For i As Integer = 0 To fontFamilies.Length - 1
cbxTitleFonts.Items.Add(fontFamilies(i).Name)
Next
End Sub
make sure that the Load handler is hit after you show your form (use break point)
also you can try to call it in the Shown event
Private Sub frmTitleAttributes_Shown(sender as Object, e as EventArgs) _
Handles frmTitleAttributes.Shown
AddFonts()
End Sub