Create Notifications Box - c#

How to show a box in the taskbar?In the Forms i have added the image, but how can I show in the taskbar at the bottom right?
Like This:
Example:

You probably want to look into the NotifyIcon Class, since you are talking about the Task Bar.
For your notification form, you would target the primary screens lower right corner:
Something like this:
notifyForm.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - notifyForm.Width,
Screen.PrimaryScreen.WorkingArea.Height - notifyForm.Height);
Make sure your notification has the following property set:
notifyForm.StartPosition = FormStartPosition.Manual;

Just set its position to bottom right... assuming that is where the notification area is for every user...

Related

Creating a marquee lookalike in Windows Store Apps

im trying to create the equivalent of this(html)
<marquee behavior="alternate">Your bouncing text goes here</marquee>
in a Windows Store App, with C#
is there any control that can do this or do i have to create a custom one?
There are no Marquee controls in Windows Store Apps.
I have managed to find code doing something similar to what you are trying to do. Go take a look at WPF Marquee Text Animation. If you play around with that code you should be able to get the wanted result
The main difference with your Marquee is that once you reach the edge of the screen you want to go back the other way. Something as simple as getting the Width of your textblock and your grid and substracting them could give you the wanted result
One way to do it would be something like this :
Get the width difference of your controls
int TotalMargin = gridTest.Width - textblocktest.Width
You would then need to add continuously a value to your margin
if textblocktest.Margin.Left < TotalMargin {
textBlock.Margin = New Thickness(textblock.Margin.Left + aNumber,0,0,0)
}
else{
//Call a procedure doing the same thing but decrementing the margin until it is at 0 and then going back to adding margin
}

Positioning a StatusStrip on the bottom of a window in Windows Forms

I'm trying to keep a status bar flush up against the bottom left corner of a realizable window without overflowing. I've got it to stay in place by having a resize function that updates the location and size of the status strip, but the bottom and the right side of it are always extending past the window. Here's how I'm calculating where it should go.
statusBar.Location = new System.Drawing.Point(0, Form.Size.Height - 22);
statusBar.Size = new System.Drawing.Size(Form.Size.Width, 22);
Where 22 is the constant height I want the statusBar to be. I know there has to be some other variable I'm not taking into account in setting this that's stored in the form, but I'm not sure how to access it, or what it even is.
What am I doing wrong? And is there any other easier way to keep the statusstrip on the bottom of the window regardless of resize events?
Set the Dock property to Bottom
You have to use ClientSize instead of Size.
The following:
textBox1.AppendText(Size.ToString() + "\r\n");
textBox1.AppendText(ClientSize.ToString() + "\r\n");
yields:
{Width=300, Height=300}
{Width=284, Height=262}
Though, of course, it's easiest to just use Boo's answer.

How to show SplashScreen on the second monitor?

How to show SplashScreen on the second monitor? Now it shows only on primary monitor, but application starts on the secondary monitor.
There are no properties to control where the standard WPF splash screen shows up.
If you need to change the default behavior you need to do your own implementation. An example is available here
You can use the 'Screen' class with the WindowStartupLocation property of your splash screen (I assume you are using a Window for this).
Like:
Window someWindow = new SomeWindow();
someWindow.WindowStartupLocation = WindowStartupLocation.Manual;
someWindow.Left = Screen.AllScreens[1].Bounds.Left;
someWindow.Top = Screen.AllScreens[1].Bounds.Top;
If needed you can center it yourself ofcourse. Take the screen height and the window height and calculate the center.
Check out the System.Windows.Forms.Screen class.
You can use Screen.GetWorkingArea() to get the current display, and then set the location of the splash screen based on that. Screen.FromControl() and Screen.AllScreens may also be useful.

Getting a text area in the system tray

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.

How to dock a windows form in C#?

I just would like to know if it is possible to dock a windows form on top of the user screen? I have been trying to do this by manually setting the position of my form to the coordinates I want. But using this method, however, allows the user to change the position of the form just by dragging it. I want to make the form docked to the upper portion of the screen since this window form will server as a menu for the project I am making.
Thanks a lot. :)
I would consider using the Control.Dock property along with one of the DockStyle enumeration values.
You might need to play with the Layout too, so that you may layout your form's controls differently depending on the DockStyle selected.
You will need, in my point of view, to consider the Control.Location property so that you get to know which DockStyle value to dock your form with.
EDIT #1
Your Windows Form has a Dock property as it inherits from Control.
Let's consider the following :
Each time your form comes closer to your right-side of the screen, for example, or of the MDI container, you want to dock right, right ? (Little word play here... =P) So, you have to subscribe to the Control.LocationChanged event.
private void myForm_LocationChanged(object sender, EventArgs e) {
if (this.Location.X > 900) then
this.Dock = DockStyle.Right;
else if (this.Location.X < 150) then
this.Dock = DockStyle.Left;
else if (this.Location.Y > 600) then
this.Dock = DockStyle.Bottom;
else if (this.Location.Y < 150) then
this.Dock = DockStyle.Top;
else
this.Dock = DockStyle.None;
}
Indeed, instead of constant values, you should use the current desktop resolution and calculate a ratio from it where you want your docking to occur.
***Disclaimer:****This code is provided as-is and has not been tested. This algorithm is hopefully enough to guide you through the docking process as you need it. Further assistance may be brought upon request.* =)
It seems the Form.DesktopLocation property is the righter tool for the job as for your main window, meaning your MDI container, for instance. As for the other windows, I would go along with something that looks like the code sample provided.
Does this help?
EDIT #2
If you want to prevent Form's overlapping, perhaps the Control.BringToFront() method could do it before or after your call to the Control.Show() method, depending on what works best for you.
So after some tweaks I finally was able to get this code working.
this.DesktopLocation = new Point((Screen.PrimaryScreen.Bounds.Width / 2 - 420), 0);
I placed that line below the InitializeComponent() and it docks my form to the center of the screen with whatever resolution values.
By setting the FormBorderStyle of your form to None, you take the drag handle away from the user so they cannot move it via the mouse.
Then you just need to place it where you want.
If you really want to take away the users options you can also set the ShowInTaskbar property to false

Categories