Getting a text area in the system tray - c#

i was just wondering what i need to research to be able to have a programme that is in the system tray, when the user clicks the programme icon, just above the system tray a small text area appears allowing the user to type in a search condition. There is plenty of resources for c# and getting your programme in the system tray, but then it just opens as normal, which is not quite what i am looking for.
Thanks

One way to accomplish this is to use a standard WinForms window which contains a single text box and has no border. This window can then be displayed and positioned as normal (likely using many of the existing samples) but will appear as a floating text box.
var form = new MyTextBoxForm();
form.FormBorderStyle = BorderStyle.None;
form.StartPosition = FormStartPosition.Manual;
// position the form
form.ShowDialog();

Handle the NotifyIcon.Click event and show your form in the desired location.
For example:
var screen = Screen.PrimaryScreen;
form.Left = screen.WorkingArea.Right - form.Width;
form.Top = screen.WorkingArea.Bottom - form.Height;

Maybe with this Make your program in the system + add a menu you could try editing the menu, like you'd do a regular menu with toolstrips.... and change the label by a textbox.
Just a random idea.

Related

C# Switch off or cover duplicated monitor

I'm developing an app in C#. This app will run on a PC and also in a WACOM tablet, which is a duplicated monitor of the PC.
I want to switch off or cover the tablet with an image because the client can't see the beginning and the end of the process. When the time is right, the tablet will turn on or the screensaver will be removed so that the client can interact and, once the client's actions are finished, the WACOM tablet returns to the initial state. How can I do this?
I've been searching and I've found how to switch off the principal monitor but I don't know how to switch off only the tablet. Also some kind of screensaver would be right, but I didn't found how to put an image only in one screen.
You didn't mention the framework you are working, assuming you can reference WinForms, here is a way to show a form maximized on a specific screen:
System.Windows.Forms.Screen[] screens;
screens = System.Windows.Forms.Screen.AllScreens;
System.Windows.Forms.Screen selectedScreen = screens[1]; // choose your preffered monitor
// Sets the form to show maximized on the selected screen:
form.Left = currentScreen.Bounds.Width;
form.Top = currentScreen.Bounds.Height;
form.StartPosition = FormStartPosition.Manual;
form.Location = currentScreen.Bounds.Location;
Point p = new Point(currentScreen.Bounds.Location.X, currentScreen.Bounds.Location.Y);
form.Location = p;
form.WindowState = FormWindowState.Maximized;
form.Show();
If you disable form borders and have a PictureBox docked to "Fill" displaying your selected image you will achieve your intended goal and cover your tablet screen with an image.

How to open two same Winforms on Maximised and minimized WindowState?

I have an game as an Winform in Full Screen (no borders), maximized. But I want to present them on an different screen, like a beamer and control it on the original screen, so I need the same screen, opened twice:
One at my own screen Maximized, no borders
One at the second screen, normal state with title bar.
I'm quite sure, I'm thinking about this too easily. What I tried is:
new game().Show();
new game().Show(WindowState = FormWindowState.Normal));
But then It says:
Argument 1: cannot convert from 'System.Windows.Forms.FormWindowState' to 'System.Windows.Forms.IWin32Window'
So, is this hard to do?
Try this:
game g1 = new game();
g1.Show();
game g2 = new game();
g2.WindowState = FormWindowState.Normal;
g2.Show();
What you tried doesn't work because Form.Show() expects either nothing or another IWin32Window (typically another Form) as an argument, and you're passing a FormWindowState.
Note that, while this shows you how to open two forms of the same class with different window states, it doesn't show you how to make two different forms show the same game content at once, which will be much more involved.

Setting default position for new toolwindow in VsPackage

I'm creating a VsPackage with a ToolWindow and having an issue setting the default position of the window when it is opened for the first time. I need it docked as a new tab in the 'main window' (not exactly sure what this is called - it is the center area of the IDE where the Code Editor window opens by default.), but instead, it is opening as a floating window on in the top-left.
I understand I can move the window to the right position and it will be saved for the next time in my settings, but I would like it defaulted to this position so the users don't have to do this.
[ProvideToolWindow(typeof(MyToolWindow),
Style = Microsoft.VisualStudio.Shell.VsDockStyle.Linked,
Window = "GUID Here")]
I know I have to set a specific guid, but I can't seem to find the right one - this list doesn't seem to list what I need: https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.toolwindowguids_fields(v=vs.140).aspx
You should use Style = VsDockStyle.MDI.

Making the image go full screen in slideshow application in winforms

I have an winforms application for slideshow of images.im using a list for storing the list of image paths,picture box to display image and on click of [slideshow] button..the slideshow happens...everything is working fine but i have one problem with full screen of image... on click of slideshow,image should open in full screen same like windows image viewer. please help me,keep in mind,only image should go full screen.not the full form.
i got below code in almost all the sites but Windowstate shows an error.
targetForm.WindowState = FormWindowState.Maximized;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.TopMost = true;
targetForm.Bounds = Screen.GetBounds(targetForm);
please help me out.
thanks in advance.
I think you are trying to use different layouts for windowed and full screen mode.
When you switch to full screen you can:
programatically change PictureBox to fill the form with pictureBox.Dock = DockStyle.Fill
open another form (in full screen) that contains only the PictureBox that fills the form
Note:
First method won't work as expected if you have other controls with Dock set to something else than DockStyle.None

How do I get a disabled ToolStripButton to paint its image in colour?

We have a button which allows users to 'lock' a form. Users are not permitted to 'unlock' the form, so when pressed, we want the button to be disabled, so that the user receives appropriate visual feedback.
However, the customer reports that the greyed 'lock' icon suggests to them that the form is not locked, so we would like to display the button in a pressed state, but with the icon in colour, even though the button is disabled.
How do we do that, with the absolute minimum amount of overridden painting?
Actually I disagree with the approach. Your customer might have a valid point, but I don't think they have the correct suggestion for the fix. You should look into other ways to make the form appear "locked". Changing borders or font colours, having a big padlock icon appear or change from open to closed etc. Buttons look a certain way because that's what users expect. If you have a disabled button that looks like it might be enabled, that's going to confuse users who might not then understand why they can't click it.
You can set the ToolStripButton Image as BackgroundImage
and then set the DiplayStyle to None.
The picture should stay in colour no matter what's the button Enabled value.
I was in this case few weeks ago and this question doesn't have an answer, so this is my solution 4 years later :
I'm using this solution to repaint the ToolStripButton in many cases : disabled, checked, selected
override OnPaint event or change renderer of your ToolStrip
draw your image without grey filter with this method, just set the image of the button and image's position on your button : http://msdn.microsoft.com/en-us/library/chas0s9c(v=vs.110).aspx
Two good examples who helped me :
http://tutorials.csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Customizing_a_Renderer
http://jskiles1.wordpress.com/2009/08/22/33/)
ToolStrip class :
ToolStrip ts = new ToolStrip();
//[...]
ts.RenderMode = ToolStripRenderMode.Professional; //Professional is just an example
ts.Renderer = new CustomRenderer();
CustomRenderer class :
public class CustomRenderer: ToolStripProfessionalRenderer
{
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
{
if (!e.Item.Enabled) //in this case you will just have the image in your button, you need to add text etc in this if
{
//to draw the image
Graphics g = e.Graphics;
g.DrawImageUnscaled(e.Item.Image, new Point(2, 2)); //you need to specify the correct position
}
else //other cases
base.OnRenderButtonBackground(e);
}
}
The problem is to know the correct position of all elements in your ToolStripButton , that's why I drawn the ToolStripButton in every cases
Another way: don't set the button.Enabled = false at all. Just set the button.Checked = true or false and when someone clicks on the button test for the Checked state and do whatever you do. The button will then function as you want and stay colored too.

Categories