how to make program that be in the taskbar windows-CE - c#

how to make C# program that will be All time in the taskbar ?
i want to Build a Keyboard program.
i need that when i open the device the program will open and be in the taskbar.
another question is, when i have an external program that has a Textbox, how
to make that when i press any key in my C# keyboard it will be in this external Textbox ?
thank's in advance

It's not implemented in the CF, but the NotifyIcon class is what you're after. The SDF does implement it. It would be used something like this:
m_notifyIcon = new NotifyIcon();
m_notifyIcon.Icon = this.Icon;
m_notifyIcon.Visible = true;
m_notifyIcon.Click += new EventHandler(m_notifyIcon_Click);
m_notifyIcon.DoubleClick += new EventHandler(m_notifyIcon_DoubleClick);
EDIT
If you want to implement this yourself, the place to start is with the Shell_NotifyIcon API. You'll want to pass it the handle to a MessageWindow class and handle the WM_NOTIFY messages.

To Create a system Tray application in Windows-CE, put some code like:
CSystemTray m_TrayIcon; // Member variable of some class
...
// in some member function maybe...
m_TrayIcon.Create(pParentWnd, WM_MY_NOTIFY, "Click here",
hIcon, nTrayIconID);
Eg. For a non-MFC tray icon, do the following:
Collapse
CSystemTray m_TrayIcon; // Member variable of some class
...
// in some member function maybe...
m_TrayIcon.Create(hInstance, NULL, WM_MY_NOTIFY,
"Click here", hIcon, nID);
// Send all menu messages to hMyMainWindow
m_TrayIcon.SetTargetWnd(hMyMainWindow);
As found here:
http://www.codeproject.com/KB/shell/systemtray.aspx
To create a system tray application in Windows XP or Windows 7/Vista, put some code like this in your project:
private void Form1_Resize(object sender, System.EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
Hide();
}
and this to handle the system tray click
private void notifyIcon1_DoubleClick(object sender,
System.EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
}
This and more information found at :
http://www.developer.com/net/net/article.php/3336751/C-Tip-Placing-Your-C-Application-in-the-System-Tray.htm

Related

C# form show notifications without any tray icon

I want to use NotifyIcon, but I don't want any icons to appear in the lower right field, is this possible?
Or does anyone have an alternative solution suggestion?
I want to send a notification until the user sees the notification, the visibility will be turned on, but there will not be any icon in the lower right part. It will only appear in the notification panel on the right.
I tried to hide icon.But couldn't.
Set NotifyIcon.Visible = false
alternatively you could use the Windows Toast notification if you are using .net5.0 or higher.
As described on Microsofts site, it only works with specific TFs.
.net6 is given on MS Site, for .net5 you can use <TargetFramework>net5.0-windows10.0.17763.0</TargetFramework>
A workaround would be to only show the NotifyIcon during the time the notification is displayed and hide it immediately after. Here's a complete example:
public Form1()
{
InitializeComponent();
notifyIcon1.Visible = false;
notifyIcon1.BalloonTipClosed += notifyIcon1_BalloonTipClosed;
}
private void button1_Click(object sender, EventArgs e)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(1000, "Title", "Some text here", ToolTipIcon.Info);
}
private void notifyIcon1_BalloonTipClosed(object sender, EventArgs e)
{
notifyIcon1.Visible = false;
}

wpf application c# How to minimize/bring to front sub forms

My WPF application is a media player that has a button that launches another window to a certain location and is my webbrowser. Problem is, once i click my button to launch the browser, my 'hide' button does not hide the browser window :/, from what i researched i need to inherit button click events, take a look at the code:
private void button4_ClickWeb(object sender, RoutedEventArgs e)
{
//opens a web browser if 'Web' is clicked on the WPF Media PLayer
Window1 f1 = new Window1();
f1.Show();
}
the ideas i thought would work is create a 'toggle button' like such:
private void button4_ClickWeb(object sender, RoutedEventArgs e)
{
ToggleButton tb = (ToggleButton)sender;
if ((bool)tb.IsChecked)
{
f1.Show();
//or
f1.WindowState = WindowState.Normal;
}
else
{
f1.Hide();
f1.WindowState = WindowState.Minimized;
}
}
this approach failed, and yes i tried variations and moving things around with NO success, i was told that i need to make a class of f1 to inherit button click events but i have no idea how to do that :/ any ideas?
here is how the app looks like:

Show MessageBox immediately in Windows Forms?

Is there any way to have a messagebox immediately pop up when a form opens? I just want to display a short message about how to use the form when it opens. I tried
private void myForm_Load(object sender, EventArgs e)
{
DialogResult dialogOpen = MessageBox.Show("Use the navigation menu to get started.", "Welcome!", MessageBoxButtons.OK);
}
but it doesn't work.
Showing a MessageBox during Form_Load works just fine for me. I literally copy/pasted the code from your original post, and it worked. I'm on .NET Framework 4.5 on Windows 8.1.
Are you sure your Load event handler is getting called? Perhaps the it's not hooked up to the Load event properly.
I don't see why it wouldn't work in Form_Load. Definitely try doing as others have pointed out by putting it beneath form initialization.
Though, given that you're just showing a message box, I don't think there is any reason to store the result, so a simple MessageBox.Show(message); Should do the trick.
As #s.m. said, from a UX point of view, having a notification thrown in your face as soon as the app starts would be very obnoxious, at least if you have it EVERY time. Personally, I would create a boolean Settings variable, set it to true the first time the message is displayed, and only display it when the setting is false, i.e. the first time the message is displayed.
private boolean splashShown = Properties.Settings.Default.splashShown;
private void Form_Load(object sender, EventArgs e)
{
if (!splashShown)
{
MessageBox.Show("message");
myForm.Properties.Settings.Default.splashShown = true;
myForm.Properties.Settings.Default.Save();
}
}
And set up the splashShown Setting in your form properties.
If the problem is that your Form_Load() method isn't actually attached to your Form.Load() event, you can double click the form window in the designer and it will automatically created the Form_Load() base method for you and attach it to the Form.Load() event
Is there a reason to use the Load method of the form? If not you could to it in the constructor of form. If you want it to show up immediately after your form loads, you should do it in the constructor after the form is initialized. It should look something like this:
public partial class myForm : Form
{
public myForm()
{
InitializeComponent();
DialogResult dialogOpen = MessageBox.Show("Use the navigation menu to get started.", "Welcome!", MessageBoxButtons.OK);
}
}
The constructor (public myForm()) and the InitializeComponent(); should be automatically added to the form by Visual Studio after creating it.
Form_Load event occurs before the form is really visible.
I use:
static private bool splashShown = false;
private void Form1_Activated(object sender, System.EventArgs e)
{
if (!splashShown)
{
MessageBox.Show("message");
splashShown = true;
}
}
I have used this and it works fine. App start brings up messagebox first before all else.
InitializeComponent();
MessageBox.Show("put your message here");

Windows Application That Displays Pop-Ups While Other Programs Are Running

Firstly, I have zero experience programming with .NET so this could be a pretty nooby question...
I'm wondering if it's possible to build an application like xFire - which displays pop-ups in-game to a user.
As the primary application will have focus, how does my application manage to display it's message/popup? Does the primary application have to allow access or something?
Cheers!
Looks like you are looking for NotifyIcon, it displays little pop-ups just as know from Windows.
The example is a little long, but the documentation will surely help you understand.
using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.ComponentModel.IContainer components;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.components = new System.ComponentModel.Container();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
// Initialize contextMenu1
this.contextMenu1.MenuItems.AddRange(
new System.Windows.Forms.MenuItem[] {this.menuItem1});
// Initialize menuItem1
this.menuItem1.Index = 0;
this.menuItem1.Text = "E&xit";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
// Set up how the form should be displayed.
this.ClientSize = new System.Drawing.Size(292, 266);
this.Text = "Notify Icon Example";
// Create the NotifyIcon.
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
// The Icon property sets the icon that will appear
// in the systray for this application.
notifyIcon1.Icon = new Icon("appicon.ico");
// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon1.ContextMenu = this.contextMenu1;
// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon1.Text = "Form1 (NotifyIcon example)";
notifyIcon1.Visible = true;
// Handle the DoubleClick event to activate the form.
notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
}
protected override void Dispose( bool disposing )
{
// Clean up any components being used.
if( disposing )
if (components != null)
components.Dispose();
base.Dispose( disposing );
}
private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
{
// Show the form when the user double clicks on the notify icon.
// Set the WindowState to normal if the form is minimized.
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
// Activate the form.
this.Activate();
}
private void menuItem1_Click(object Sender, EventArgs e) {
// Close the form, which closes the application.
this.Close();
}
}
See MSDN.
"As the primary application will have focus, how does my application manage to display it's message/popup? Does the primary application have to allow access or something?"
An application can set itself as "TopMost" which means it appears in front of other "normal" applications that are not TopMost. A well behaved notification will appear without stealing focus from the current application (this is usually achieved with the ShowWindow() API and the SW_SHOWNA flag). This does not require any permission from the currently active application.
Take a look at TaskbarNotifier, a skinnable MSN Messenger-like popup in C# and now in VB.NET too.

How to start the application directly in system tray? (.NET C#)

I mean when the user starts my application(exe). I want it to start directly in system tray, without showing the window. Like antivirus softwares & download managers, which start and run in the system tray silently.
I want the same effect and when user click the "show" button of the notifyIcon's contextmenustrip then only application should show GUI.
I'm using this, but its not working
private void Form_Load(object sender, EventArgs e)
{
this.Hide();
}
May be I need to have Main() function in some other class which has no GUI but has notifyIcon & ContextMenuStrip whose option will instantiate the GUI window class. Right?
The way I usually setup something like this is to modify the Program.cs to look something like the following:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (NotifyIcon icon = new NotifyIcon())
{
icon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
icon.ContextMenu = new ContextMenu(new MenuItem[] {
new MenuItem("Show form", (s, e) => {new Form1().Show();}),
new MenuItem("Exit", (s, e) => { Application.Exit(); }),
});
icon.Visible = true;
Application.Run();
icon.Visible = false;
}
}
Using this, you don't need to worry about hiding instead of closing forms and all the rest of the hacks that can lead to... You can make a singleton form too instead of instantiating a new Form every time you click the show form option. This is something to build off of, not the end solution.
You need to set up the notify icon as well.
Either manually or via the toolbar (drag a notifyIcon onto your form) create the notifyIcon:
this.notifyIcon = new System.Windows.Forms.NotifyIcon(components);
Then add this code to Form_Load():
// Notify icon set up
notifyIcon.Visible = true;
notifyIcon.Text = "Tooltip message here";
this.ShowInTaskbar = false;
this.Hide();
Though this will, as has been pointed out, briefly show the form before hiding it.
From the accepted answer of this question, the solution appears to be to change:
Application.Run(new Form1());
to:
Form1 f = new Form1();
Application.Run();
in Main().
Have you created a Windows Application in C#?
You need to drag a NotifyIcon control onto the form, the control will be placed below the form because it has no visual representation on the form itself.
Then you set its properties such as the Icon...
Try this one first...

Categories

Resources