Forum
merhaba
c# içerisinde eklemiş olduğum picturebox ı form üzerinde mouse tıklatarak seçmek ve köşelerinde oluşacak olan noktalardan mouse a basılı tutarak boyutlandırmak istiyorum. bu konu hakkında yardımlarınızı bekliyorum.
Teşekkürler.
Merhabalar;
Aşağıda ki kod yardımcı olacaktır, ayrıca bu linkte örnek bir proje bulabilirsiniz.
https://www.codeproject.com/Articles/13184/Runtime-resizable-controls
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MovingControlByMouse
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Control draggedPiece = null;
bool resizing = false;
private Point startDraggingPoint;
private Size startSize;
Rectangle rectProposedSize = Rectangle.Empty;
int resizingMargin = 5;
private void piece_MouseDown(object sender, MouseEventArgs e)
{
draggedPiece = sender as Control;
if ((e.X <= resizingMargin) || (e.X >= draggedPiece.Width - resizingMargin) ||
(e.Y <= resizingMargin) || (e.Y >= draggedPiece.Height - resizingMargin))
{
resizing = true;
// indicate resizing
this.Cursor = Cursors.SizeNWSE;
// starting size
this.startSize = new Size(e.X, e.Y);
// get the location of the picture box
Point pt = this.PointToScreen(draggedPiece.Location);
rectProposedSize = new Rectangle(pt, startSize);
// draw rect
ControlPaint.DrawReversibleFrame(rectProposedSize, this.ForeColor, FrameStyle.Dashed);
}
else
{
resizing = false;
// indicate moving
this.Cursor = Cursors.SizeAll;
}
// start point location
this.startDraggingPoint = e.Location;
}
private void piece_MouseMove(object sender, MouseEventArgs e)
{
if (draggedPiece != null)
{
if (resizing)
{
// erase rect
if (rectProposedSize.Width > 0 && rectProposedSize.Height > 0)
ControlPaint.DrawReversibleFrame(rectProposedSize, this.ForeColor, FrameStyle.Dashed);
// calculate rect new size
rectProposedSize.Width = e.X - this.startDraggingPoint.X + this.startSize.Width;
rectProposedSize.Height = e.Y - this.startDraggingPoint.Y + this.startSize.Height;
// draw rect
if (rectProposedSize.Width > 0 && rectProposedSize.Height > 0)
ControlPaint.DrawReversibleFrame(rectProposedSize, this.ForeColor, FrameStyle.Dashed);
}
else
{
Point pt;
if (draggedPiece == sender)
pt = new Point(e.X, e.Y);
else
pt = draggedPiece.PointToClient((sender as Control).PointToScreen(new Point(e.X, e.Y)));
draggedPiece.Left += pt.X - this.startDraggingPoint.X;
draggedPiece.Top += pt.Y - this.startDraggingPoint.Y;
}
}
}
private void piece_MouseUp(object sender, MouseEventArgs e)
{
if (resizing)
{
if (rectProposedSize.Width > 0 && rectProposedSize.Height > 0)
{
// erase rect
ControlPaint.DrawReversibleFrame(rectProposedSize, this.ForeColor, FrameStyle.Dashed);
}
// compare to min width and size ?
if (rectProposedSize.Width > 10 && rectProposedSize.Height > 10)
{
// set size
this.draggedPiece.Size = rectProposedSize.Size;
}
else
{
// you might want to set some minimal size here
this.draggedPiece.Size = new Size((int)Math.Max(10, rectProposedSize.Width), Math.Max(10, rectProposedSize.Height));
}
}
this.draggedPiece = null;
this.startDraggingPoint = Point.Empty;
this.Cursor = Cursors.Default;
}
}
}
bir nebze işimi görüyor. bu örneğe benzer tamamen 4 köşesinden boyutlandıracak ve 4 köşesinde nokta görünecek şekilde bir örnek olursa makbule geçer.
Teşekkürler.
buradaki örnekte sağ alt köşe çalışıyor ortasından yada sol üst taraftan boyutlandırma yapmıyor.
O zaman buradaki örneği deneyin,
4 köşeden de boyutlandırma yapabilir, taşıma ve kaydetme işlemlerini yapabilir bir örnek.
https://www.codeproject.com/Tips/709121/Move-and-Resize-Controls-on-a-Form-at-Runtime-With
