How to prevent shadow from hiding under window? - c#

I have this issue where I open an extra window with window.show()
Which logically will draw on top of my first window(the part where the shadow is drawn).
But I want the new window to draw behind the shadow, or at least force the first window to redraw on top, so I don't get this effect that if I mouse over my original window the shadow pops back into view.
Any ideas? I tried window.focus() and window.Active(), window.show()..
Thanks!
http://i.imgur.com/GTes1NR.gifv

add eventHandler onloaded for this new Window in first window and in this handler you can set Focus on first window (this)
window.Loaded += (sender, args) => this.Focus();
window.Show();
For me it works.

Related

Popup window in C#.net

How to popup a child form when I click the button. I want to child winform to be in the centre of the screen and the whole background screen should be blurred. and a small close button should be visible in the right corner of the form. I have searched the web but found nothing.
Using Winforms.
Make a new windows form. it has a close button by default. Set it default position to center screen. Then on your button click.
Lets say your new form is Form2
Form2 frm = new Form2();
frm.ShowDialog();
it will not make the rest of screen blurred but user will not be able to do anything with it.
For blurry effect a workaround has been posted here
You can trigger event from click button like this
Form form1=new Form();
form1.show;
and after that to blurr the parent screen use opacity property of and increase or decrease it accord to your requirement.
you can also control the transparency of the child form using a timer and increase paacity with timer click it will make it more dynamic and interactive.

Some questions about Windows Presentation Foundation (C#)

I am working on a program that contains (among other things) a WPF window for which I am using the next code to maximize it at a MouseDoubleClick Event:
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
this.Topmost = true;
Now, what I want to do is that when the window is maximized and the mouse exits the screen (goes to the bottom of the screen until it exits the screen) a new window to appear at the bottom of the screen(WPF or WindowsForm) that will contains several things (buttons, a scrollBars, etc) and that will be active only as long as the mouse is over it (just like in BSplayer). My question is how to do that ? I'm really a starter with WPF, I don't know XAML and I would prefer to do as much as I can using C# code.
So: how do I know when the mouse leaves the screen and how do I make that window to appear on bottom of the screen (without minimizing or doing anything else with the original window) ?
I tried using this.MouseLeave but it doesn't work when the window is maximized.
And if I am asking this question here, I will use my chance to also ask two other things:
When the WPF window is maximized and if the mouse hasn't been moved for more than 5 seconds, than I want the mouse to be hidden and to become visible again only when the mouse moves. How do I do this ?
When the WPF window is not maximized, I want that the border of the screen to be very small, almost invisible (no minimize, close or other button). I am using this.WindowStyle = System.Windows.WindowStyle.ToolWindow but it still leaves the exit/close button there; If I use this.WindowStyle = System.Windows.WindowStyle.None it looks perfect, but then I can't move the window. I there anyway to make the window movable with WindowStyle.None ? Preferably, when I keep the mouse pressed on the interior of the screen, I want to be able to drag the WPF window around on my screen.
Really need help to these problems. It's a pretty important project that I am working on.
Answer to this question
When the WPF window is maximized and if the mouse hasn't been moved for more than 5 seconds, than I want the mouse to be hidden and to become visible again only when the mouse moves. How do I do this ?
This can be achieved by using the timer with an interval of 5 seconds. When timer elapse set mouse cursor to None to hide it and when mouse moves, reset the mouse cursor to original one.
Put below code in the constructor:
this.MouseMove += new MouseEventHandler(MainWindow_MouseMove);
tm = new System.Timers.Timer();
tm.Interval = 5000;
tm.Elapsed += new System.Timers.ElapsedEventHandler(tm_Elapsed);
tm.Start();
Below are event defination:
void MainWindow_MouseMove(object sender, MouseEventArgs e)
{
tm.Stop();
tm.Start();
// Reseting the time back to original. Here I have assumed that original one is Arrow.
this.Dispatcher.Invoke(new Action(() =>
{
Mouse.OverrideCursor = Cursors.Arrow;
}));
}
void tm_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
this.Dispatcher.Invoke(new Action(() =>
{
if (Mouse.OverrideCursor != Cursors.None)
{
Mouse.OverrideCursor = Cursors.None;
currentCursor = Mouse.OverrideCursor;
}
}));
}
Hope this helps !!

Prevent window redraw when resizing c# windows forms

What windows message or event can i listen to in order to stop a window from being redrawing every pixel of it's resize?
That is, when a user clicks on the edge of the window and starts to re-size it, i don't want to re-draw the entire contents until he lets go. This is because for some reason it's currently choppy at resizing probably because everything is re-docking and what not.
I tried WM_SIZING but that only tells me it's being re-sized, i wish to know the start and end of the sizing so i can suspend the layout until the user stops resizing.
Nevermind, just found these two events.
this.ResizeBegin += (s, e) => { this.SuspendLayout(); };
this.ResizeEnd += (s, e) => { this.ResumeLayout(true); };
Works a treat

Anchoring a Windows Forms Tooltip to the mouse

I want to show a tooltip when hovering over a button and as long as the mouse is over the button the tooltip should follow the mouse. What is the correct way to achieve that?
When I add a MouseMove event that calls tooltip.Show(...) with the updated mouse position it flickers extremely, and also redraws the tooltip when the mouse rests. And if it is an OwnerDraw tooltip I can see the default system tooltip style "fighting" with the self-drawn tooltip.
Indeed, with .Net 2.0 the ToolTip object has been altered. Before 2.0, there were some inconsistency problems when the ToolTip text was changed while the ToolTip was active, or with some other situations.
Since 2.0, the Tooltip is hidden each time something happens what could affect the currently active Tooltip.
While this solved some problems, it now causes some events being fired right after e.g. a SetToolTip(), even if this function has been called from within this very event, resulting in an endless loop of ToolTip draw/hide until the mouse moves away from the ToolTip area.
My own workaround is to check whether the ToolTip is already the same and omitting the Set ToolTip() if so. (simply omitting the next event by a static flag as suggested above can cause problems as there is no guarantee that there will be a new event right after, e.g. if the mouse has just touched the ToolTip area and moved away already).
Also, using OnMouseHover just to display a Tooltip disables the internal timer functionality of the ToolTip component as well as causing many many unnecessary events and therefore wastes processor time. The Popup Event of the ToolTip component serves well as point of action.
In this special case, however, OnMouse Hover is necessary to track the mouse movement.
Anyways, altering the ToolTip position causes a complete redraw of the Tooltip and therefore flicker. This can be reduced for a motionless mouse by checking whether the mouse position has changed between two events.
Unfortunately, the ToolTip component has no way to change the position of the ToolTip adn is shown always relative to the current mouse position. So the only way to have it follow the mouse is to close and redraw it.
it MAY help to set the UseFading and/or UseAnimation properties to false so the flicker can be further reduced.
OK, this may be complete overkill, and probably not the best solution, but I think a fun little hack nonthless.
Basically, I'm drawing a ListView at the location of the mouse. Some code:
ListView v = new ListView();
public Form1()
{
InitializeComponent();
v.Items.Add("Foo");
v.Height = 30;
v.Width = 50;
this.button1.Controls.Add(v);
v.MouseMove += new MouseEventHandler(v_MouseMove);
v.BackColor = SystemColors.Info;
this.button1.MouseMove += new MouseEventHandler(button1_MouseMove);
}
void v_MouseMove(object sender, MouseEventArgs e)
{
v.Location = new Point(v.Location.X + e.Location.X, v.Location.Y + e.Location.Y);
}
void button1_MouseMove(object sender, MouseEventArgs e)
{
v.Location = e.Location;
}
I've noticed that when manually showing a tooltip with OnMouseHover, OnMouseMove gets called one more time after the tooltip is shown. As a hack, I've ignored the next OnMouseMove call immediately following the tooltip being shown (using a flag). Perhaps a similar phenomenon is occurring?

Maximizing child mdi in limited area

I have a form which is a mdicontainer and has a menu strip at the top. I add a child form to my mdi container and when I maximize the child it maximizes over the menustrip. I want to know how to limit the child to maximize below the menustrip. Any help would be appreciated.
Your child form is being maximized in the way that child forms are supposed to be maximized in MDI. It's not really covering the menu strip of the parent form - it's actually merging its own menu strip with that of the parent form.
To make the child form take up only the available child area in the MDI parent (and not merge its menu with the parent's menu), put something like this code in the child form's Resize event:
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
this.Size = this.MdiParent.ClientSize;
this.Location = new Point(0, 0);
}
which will prevent the child window from being actually maximized.
I say "something like this code" because this snippet doesn't work exactly right. The ClientSize property of the parent form gives the overall size of the form, whereas you want to use the size of just the MDI client area. I don't know how to get that, and apparently it's not super-easy. See this question:
Size/Location of Winforms MDI Client Area
You could set the MaximumSize property so that it doesn't fill up the entire container.
I know this an old question, but I just ran into this on an old project I'm working on, so here's an answer for anyone seeing this. Setting the Dock to DockStyle.Fill will give you the behaviour you want.
Just be aware that the window will act/look strange if you try to reposition or resize the window while it has that DockStyle.
To accomplish this, I subscribed to the MDI client window's resize event and if the window had just been maximized, I set its DockStyle to Fill, set the FormBorderStlye to FixedDialog(to prevent resizing), and set the window state to normal to prevent the maximization from occurring.
To prevent the user from moving the window while it is in this "maximized state" I simply overrode the WndProc method and handled when the window was being moved(SC_MOVE) and placed a return to prevent the action from taking effect.

Categories

Resources