Handling a click over a balloon tip displayed with TrayIcon's ShowBalloonTip() - c#

I use the ShowBalloonTip method of a TrayIcon class to display a balloon tip. Is there a way to handle a click over this balloon?
When I click over the balloon, no event seem to be generated, and it only closes the balloon.

I think you mean NotifyIcon . Use following pattern...
NotifyIcon notifyIcon = null;
public Form1()
{
InitializeComponent();
notifyIcon = new NotifyIcon();
// Initializing notifyIcon here...
notifyIcon.BalloonTipClicked += new EventHandler(notifyIcon_BalloonTipClicked);
}
void notifyIcon_BalloonTipClicked(object sender, EventArgs e)
{
// Operation you want...
}
I hope it feed your needs...

Have you tried the following snippet? I managed to find it whilst doing a quick google search:
private void TrayNotifyIcon_BalloonClick(object sender, EventArgs e)
{
//Perform Action
}
Obviously you'll need to make sure you specify the correct name in the method signature for your own application.
I think this was written in an older version of the .Net Framework and there's probably a newly named method for it.
Source: Build a C# Notification System

Related

Textbox_Enter event not does nothing

I want to be able to tell when the user cliked on a textbox and is in "edit" mode. Everywhere I look I see the textbox_Enter and textbox_Leave events being used with the instructions within that and it works fine. For me however it doesn't do anything. I tried elimination as many outside factors as possible, including creating a brand new project just for testing purposes and copied some code samples yet again nothing happens when I click on the textbox. I'm using Visual Studio 2017 on Windows 10 with Visual C# Application Windows Form (.NET Framework)
Also here's a sample of the code I try to use if it helps for whatever reason
private void textbox_Enter(object sender, ControlEventArgs e)
{
label.Text = "ok";
}
First of all the type of the e parameter is not correct: It must be EventArgs, not ControlEventArgs:
private void textbox_Enter(object sender, EventArgs e)
{
// Do something
}
Second, you need to register the event in the forms designer with the textbox control in the properties window:
You need to wire up this method to the textbox enter event. Select the control and then look at the events section in the properties tab.

How to add an event on a menu in C# project?

I have a C# Windows Forms App that contain a menu bar.
I want to display a Help Message when I press on the "HELP" menu button.
All that I can see when I press view code is this:
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
I think that I need to create inside the function a MessageBox or an event that will display the desired message.
Do you have any idea how should I do this, please?
Below should work for what your asking. If you are on your form you can double click the button you want to interact with, and Visual Studio should take you to the empty method.
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is supposed to be helpful");
}

How to set the focus on a form

I want to set the focus on a popup form I have created when the mouse hover it,
I checked MSDN and they said to use the SetFocuse method but it does not work.
I tried this:
private void POPUPmainmanue_MouseHover(object sender, EventArgs e)
{
POPUPmainmanue.SetFocus();
}
It's strange but I could find no SetFocus() method for a Form on MSDN.
However, using the Activate() methods works well enough.
private void POPUPmainmanue_MouseHover(object sender, EventArgs e)
{
POPUPmainmanue.Activate();
}
Also, always make sure you do not forget to set the EventHandler:
POPUPmainmanue.MouseHover += POPUPmainmanue_MouseHover;
You also did not mention whether you are using WinForms or WPF, although I think it's the former as you say 'form'. Again, what exactly is POPUPmainmanue? A form? I don't think so. A form does not have a SetFocus() method.
I don't think it's easy to implement, cause it's not very clear the question:
It's possible to set focus on textbox when the mouse hovers the form, and another more clear possiblity to set focus on a form when a form opens.
this.BringToFront();
this.Activate();

How to close a form in UserControl

I created a UserControl with the buttons Save, Close and Cancel. I want to close the form without saving on the Cancel button, prompt a message to save on the Close button and Save without closing on the Save button. Normally, I would have used this.Close() on the Cancel button, but the UserControl doesn't have such an option. So I guess I have to set a property for that.
Scrolling down the "Questions that may already have your answer" section, I came across this question: How to close a ChildWindow from an UserControl button loaded inside it? I used the following C# code:
private void btnCancel_Click(object sender, EventArgs e)
{
ProjectInfo infoScreen = (ProjectInfo)this.Parent;
infoScreen.Close();
}
This does the job for one screen, but I wonder if I have to apply this code for all the screen I have? I think there should be a more efficient way. So my question is: Do I need to apply this code for every form I have, or is there another (more efficient) way?
you can use
((Form)this.TopLevelControl).Close();
you can use the FindForm method available for any control:
private void btnCancel_Click(object sender, EventArgs e)
{
Form tmp = this.FindForm();
tmp.Close();
tmp.Dispose();
}
Do not forget to Dispose the form to release resources.
Hope this helps.
You also can close one form in any part of the code using a remote thread:
MyNamespace.MyForm FormThread = (MyNamespace.MyForm)Application.OpenForms["MyForm"];
FormThread.Close();
I found the simple answer :) I all ready thought of something like that.
To close a WinForm in a ButtonClicked Event inside a UserControl use the following code:
private void btnCancel_Click(object sender, EventArgs e)
{
Form someForm = (Form)this.Parent;
someForm.Close();
}

Open another page (not web) on C#

I'm creating a native C# application and I need to do a simple thing:
Once the user clicks some certain button, another .cs file is opened (with its own design, code and stuff). If it is possible, I would like to know how to close the current form at the same time.
EDIT: what I exactly need:
namespace Mokesciai
{
public partial class Mokesciai : Form
{
public Mokesciai()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//write code here to open another page called "NewPage.cs" with its own subfiles "NewPage.Designer.cs" and
//"NewPage.resx", as shown in the solution explorer
}
}
}
The application is C# Windows application
EDIT2: what I want in the graphical way: http://sdrv.ms/JXKVEL
By clicking "Click me" I want to open the new form
private void button1_Click(object sender, EventArgs e)
{
YourSecondForm objForm=new YourSecondForm();
objForm.Show();
this.Close();
}
Assuming YourSecondForm is the name of your another form which you want to display on the button click event.
That is a form.
You can create a new instance of the form class, then call Show().
As far as i understand from your question, may be you want to do this. You can use Process.Start() to start any other application from your native app.
using System.Diagnostics;
string path=#"path to the app"
Process.Start(path);
OR
Create a new form place a multi line text box, then read the file using StreamReader & fill its result on the text box. For more information on how to use Stream Reader Check out this or this

Categories

Resources