@pcinfogmach כתב בשאלה בwpf האם יש דרך להסיר את הצל שסביב האובייקט window:
אבל מסתבר שאם עושים את זה אז מאבדים את היכולת לשנות את הגודל של החלון.
עריכה: צריך לעשות כך במקום
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="0"
CornerRadius="0"
CaptionHeight="0"/>
</WindowChrome.WindowChrome>
מצו"ב על הדרך קוד לuserform עם אפשרות דומה לחלון של הגדלה וגרירה (לא מושלם אבל עובד)
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace newresizableusercontrol
{
public partial class MainWindow : Window
{
private enum HitType
{
None, Body, UL, UR, LR, LL, L, R, B, T
};
private HitType MouseHitType = HitType.None;
private bool DragInProgress = false;
private Point LastPoint;
public MainWindow()
{
InitializeComponent();
}
private HitType SetHitType(Grid grid, Point point)
{
double left = Canvas.GetLeft(grid);
double top = Canvas.GetTop(grid);
double right = left + grid.Width;
double bottom = top + grid.Height;
const double GAP = 10;
if (point.X < left || point.X > right || point.Y < top || point.Y > bottom)
return HitType.None;
if (point.X - left < GAP)
{
if (point.Y - top < GAP) return HitType.UL;
if (bottom - point.Y < GAP) return HitType.LL;
return HitType.L;
}
else if (right - point.X < GAP)
{
if (point.Y - top < GAP) return HitType.UR;
if (bottom - point.Y < GAP) return HitType.LR;
return HitType.R;
}
if (point.Y - top < GAP) return HitType.T;
if (bottom - point.Y < GAP) return HitType.B;
return HitType.Body;
}
private void SetMouseCursor()
{
Cursor desiredCursor = Cursors.Arrow;
switch (MouseHitType)
{
case HitType.None:
desiredCursor = Cursors.Arrow;
break;
case HitType.Body:
desiredCursor = Cursors.ScrollAll;
break;
case HitType.UL:
case HitType.LR:
desiredCursor = Cursors.SizeNWSE;
break;
case HitType.LL:
case HitType.UR:
desiredCursor = Cursors.SizeNESW;
break;
case HitType.T:
case HitType.B:
desiredCursor = Cursors.SizeNS;
break;
case HitType.L:
case HitType.R:
desiredCursor = Cursors.SizeWE;
break;
}
if (Cursor != desiredCursor) Cursor = desiredCursor;
}
private void canvas1_MouseDown(object sender, MouseButtonEventArgs e)
{
MouseHitType = SetHitType(rectangle1, e.GetPosition(canvas1));
SetMouseCursor();
if (MouseHitType == HitType.None) return;
LastPoint = e.GetPosition(canvas1);
DragInProgress = true;
}
private void canvas1_MouseMove(object sender, MouseEventArgs e)
{
if (DragInProgress)
{
Point point = e.GetPosition(canvas1);
double offsetX = point.X - LastPoint.X;
double offsetY = point.Y - LastPoint.Y;
double newX = Canvas.GetLeft(rectangle1);
double newY = Canvas.GetTop(rectangle1);
double newWidth = rectangle1.Width;
double newHeight = rectangle1.Height;
switch (MouseHitType)
{
case HitType.Body:
newX += offsetX;
newY += offsetY;
break;
case HitType.UL:
newX += offsetX;
newY += offsetY;
newWidth -= offsetX;
newHeight -= offsetY;
break;
case HitType.UR:
newY += offsetY;
newWidth += offsetX;
newHeight -= offsetY;
break;
case HitType.LR:
newWidth += offsetX;
newHeight += offsetY;
break;
case HitType.LL:
newX += offsetX;
newWidth -= offsetX;
newHeight += offsetY;
break;
case HitType.L:
newX += offsetX;
newWidth -= offsetX;
break;
case HitType.R:
newWidth += offsetX;
break;
case HitType.B:
newHeight += offsetY;
break;
case HitType.T:
newY += offsetY;
newHeight -= offsetY;
break;
}
if ((newWidth > 0) && (newHeight > 0))
{
Canvas.SetLeft(rectangle1, newX);
Canvas.SetTop(rectangle1, newY);
rectangle1.Width = newWidth;
rectangle1.Height = newHeight;
LastPoint = point;
}
}
else
{
MouseHitType = SetHitType(rectangle1, e.GetPosition(canvas1));
SetMouseCursor();
}
}
private void canvas1_MouseUp(object sender, MouseButtonEventArgs e)
{
DragInProgress = false;
}
}
}
היה מעניין אבל מרגיש לי קצת בזבוז זמן. שוין.