I've a custom WPF window and i implemented code when i click on title bar it maximizes full area without task bar that is OK, but when i pressed the left mouse button on title bar and move towards top then my window maximizes entire screen including task bar but i want to maximize with exemption of task bar, so please any one help me to get out of this.
Thanks,
#nagaraju.
This solution may help you :) get the position of the taskbar(Fixed Position) and set the taskbar position to the fixed one on the windows sizechange event
private double positionX;//set this value to the value of the fixed taskbar X position
private double positionY;//set this value to the value of the fixed taskbar Y position
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
label1.SetValue(Canvas.TopProperty, positionY);
label1.SetValue(Canvas.LeftProperty, positionX);
}
Related
For a Winforms textbox, when you click and drag over the text, it highlights it. Is there a way to determine which direction the user dragged over?
There is no way to get this info using the Windows TextBox selection API. For example, the EM_GETSEL message defines the starting and ending character positions of the selection, but in a predefined (sorted) order.
However you could get this info by handling the control's MouseMove event. For example:
textBox1.MouseMove += new MouseEventHandler(textBox1_MouseMove);
void textBox1_MouseMove(object sender, MouseEventArgs e)
{
Control tbCtrl = sender as Control;
// the mouse coordinate values here are relative to the coordinates of the control that raised the event
int mouseX = e.X;
...
}
By applying some logic to mouseX you could potentially discover the average direction the cursor is moving. It would work best if the user is making a linear motion. You could also handle the textbox's drag-and-drop event for similar mouse information if you only wanted the event raised while the user was dragging the mouse.
I try to create a window, that can be moves or resized via multi-touch gestures. I tried it this way. I captures the TouchDown-Event of the window and saved all active TouchDevices in a List, to know which TouchDevices are active. I catch updated and deactivated event of the TouchDevices to know when they are moved and when they are deactivated. I save the Left and Top Property of the Window and the position where the TouchDevice started and everytime the Updated event is called I move the Window to the new Position relative to the new position of the TouchDevice. This works if I move the finger. But if I don't move the finger (or just very little) the window suddenly began shaking (moving chaotically) and then soon disappears to a position outside of the screen.
I think the problem here is, that the function "GetTouchPoint" of the TouchDevice only give relative coordinates related to the window (even if I set the parameter null instead if the window reference). And because the Window moves the relative position of the TouchDevice (that doesn't move) changes too. So I did a research but wasn't able to find a way to determine the screen coordinates of the touch device.
So I hope anyone can help me how to get the absolute coordinates of the TouchDevice. Or can help me find another way to "DragMove" the window with touch.(I tried DragMove, but that only works for mouse clicks, not TouchDowns) Also I like to resize the window when two Touch Devices are active and therefor I also need absolute coordinates because otherwise same effect happens.
I ran into this issue because my taskbar is on the right edge of the screen, effectively pushing the maximized window to the right. This issue also arises when the application's window is not maximized, and floating somewhere on the screen.
Here is an extension method that fixes the coordinates based on the application window's position.
public static Point FixCoordinates(this Point point)
{
var left = Application.Current.MainWindow.Left;
var top = Application.Current.MainWindow.Top;
return new Point(point.X + left, point.Y + top);
}
You may want to pass in a window that hosts your touched control as a parameter. In my case it is application's main window.
Also, since you tagged the question with "multi-touch", here is a method which averages multiple touch coordinates:
public static Point GetAverage(this IEnumerable<Point> points)
{
var averageX = points.Average(p => p.X);
var averageY = points.Average(p => p.Y);
return new Point(averageX, averageY);
}
And I use it in the code like this:
private void TouchAdornment_TouchDown(object sender, TouchEventArgs e)
{
var touchPosition = (sender as UIElement).TouchesOver.Select(t => t.GetTouchPoint(null).Position).GetAverage().FixCoordinates();
}
I've got two background pictures, one is blurry, the other one is the same picture, but more colorful.
The default background image is the blurry one.
When I move the cursor, I'd like to change the background image from the blurry to the colorful one,
but only in a circle around the cursor,
and when I move the cursor forward, the changed background stays where the circle around the cursor went earlier.
(like when you scratch a lottery ticket with a coin)
I think I have to handle the MouseMove event, and use the MouseEventArgs cursor position,
but I cannot go through, and I really need help!
Thanks in advance!
You might want to try following this path:
Add a Canvas to your page, with the same size as both of your images
Create a clipping path in the shape of an ellipse (<Ellipse ...>) and position it outside of your image, in the canvas
Put the "blurry image" on your canvas first (below), and then the "sharp image", filling the whole canvas.
Let the ellipse be the clipping mask of your "sharp image" (using Image.Clip or YourUIElement.Clip (reference on MSDN)
Move your ellipse with the mouse cursor. The code might look like this (note: I didn't test the code):
-
imageCanvas.MouseMove += imageCanvas_MouseMove;
private void imageCanvas_MouseMove(object sender, MouseEventArgs e)
{
Point mousePosition = e.GetPosition();
Canvas.SetTop(myEllipse, mousePosition.Y - myEllipse.ActualHeight / 2);
Canvas.SetLeft(myEllipse, mousePosition.X - myEllipse.ActualWidth / 2);
}
If this works, you can increment your visual design adding animations on MouseEnter/MouseLeave, etc.
I have a WinForm app that has an image displayed in a PictureBox that has the added functionality of allowing a user to draw a rectangle on the image by clicking and dragging.
The Location, Height and Width of the rectangle are saved to disk.
When the image is viewed again I would like to automatically redraw that rectangle in the same position on the image.
When I redraw it, however, the Height and Width are fine but the location is always off.
The location is being captured in the MouseDown Event like so
private void pbSample_MouseDown(object Sender, MouseEventArgs e)
{
if (SelectMode)
{
StartLocation.X = e.X;
StartLocation.Y = e.Y;
//later on these are saved as the location of the rectangle
}
}
And I am redrawing it like so
public void DrawSelectedArea(Rectangle rect)
{
Graphics g = this.pbSample.CreateGraphics();
Pen p = new Pen(Brushes.Black);
g.DrawRectangle(p, rect);
}
Given the location from the MouseEventArgs captured during the MouseDown Event how can I calculate the correct location to redraw my rectangle?
The mouse-click points you're capturing are probably relative to the Form rather than the picture box. You either need to make sure you're capturing the coordinates properly or offset them.
Could you include a screenshot as an example?
I am developing an kind of outlook calendar application where I need to make the appointment resizable from mouse.
My first try with a thumb did not work properly so I tried another way.
What I did is that:
1) on the botton of the appointmennt panel I added a rectangle to figure out the resize zone (the thumb). The appointment panel is put on a grid panel.
2) I intercept down event on the rectangle and send event to this code:
private Point startPoint;
private void OnResizeElementMouseDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
this.MouseMove += new MouseEventHandler(ResizeEndElement_MouseMove);
this.MouseLeftButtonUp += new MouseButtonEventHandler(OnResizeElementMouseUp);
// some code to perform new height computation
Mouse.Capture(this);
}
where this is the appointment panel that own the thumb.
Decreasing height works well.
But increasing is more difficult. If I move the mouse very very slowly it's OK, if I speed it up a little bit it tends to leave out the appointment panel and then all MouseMove event are lost.
I thought Mouse.Capture() was propose to solve this kind of problem, but in fact not.
Does anybody know what is wrong in my code?
You should be using an actual Thumb control. Check out MSDN for help:
How to: Use a Thumb to Enable Dragging
you should use a thumb, but to play with mouse capture, override the protected override void OnLostMouseCapture(MouseEventArgs e) method, then you will know if you have lost the capture.