|
Hi,
Thanks for your sample code, that will very helpful me to learning C# WPF program.
Now, I have a question, How can i moving whole the "resizing window" ?
Does it can calling the "DragMove();" method ?
if you have any idea, please share to me, Thanks.
|
|
|
|
|
Hi, I had some minor issues with the code (which btw is great) and added a minimum and maximum window size to the code.
Cheers, Martin
private void updateSize()
{
try
{
PointAPI p = new PointAPI();
GetCursorPos(out p);
if (resizeRight)
{
var right = this.resizeSize.Width - (resizePoint.X - p.X);
if (right > 0 && right < target.MaxWidth && target.MinWidth < right)
{
target.Width = right;
}
}
if (resizeDown)
{
var down = resizeSize.Height - (resizePoint.Y - p.Y);
if (down > 0 && target.MaxHeight > down && target.MinHeight < down)
target.Height = down;
}
if (resizeLeft)
{
var left = resizeSize.Width + (resizePoint.X - p.X);
if(left > 0 && target.MaxWidth > left && target.MinWidth < left)
{
target.Width = left;
target.Left = resizeWindowPoint.X - (resizePoint.X - p.X);
}
}
if (resizeUp)
{
var up = resizeSize.Height + (resizePoint.Y - p.Y);
if (up > 0 && target.MaxHeight > up && target.MinHeight < up)
{
target.Height = up;
target.Top = resizeWindowPoint.Y - (resizePoint.Y - p.Y);
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
|
|
|
|
|
|
Hello
I tried your resizer and liked it very much!
But!: I did some tests with it and found a bug:
1) I graped a border and
2) let the mouse fly uncontrolled across the screen.
-> The application crashed because of negative width/ height:
func:updateSize: "-635" ist kein gültiger Wert für die Eigenschaft "Height".
Solution:
Just put an try and catch in the updateSize function and you are done.
Alternativ:Inser a check if the new Size-Values are greater than zero, before it is assigned to target.
After this the resizer rocks!!!
Keep on the good work!
Best regards Tom
|
|
|
|
|
I mixed your code with Kirupa's blog post about WPF window resizing here: http://blog.kirupa.com/?p=256[^]
Here's the result! I fixed a few bugs with cursors changing too soon. There's still a bug though where if the window is resized to an area less than the NE, SW, or SE corners, the cursor will go back to an arrow. Strange.
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows;<br />
using System.Windows.Controls;<br />
using System.Windows.Data;<br />
using System.Windows.Documents;<br />
using System.Windows.Input;<br />
using System.Windows.Media;<br />
using System.Windows.Media.Imaging;<br />
using System.Windows.Shapes;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Interop;<br />
using System.Threading;<br />
using System.Windows.Media.Effects;<br />
<br />
namespace DNBSoft.WPF<br />
{<br />
public class WindowResizer<br />
{<br />
private Window target = null;<br />
<br />
private bool stopCursorChanges = false;<br />
<br />
private bool resizeRight = false;<br />
private bool resizeLeft = false;<br />
private bool resizeUp = false;<br />
private bool resizeDown = false;<br />
private bool resizeLeftUp = false;<br />
private bool resizeLeftDown = false;<br />
private bool resizeRightUp = false;<br />
private bool resizeRightDown = false;<br />
<br />
private Dictionary<UIElement, short> leftElements = new Dictionary<UIElement, short>();<br />
private Dictionary<UIElement, short> rightElements = new Dictionary<UIElement, short>();<br />
private Dictionary<UIElement, short> upElements = new Dictionary<UIElement, short>();<br />
private Dictionary<UIElement, short> downElements = new Dictionary<UIElement, short>();<br />
private Dictionary<UIElement, short> leftUpElements = new Dictionary<UIElement, short>();<br />
private Dictionary<UIElement, short> rightUpElements = new Dictionary<UIElement, short>();<br />
private Dictionary<UIElement, short> leftDownElements = new Dictionary<UIElement, short>();<br />
private Dictionary<UIElement, short> rightDownElements = new Dictionary<UIElement, short>();<br />
<br />
private PointAPI resizePoint = new PointAPI();<br />
private Size resizeSize = new Size();<br />
private Point resizeWindowPoint = new Point();<br />
<br />
private delegate void RefreshDelegate();<br />
<br />
public WindowResizer(Window target)<br />
{<br />
this.target = target;<br />
<br />
if (target == null)<br />
{<br />
throw new Exception("Invalid Window handle");<br />
}<br />
}<br />
<br />
#region add resize components<br />
private void connectMouseHandlers(UIElement element)<br />
{<br />
element.MouseLeftButtonDown += new MouseButtonEventHandler(element_MouseLeftButtonDown);<br />
element.MouseEnter += new MouseEventHandler(element_MouseEnter);<br />
element.MouseLeave += new MouseEventHandler(setArrowCursor);<br />
}<br />
<br />
public void addResizerRight(UIElement element)<br />
{<br />
connectMouseHandlers(element);<br />
rightElements.Add(element, 0);<br />
}<br />
<br />
public void addResizerLeft(UIElement element)<br />
{<br />
connectMouseHandlers(element);<br />
leftElements.Add(element, 0);<br />
}<br />
<br />
public void addResizerUp(UIElement element)<br />
{<br />
connectMouseHandlers(element);<br />
upElements.Add(element, 0);<br />
}<br />
<br />
public void addResizerDown(UIElement element)<br />
{<br />
connectMouseHandlers(element);<br />
downElements.Add(element, 0);<br />
}<br />
<br />
public void addResizerRightDown(UIElement element)<br />
{<br />
connectMouseHandlers(element);<br />
rightDownElements.Add(element, 0);<br />
}<br />
<br />
public void addResizerLeftDown(UIElement element)<br />
{<br />
connectMouseHandlers(element);<br />
leftDownElements.Add(element, 0);<br />
}<br />
<br />
public void addResizerRightUp(UIElement element)<br />
{<br />
connectMouseHandlers(element);<br />
rightUpElements.Add(element, 0);<br />
}<br />
<br />
public void addResizerLeftUp(UIElement element)<br />
{<br />
connectMouseHandlers(element);<br />
leftUpElements.Add(element, 0);<br />
}<br />
#endregion<br />
<br />
#region resize handlers<br />
private void element_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)<br />
{<br />
stopCursorChanges = true;<br />
GetCursorPos(out resizePoint);<br />
resizeSize = new Size(target.Width, target.Height);<br />
resizeWindowPoint = new Point(target.Left, target.Top);<br />
<br />
#region updateResizeDirection<br />
UIElement sourceSender = (UIElement)sender;<br />
if (leftElements.ContainsKey(sourceSender))<br />
{<br />
resizeLeft = true;<br />
}<br />
if (rightElements.ContainsKey(sourceSender))<br />
{<br />
resizeRight = true;<br />
}<br />
if (upElements.ContainsKey(sourceSender))<br />
{<br />
resizeUp = true;<br />
}<br />
if (downElements.ContainsKey(sourceSender))<br />
{<br />
resizeDown = true;<br />
}<br />
if (leftDownElements.ContainsKey(sourceSender))<br />
{<br />
resizeLeftDown = true;<br />
}<br />
if (rightDownElements.ContainsKey(sourceSender))<br />
{<br />
resizeRightDown = true;<br />
}<br />
if (rightUpElements.ContainsKey(sourceSender))<br />
{<br />
resizeRightUp = true;<br />
}<br />
if (leftUpElements.ContainsKey(sourceSender))<br />
{<br />
resizeLeftUp = true;<br />
}<br />
#endregion<br />
<br />
Thread t = new Thread(new ThreadStart(updateSizeLoop));<br />
t.Name = "Mouse Position Poll Thread";<br />
t.Start();<br />
}<br />
<br />
private void updateSizeLoop()<br />
{<br />
try<br />
{<br />
while (resizeDown || resizeLeft || resizeRight || resizeUp || resizeLeftDown || resizeLeftUp || resizeRightDown || resizeRightUp)<br />
{<br />
target.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, new RefreshDelegate(updateSize));<br />
target.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, new RefreshDelegate(updateMouseDown));<br />
Thread.Sleep(20);<br />
}<br />
stopCursorChanges = false;<br />
target.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, new RefreshDelegate(setArrowCursor));<br />
}<br />
catch (Exception)<br />
{<br />
}<br />
}<br />
public void InitializeWindowSource(object sender, EventArgs e)<br />
{<br />
hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;<br />
}<br />
<br />
#region updates<br />
private void updateSize()<br />
{<br />
PointAPI p = new PointAPI();<br />
GetCursorPos(out p);<br />
<br />
if (resizeRight)<br />
{<br />
target.Cursor = Cursors.SizeWE;<br />
ResizeWindow(ResizeDirection.Right);<br />
}<br />
<br />
if (resizeDown)<br />
{<br />
target.Cursor = Cursors.SizeNS;<br />
ResizeWindow(ResizeDirection.Bottom);<br />
}<br />
<br />
if (resizeLeft)<br />
{<br />
target.Cursor = Cursors.SizeWE;<br />
ResizeWindow(ResizeDirection.Left);<br />
}<br />
<br />
if (resizeUp)<br />
{<br />
target.Cursor = Cursors.SizeNS;<br />
ResizeWindow(ResizeDirection.Top);<br />
}<br />
if (resizeRightDown)<br />
{<br />
target.Cursor = Cursors.SizeNWSE;<br />
ResizeWindow(ResizeDirection.BottomRight);<br />
}<br />
if (resizeRightUp)<br />
{<br />
target.Cursor = Cursors.SizeNESW;<br />
ResizeWindow(ResizeDirection.TopRight);<br />
}<br />
if (resizeLeftDown)<br />
{<br />
target.Cursor = Cursors.SizeNESW;<br />
ResizeWindow(ResizeDirection.BottomLeft);<br />
}<br />
if (resizeLeftUp)<br />
{<br />
target.Cursor = Cursors.SizeNWSE;<br />
ResizeWindow(ResizeDirection.TopLeft);<br />
}<br />
<br />
}<br />
<br />
[DllImport("user32.dll", CharSet = CharSet.Auto)]<br />
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);<br />
private const int WM_SYSCOMMAND = 0x112;<br />
private HwndSource hwndSource;<br />
<br />
private void ResizeWindow(ResizeDirection direction)<br />
{<br />
switch (direction)<br />
{<br />
case ResizeDirection.Top:<br />
target.Cursor = Cursors.SizeNS;<br />
break;<br />
case ResizeDirection.Bottom:<br />
target.Cursor = Cursors.SizeNS;<br />
break;<br />
case ResizeDirection.Left:<br />
target.Cursor = Cursors.SizeWE;<br />
break;<br />
case ResizeDirection.Right:<br />
target.Cursor = Cursors.SizeWE;<br />
break;<br />
case ResizeDirection.BottomLeft:<br />
target.Cursor = Cursors.SizeNESW;<br />
break;<br />
case ResizeDirection.TopRight:<br />
target.Cursor = Cursors.SizeNESW;<br />
break;<br />
case ResizeDirection.BottomRight:<br />
target.Cursor = Cursors.SizeNWSE;<br />
break;<br />
case ResizeDirection.TopLeft:<br />
target.Cursor = Cursors.SizeNWSE;<br />
break;<br />
}<br />
SendMessage(hwndSource.Handle, WM_SYSCOMMAND, (IntPtr)(61440 + direction), IntPtr.Zero);<br />
}<br />
<br />
public enum ResizeDirection<br />
{<br />
Left = 1,<br />
Right = 2,<br />
Top = 3,<br />
TopLeft = 4,<br />
TopRight = 5,<br />
Bottom = 6,<br />
BottomLeft = 7,<br />
BottomRight = 8,<br />
}<br />
<br />
private void updateMouseDown()<br />
{<br />
if (Mouse.LeftButton == MouseButtonState.Released)<br />
{<br />
resizeRight = false;<br />
resizeLeft = false;<br />
resizeUp = false;<br />
resizeDown = false;<br />
resizeLeftUp = false;<br />
resizeLeftDown = false;<br />
resizeRightUp = false;<br />
resizeRightDown = false;<br />
}<br />
}<br />
#endregion<br />
#endregion<br />
<br />
#region cursor updates<br />
private void element_MouseEnter(object sender, MouseEventArgs e)<br />
{<br />
if (!stopCursorChanges)<br />
{<br />
bool resizeRight = false;<br />
bool resizeLeft = false;<br />
bool resizeUp = false;<br />
bool resizeDown = false;<br />
bool resizeRightUp = false;<br />
bool resizeRightDown = false;<br />
bool resizeLeftUp = false;<br />
bool resizeLeftDown = false;<br />
<br />
UIElement sourceSender = (UIElement)sender;<br />
if (leftElements.ContainsKey(sourceSender))<br />
{<br />
resizeLeft = true;<br />
}<br />
if (rightElements.ContainsKey(sourceSender))<br />
{<br />
resizeRight = true;<br />
}<br />
if (upElements.ContainsKey(sourceSender))<br />
{<br />
resizeUp = true;<br />
}<br />
if (downElements.ContainsKey(sourceSender))<br />
{<br />
resizeDown = true;<br />
}<br />
if (leftDownElements.ContainsKey(sourceSender))<br />
{<br />
resizeLeftDown = true;<br />
}<br />
if (rightDownElements.ContainsKey(sourceSender))<br />
{<br />
resizeRightDown = true;<br />
}<br />
if (leftUpElements.ContainsKey(sourceSender))<br />
{<br />
resizeLeftUp = true;<br />
}<br />
if (rightUpElements.ContainsKey(sourceSender))<br />
{<br />
resizeRightUp = true;<br />
}<br />
<br />
<br />
if (resizeLeftDown || resizeRightUp)<br />
{<br />
setNESWCursor(sender, e);<br />
}<br />
else if (resizeRightDown || resizeLeftUp)<br />
{<br />
setNWSECursor(sender, e);<br />
}<br />
else if (resizeLeft || resizeRight)<br />
{<br />
setWECursor(sender, e);<br />
}<br />
else if (resizeUp || resizeDown)<br />
{<br />
setNSCursor(sender, e);<br />
}<br />
}<br />
}<br />
<br />
private void setWECursor(object sender, MouseEventArgs e)<br />
{<br />
target.Cursor = Cursors.SizeWE;<br />
}<br />
<br />
private void setNSCursor(object sender, MouseEventArgs e)<br />
{<br />
target.Cursor = Cursors.SizeNS;<br />
}<br />
<br />
private void setNESWCursor(object sender, MouseEventArgs e)<br />
{<br />
target.Cursor = Cursors.SizeNESW;<br />
}<br />
<br />
private void setNWSECursor(object sender, MouseEventArgs e)<br />
{<br />
target.Cursor = Cursors.SizeNWSE;<br />
}<br />
<br />
private void setArrowCursor(object sender, MouseEventArgs e)<br />
{<br />
if (!stopCursorChanges)<br />
{<br />
if (!resizeDown && !resizeLeft && !resizeRight && !resizeUp && !resizeLeftDown && !resizeLeftUp && !resizeRightDown && !resizeRightUp)<br />
{<br />
<br />
target.Cursor = Cursors.Arrow;<br />
}<br />
}<br />
}<br />
<br />
private void setArrowCursor()<br />
{<br />
if (!stopCursorChanges)<br />
{<br />
if (!resizeDown && !resizeLeft && !resizeRight && !resizeUp && !resizeLeftDown && !resizeLeftUp && !resizeRightDown && !resizeRightUp)<br />
{<br />
<br />
target.Cursor = Cursors.Arrow;<br />
}<br />
}<br />
}<br />
#endregion<br />
<br />
#region external call<br />
[DllImport("user32.dll")]<br />
[return: MarshalAs(UnmanagedType.Bool)]<br />
static extern bool GetCursorPos(out PointAPI lpPoint);<br />
<br />
private struct PointAPI<br />
{<br />
public int X;<br />
public int Y;<br />
}<br />
#endregion<br />
}<br />
}<br />
<br />
|
|
|
|
|
I rebuilt your solution and the window now attempts to resize beyond the minimum size and pushes the window to move to the direction being shrunk. I wonder whats going on here.
|
|
|
|
|
If someone is still interested, this kind of resizing can be achieved by using System.Windows.Controls.Primitives.Thumb:
XAML:
...
<Thumb Name="bottomRightThumb" Height="5" Width="5" HorizontalAlignment="Right" VerticalAlignment="Bottom"
DragDelta="bottomRightThumb_DragDelta" Cursor="SizeNWSE"
BorderThickness="5" BorderBrush="Silver"/>
...
code:
...
private bool TrySetSize(double width, double height) {
if(width >= this.MinWidth && height >= this.MinHeight) {
this.Width = width;
this.Height = height;
return true;
}
return false;
}
private void bottomRightThumb_DragDelta(object sender, DragDeltaEventArgs e) {
double w, h;
w = this.Width + e.HorizontalChange;
h = this.Height + e.VerticalChange;
TrySetSize(w, h);
}
...
|
|
|
|
|
This kind of works for 1 corner. I'll post the other corners in a min
|
|
|
|
|
Just remember, the order matters - sides first, then corners.
|
|
|
|
|
Thank you! Your solution is the best. The last detail is a control template and style to mimic ResizeGrip. Here it is:
<Style x:Key="ResizeGripThumbStyle"
TargetType="{x:Type Thumb}">
<Setter Property="Stylus.IsPressAndHoldEnabled"
Value="False" />
<Setter Property="Width"
Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" />
<Setter Property="Height"
Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}" />
<Setter Property="Background"
Value="#00FFFFFF" />
<Setter Property="HorizontalAlignment"
Value="Right" />
<Setter Property="VerticalAlignment"
Value="Bottom" />
<Setter Property="Cursor"
Value="SizeNWSE" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Grid SnapsToDevicePixels="True"
Background="{TemplateBinding Background}">
<Path HorizontalAlignment="Right"
Margin="0,0,2,2"
VerticalAlignment="Bottom"
Data="M11,0L12,0 12,12 0,12 0,11z">
<Path.Fill>
<DrawingBrush TileMode="Tile"
Viewbox="0,0,4,4"
ViewboxUnits="Absolute"
Viewport="0,0,4,4"
ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#FFACB5BA"
Geometry="M0,0L2,0 2,1 1,1 1,2 0,2z M2,2L3,2 3,1 4,1 4,3 3,3 3,4 1,4 1,3 2,3z" />
<GeometryDrawing Brush="#FFC3CED3"
Geometry="M0,3L1,3 1,4 0,4z M1,2L2,2 2,3 1,3z M2,1L3,1 3,2 2,2z M3,0L4,0 4,1 3,1z" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Path.Fill>
</Path>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
|
|
|
|
|
My current task is make a window without a border (WindowStyle = None) be resizable. If I set WindowStyle = None to CanResize or CanResizeWithGrip I finish with a standard bordered window. I don't want to change window chrome and allowed to give to the user ability to change window size with a grip. I tried a couple of other solutions but this solution using a Thumb control is the simplest one. And it is working perfectly... except it doesn't capture mouse (it should) and control template is different from standard ResizeGrip. So I have improved Stanislav's solution (спасибо, братишка).
A part of window's XAML file:
<Thumb x:Name="ResizeGrip"
Grid.Row="1"
Style="{StaticResource ResizeGripThumbStyle}"
DragDelta="ResizeGripDragDelta"
MouseDown="ResizeGripMouseDown"
MouseUp="ResizeGripMouseUp" />
Window code behind:
private void ResizeGripDragDelta(object aSender, DragDeltaEventArgs aEventArgs)
{
double lWidth = ActualWidth + aEventArgs.HorizontalChange;
double lHeight = ActualHeight + aEventArgs.VerticalChange;
TrySetSize(lWidth, lHeight);
}
private void ResizeGripMouseDown(object aSender, MouseButtonEventArgs aEventArgs)
{
if (aEventArgs.LeftButton == MouseButtonState.Pressed &&
aEventArgs.RightButton == MouseButtonState.Released &&
aEventArgs.MiddleButton == MouseButtonState.Released)
{
Mouse.Capture(ResizeGrip);
}
}
private void ResizeGripMouseUp(object aSender, MouseButtonEventArgs aEventArgs)
{
if (Mouse.Captured == ResizeGrip)
{
Mouse.Capture(null);
}
}
private void TrySetSize(double aWidth, double aHeight)
{
if (aWidth < MinWidth || aHeight < MinHeight)
{
return;
}
Width = aWidth;
Height = aHeight;
}
Thumb style:
<Style x:Key="ResizeGripThumbStyle"
TargetType="{x:Type Thumb}">
<Setter Property="Stylus.IsPressAndHoldEnabled"
Value="False" />
<Setter Property="Width"
Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" />
<Setter Property="Height"
Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}" />
<Setter Property="Background"
Value="#00FFFFFF" />
<Setter Property="HorizontalAlignment"
Value="Right" />
<Setter Property="VerticalAlignment"
Value="Bottom" />
<Setter Property="Cursor"
Value="SizeNWSE" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Grid SnapsToDevicePixels="True"
Background="{TemplateBinding Background}">
<Path HorizontalAlignment="Right"
Margin="0,0,2,2"
VerticalAlignment="Bottom"
Data="M11,0L12,0 12,12 0,12 0,11z">
<Path.Fill>
<DrawingBrush TileMode="Tile"
Viewbox="0,0,4,4"
ViewboxUnits="Absolute"
Viewport="0,0,4,4"
ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#FFACB5BA"
Geometry="M0,0L2,0 2,1 1,1 1,2 0,2z M2,2L3,2 3,1 4,1 4,3 3,3 3,4 1,4 1,3 2,3z" />
<GeometryDrawing Brush="#FFC3CED3"
Geometry="M0,3L1,3 1,4 0,4z M1,2L2,2 2,3 1,3z M2,1L3,1 3,2 2,2z M3,0L4,0 4,1 3,1z" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Path.Fill>
</Path>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Hope it helps somebody someday.
|
|
|
|
|
So you were absolutely right, it helped me today, так что спасибо за это
But, there is an error in the "TrySetSize" function. When the window reached its min height, you can't adjust width even if it is still higher than minimal. And vice versa.
The corrected version:
private void TrySetSize(double aWidth, double aHeight)
{
if (aWidth >= MinWidth)
{
Width = aWidth;
}
if (aHeight >= MinHeight)
{
Height = aHeight;
}
}
|
|
|
|
|
Sample doesn't really work and crashes
|
|
|
|
|
Sample project does not work
|
|
|
|
|
Hi, In the application I want to implement the resizing functionality in ListBox Items. Is this possible with what you have provided. If yes can you provide some sample for the same.
Thanks,
Anjali
|
|
|
|
|
Hi, from a few quick thoughts I would have thought it is possible. Unfortuantly these days I work for a living (rather than being a post-grad student) so I don't have as much free time to do this sort of thing. Look at the code and have a go yourself; if you get stuck send me a small demo and i'll see what I can do (it won't be quick though).
Ps. The method here is ok but has flaws, I suggest you spend five minutes playing with the application (resizing it from all sides).
|
|
|
|
|
Hi,
title says it all really.
Thanks
|
|
|
|
|
Thanks for the bug alert; i'll look into that!
|
|
|
|
|
You can try to fix the crashes by replacing the updateSize() with this:
(I've added Math.Max checks)
private void updateSize()
{
PointAPI p = new PointAPI();
GetCursorPos(out p);
if (resizeRight)
{
target.Width = Math.Max(0, this.resizeSize.Width - (resizePoint.X - p.X));
}
if (resizeDown)
{
target.Height = Math.Max(0, resizeSize.Height - (resizePoint.Y - p.Y));
}
if (resizeLeft)
{
target.Width = Math.Max(0, resizeSize.Width + (resizePoint.X - p.X));
target.Left = Math.Max(0, resizeWindowPoint.X - (resizePoint.X - p.X));
}
if (resizeUp)
{
target.Height = Math.Max(0, resizeSize.Height + (resizePoint.Y - p.Y));
target.Top = Math.Max(0, resizeWindowPoint.Y - (resizePoint.Y - p.Y));
}
}
|
|
|
|
|
Nice code. Tried applying it to an app I'm working with in wpf/framework 3.5 only my resize isn't smooth like in your demo. I got the same result with other methods I've tried (i.e. using thumbs, etc.). Any tips?
|
|
|
|
|
I've tried it on a more complex example (see second screen shot in article) and it works relatively well although resizing down + right is certainly a little choppy. Could you email me a running binary and/or source so I can take a look please (webmaster@derek-bartram.co.uk). Thanks, Derek.
|
|
|
|
|
“One of the major roadblocks for WPF applications has been performance and it looks like this application (Yahoo Messenger) suffers the same fate. On a dual-core system with a more than plentiful graphics card, this application can’t even render the emoticon popout opening and closing without obvious pauses. Generally when anything animates, CPU usage flies right up and performance hits rock bottom.” --- Long Zheng
Could be the issue perhaps, WPF just being very slow in general, however in this case it could be me and the bodge I had to use to get this code to work.
|
|
|
|
|
Bitmap Effects on an element results in all sub elements being software renderer = BAD performance
|
|
|
|
|