C# - Using a NotifyIcon from an User Control - c#

This is something that surprisingly wasn't able to find a solution online.
I have in my main form a couple of user control, that after doing a certain action, I want to show a notification icon.
The examples shown about doing from a different form don´t apply to User Controls, as you can't directly reference the form that is using it.
In the case the question is a bit confusing:
Application
- Main Form
--NotifyIcon
--UserControl
---Button that when pressed, show the NotifyIcon
--UserControl
---Button that when pressed, show the NotifyIcon
I´m using VS2010 by the way.

Related

App has too many tabs opened in the task-bar

I'm making a WinForm app in C# (Visual studio) for fun. I came across a low-priority problem. It doesn't affect how the app works. But...
On the starting page, I have a button to open a Form1, inside Form1, there's a button to open a Form2 and so on.
At runtime, when I open a form, its parent form does not close and every form is a separate tab in the task-bar. As the layers grow, I'll have more-than-acceptable amount of tabs down there...
Is there a way to have only 1 tab?
I've tried:
Adding a parentForm.close() line when opening the form, but that was bad.
Instead of creating another form, putting everything in a panel, and bringing out another panel using code, but if there are too many layers, the code gets ridiculously long.
There has to be a simpler way right? Please shed some light.
Yes, you have a property in every form called ShowInTaskbar which is true by default. You can change that in the form properties under Window Style section or changing it by code manually:
Form2.ShowInTaskbar = false;
Form2.ShowDialog();
Configure to false all forms but the first one in order to achieve your desired behaviour.
Make sure your opened forms are dialogs or you are put them on top so user can never get in the situation where the form is behind and they cannot close it.
Anyway, with a proper form parenting configuration (if it fits your needs) you won't need this, as children forms won't appear in the taskbar.
If a form is parented within another form, the parented form is not displayed in the Windows taskbar.
Make sure you check the MSDN Documentation about this.

C# - Finding Coordinates of a Winform application

I have a simple login screen windows form application and I am controlling that application through an adapter now i want to find the coordinates of the textboxes and button, I tried using the coordinates after right clicking the textbox control and picking the location from its property but it did not work. So i want to find the proper location, as windows form application form size can be changed during the run-time. So, how can i find the windows form coordinates.
I have tried using the coordinates provided in the properties of the textbox and button controls but those did not work.
IntPtr childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intFirstNameCoordX,intFirstNameCoordY));
This is how i want to find the window.
I want to find the textbox and buttons position in windows form. I was googling and found some Spy++ tool but i am not sure if that is what i require and if it is then can anyone please guide me how i can use it to find the position in a simple window form application.
OK, I can see that you are using WinApi functions, so I won't go deeper into that, just give you some idea.
First, you can get the main window handle. You can get the handle by process (enum process windows) or by it's caption. If you want to get the handle by caption you can use FindWindow
This handle is the window handle. Next, you can enum it's child windows - for example panels or other controls, using EnumChildWindows
Now the rest depends on your GUI architecture. You may have edits and buttons in panels, so you will have to search for child windows of that panel. You may have controls just put on your main window - so you just search for child controls of that window.
Next, when you find the control, you're interested in, you can get more info, using for example GetWindowRect

C# Form with buttons and dynamic forms beside those buttons

I am using Windows form in C# and i am trying to create one single form dialog that will be responsible displaying other dialogs within the boundary of it's dialog. To do that i tried Tab Control and it worked well and i can create different types of form in tab control easily without opening any separate forms.
but the problem is i don't want to use Tab control , I have some buttons on the main form at left side and clicking those buttons i want to display separate forms beside those buttons. I searched google but did not find any example like that nor i am able to find any control as this. My application is very simple one dialoge with left side buttons and on right side i want to show different forms based on those buttons... C# is not my native language but now i have to work on it and require help.
Kindly check the attached image for more information
Each page could be an instance of Panel, then show/hide the Panel instances according to which button is clicked....make them all the same size, shape, and position ;)

Control click through transparency c#

I am making a form that is transparent. However, I would like to sometimes be able to click "through" the form. What I mean is that I need to be able to control whether clicks go through the form or not. I am using Windows 8, which I heard makes a difference in this case as well. How can I do this?
Thanks!
EDIT: Refining my question: I am making a form which is transparent and maximized. When a user clicks, the form catches the click then moves it from the previous location which was clicked, and clicks "through" the form at the new location. I've got most of it working in C# and WPF, but I cannot simulate clicks "through" the form. How would I do this?

User control in avalon dock and separate window

I'm developing a bunch of user controls which do different things - like a maintenance screen, enquiry screen, report screen that sort of thing. Each screen has a dedicated purpose and a single user control holds all the functionality for the one screen.
I'm using avalondock and can place these user controls into LayoutDocuments. This creates a separate tab for each screen/user control. I've got a menu system setup so users can choose which screens they need access to. For each new screen I create a new LayoutDocument, add the appropriate control to it, then add the LayoutDocument to the Docking panel's children.
This is all working fine.
Avalon dock also has the feature of being able to drag out the layout document and make it float - you can also dock it somewhere else in the app if you wish.
I'd like to take this concept one step further: Being able to say right click on a layout document and choose "Make external window" (i'll work out the exact wording later). The effect of this action would be to create a new application with it's own icon in the task bar; being able to alt-tab between it and other apps;
Kind of like when you're in say Excel editing a document and you then open up a second instance of excel. In Windows 7 you get two excel icons in the task bar (one behind the other), and you can alt-tab between them.
This is nearly the behaviour that i'm after. However the second app isn't a full blown copy of the first; it has only the one user control that the user selected.
This is where i'm stuck and would like a bit of guidance.
I'm thinking that i'll probably need some kind of shell app where I can pass in the user control that I want. The shell would act as a window with title, X, minimising etc; the user control would then be the sole content of that shell. Use process.start to create new process and launch ?
Ideally i'd be able to pass in the same control in the same state as the user is currently viewing - so if for example they are part way through editing some customer record in a maintenance screen, then choose the "external window" option, that same customer record would appear in the new window.
Has anyone done something similar or offer advice if i'm on the right track ?
I think I know how to create a shell app but not sure on passing a user control to it dynamically. I'd like to avoid creating different shell apps for each user control.
No need to start a new process for that scenario.
Just create a new Window add your UserControl at runtime and remove the UserControl from the DockingManager. Make sure the Window has ShowInTaskbar set if you want it to show up there.
To get the command to undock the UserControl as a seperate Window you just have to restyle the ContextMenu to incorporate your command (take a look at the VS2010 theme and how the ContextMenu is styled there VS2010 theme.xaml).

Categories