views:

48

answers:

2

I try to minimize my form to system tray but when I do, the form disappears and the notification icon doesnt work :(

What am I doing wrong?

Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    If Me.WindowState = FormWindowState.Minimized Then
        Me.Visible = False
        NotifyIcon1.Visible = True
    End If
End Sub


Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick, NotifyIcon1.BalloonTipClicked
    Me.WindowState = FormWindowState.Normal
    Me.Visible = True
    NotifyIcon1.Visible = False
End Sub

I initialize NotificationIcon text, balloon tip and other stuff in the aspx page

A: 

That's in C# but the idea should be obvious :)

private void Form1_SizeChanged(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        notifyIcon1.Visible = true;
        this.ShowInTaskbar = false;
        this.Hide();
    }
    else
    {
        notifyIcon1.Visible = false;
    }
}

void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
    notifyIcon1.Visible = false;
    this.ShowInTaskbar = true;
    this.Show();
    this.WindowState = FormWindowState.Normal;
}
Idea was obvious but my mistake was forgetting to initialize Notification icon, in Form_Load
wallace740
When the form is minimized, the other events are not working
wallace740
Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick Button3.PerformClick() ' BUMP ALL End SubButton clicks every 60 seconds but when minimized, it doesnt do anything, when I resized the form (maximize) then it works again.what is the reason for this?
wallace740
Because the implementation of PerformClick checks button's property CanSelect and if it's false - does nothing: public void PerformClick(){ if (base.CanSelect) {
How can I fix this in my occasion?
wallace740
Just call the method which you have subscribed for Button.Click event (button3_Click(null, null)) instead of calling PerformClick, or redesign your classes.
Thanks a lot user472157 Button3_Click(Sender, e)solved it
wallace740
You are welcome :)
A: 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    NotifyIcon1.Icon = Me.Icon
End Sub

In the tutorial it was not telling me to include Icon in the Form Load, that was the reason.

Problem solved! :)

wallace740