I made picturebox which would change if the mover is over the image but it takes too long. can someone help me please?
Here's my code:
Private Sub button2_MouseHover(sender As Object, e As EventArgs) Handles button2.MouseHover
button1.Visible = True
button2.Visible = False
End Sub
Private Sub button1_MouseLeave(sender As Object, e As EventArgs) Handles button1.MouseLeave
button1.Visible = False
button2.Visible = True
End Sub
Thanking you in advance
If you want to adjust the time the mouse must pause over the image, the docs say;
A typical use of MouseHover is to display a tool tip when the mouse pauses on a control within a specified area around the control (the "hover rectangle"). The pause required for this event to be raised is specified in milliseconds by the MouseHoverTime property.
To achieve that, simply change the value of SystemInformation.MouseHoverTime in your code.
Alternatively, as someone has commented, use a MouseEnter event instead, this will trigger instantly.
Related
I have to create a Loading form, while processing a calculus. This form should prevent any action to the other forms while performing this calculus so the most proper command to use should be ShowDialog(). I've also found that I need to run this command, in order to prevent the form freezing, with a BackgroundWorker. So what I've done is to define the button - that will start the calculus - and the BackgroundWorker itself. So this is what I wrote:
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Form18.ProgressBar1.Minimum = 0
Form18.ProgressBar1.Value = 0
Form18.ShowDialog()
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
[calculus code and progressbar progression]
If Form18.ProgressBar1.Value = Form18.ProgressBar1.Maximum Then
Form18.Close()
hrrnativexcel.Visible = True
End If
End Sub
Even if I'm using the BackgroundWorker, when I press the button, the loading form - declared in my code as Form18 - becomes blocked and progressbar gets stuck at 0% loading. Could anyone tell me where I am doing wrong? I've tried to find something about BackgroundWorker with ShowDialog command but I haven't found anything that could help me. Thanks in advance.
I would like to know if there is a way of keeping the Original Animation to keep my VB application as close to original as possible.
Private Sub Minimize_Click(sender As Object, e As EventArgs) Handles Minimize.Click
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
End Sub
I expect the minimize action to play the animation that ocurs in most if not all of the windows applications.
[Edit]:
All the apps I have installed have the default minimize animation because they all use the same windows bar, but my program doesn't because I find it not very attractive, so I created my own Print By programming the button myself I lose the animation.
You could use the opacity to create an animation of sorts.
Private Sub Minimize_Click(sender As Object, e As EventArgs) Handles Minimize.Click
For disapper As Single = 1.0! To 0 Step -0.2!
Me.Opacity = disapper
'Me.Refresh()
System.Threading.Thread.Sleep(50)
Next
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
Me.Opacity = 1.0!
End Sub
So I found that the problem is that my formborderstyle propety is set to none and the animation isn't shown when it is set to none I solved it by doing this, but even tho it works it worses things even more... For now I will stick with having no animation at all unless someone finds a solution. Thanks.
Private Sub Minimize_Click(sender As Object, e As EventArgs) Handles Minimize.Click
Me.FormBorderStyle = FormBorderStyle.FixedSingle
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
Me.FormBorderStyle = FormBorderStyle.None
End Sub
Any app minimization animation is in windows settings, and can be turned off anyway. I Don't think you can force it if you have it disabled in your userprofile System Properties settings.
This can be found in sysdm.cpl in Advanced -> Performance
So i have a tray icon that should behave the same way between 3 forms. I then created this code:
Private Sub TrayForm_MouseClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseClick
If e.Button = MouseButtons.Right Then
If Not Application.OpenForms().OfType(Of TrayForm).Any = 1 Then
TrayForm.ContextMenuStrip1.Show(Cursor.Position)
End If
End If
End Sub
Which is used to handle the tray icon. How can i do to share this event between the forms so i don't have to place this same code on every form?
How are event handlers working exactly? I looked online and on MSDN and it is not clear to me.
Thanks
Are you sure that you want to share the event, and not juste the code that will handle the event?
If you don't want to copy and paste your code, which you need to handle the events of more than one form, here's a way to do it:
Declare the sub which contains the code needed to handle the event as a public shared sub. Like this:
Public Shared Sub TrayForm_MouseClick(sender As Object, e As MouseEventArgs)
So, now you have a Sub which can handle the event you want to handle from all three forms.
Now, when you initialize those forms, add a line to make the shared Sub handle the event you want it to handle:
AddHandler NotifyIcon1.MouseClick, AddressOf ProjectName.FileName.TrayForm_MouseClick
ProjectName.FileName is meant here to be the path to refer to the shares Sub inside the file where you put it. I usually name it like ProjectNameUtils.vb or something like that.
If you just want to avoid copy and pasting your Sub so you don't have to modify it at several places every time you change something, this could be a way to achieve that.
As Stipulated by Hans Passant:
Sub Eclass_EventHandler(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
If e.Button = MouseButtons.Right Then
If Not Application.OpenForms().OfType(Of TrayForm).Any = 1 Then
Me.ContextMenuStrip1.Show(Cursor.Position)
End If
End If
End Sub
On the Trayform.VB just did the trick.
But about the shared event. i Have one that would have to be:
Private Sub FormClosingEVENT(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Not FromMenu Then e.Cancel = True
Me.WindowState = FormWindowState.Minimized
'Application.Exit()
End Sub
How should i handle this?
When I maximize my borderless form, the form covers the entire screen including the taskbar, which I don't want it to do. I'm finding it very difficult to find a solution to my problem on the net, all I've come up with is the below code, which displays the taskbar for a short time, but then disappears and the form still takes up the entire screen.
Private Sub TableLayoutPanel1_DoubleClick(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.DoubleClick
If e.Location.Y < 30 Then
Me.WindowState = FormWindowState.Maximized
Me.ControlBox = True
End If
End Sub
I'm starting to think the only way to solve my problem is to find the screen size height minus the taskbar height to get the form height, but I'm hoping there might be a simpler answer.
Use the form's Load event to set its maximum size, like this:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.MaximumSize = Screen.FromRectangle(Me.Bounds).WorkingArea.Size
End Sub
Maximizing it now restricts the size to the monitor's working area, which is the monitor size minus the taskbars.
Use the "working area" of the screen:
Me.Bounds = Screen.GetWorkingArea(Me)
You should better do this:
Me.MaximumSize = Screen.FromControl(Me).WorkingArea.Size
Because some users use multiple monitors. So if you use Hans Passant's way, when user maximize application to secondary monitor, application will get primary's monitor working area size and will look awful!!!
I think this is a better way to solve your problem
Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Normal
Me.StartPosition = FormStartPosition.Manual
With Screen.PrimaryScreen.WorkingArea
Me.SetBounds(.Left, .Top, .Width, .Height)
End With
End Sub
I have a NumericUpDown Control on a form. In the Application Settings / Properties Binding, for the value parameter, i can't select my USER setting called : Heures (Integer / User).
I tried to save the value by this way :
Private Sub NumericUpDownHeures_Leave(sender As System.Object, e As System.EventArgs) Handles NumericUpDownHeures.Leave
My.Settings.Heures = NumericUpDownHeures.Value
My.Settings.Save()
End Sub
But it's not saved.
No problem for other settings (String / User). But i don't understand why the settings (Integer / User) are not saved.
Please help, Thanks.
As you are putting "NumericUpDown1.Value" you have to set the value at My.Settings.Heures to decimal.
In Form1_Load add:
NumericUpDownHeures.Value = My.Settings.Heures
and add to the event listener for your button or other widget:
My.Settings.Heures = NumericUpDownHeures.Value
I would guess the issue is that the Leave event is not being fired as you expect it to be, especially if the user just clicks the up/down arrows. I suspect that it is only fired when the user actually clicks into the value area, then leaves. You could verify this by debugging to see if your code is ever hit or by showing a simple msgbox from that event.
I think that you will have better luck if you hook the LostFocus or ValueChanged event.
I want to add to this as well for anyone looking at this in the future.
Save your settings as shown already by putting
My.Settings.Heures = NumericUpDownHeures.Value into your ValueChanged event, and then doing reverse in the form load event.
The problem is, this value changed event fires before the form load when you first initialize, so it will keep defaulting to whatever value you have set in the designer because you're overwriting the setting value with the designer value.
To get around this, you need a private/public boolean at the top of your code that is only set to true once your form has loaded (set to true at the bottom of your form_load event), then you can add the condition to the ValueChanged event checking if the form is loaded yet or not. If it is, then change the setting value, if not, then don't.
An example:
Private IsFormLoaded As Boolean = False
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
NumericUpDown1.Value = My.Settings.SavedNumValue
IsFormLoaded = True
End Sub
Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
If IsFormLoaded = False Then Exit Sub
My.Settings.SavedNumValue = NumericUpDown1.Value
End Sub
OR
Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
If IsFormLoaded Then
My.Settings.SavedNumValue = NumericUpDown1.Value
End If
End Sub