نقل قول: قطعه کد برای بردر استایل (مهم)
نحوه جابجايي فرم با استفاده از
API
ابتدا Namespace زير رو به برنامه اضافه کنيد
using System.Runtime.InteropServices;
سپس کد زير رو به ابتداي برنامه اضافه کنيد
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
حالا کد زير را در رويداد MouseDown هر شي که خواستيد اضافه کنيد
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(this.Handle, 0xa1, 0x2, 0);
}
..............................
جابه جا کردن فرم با کليک بر روي هر قسمت آن با توابع
API
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern int ReleaseCapture();
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
static extern int SendMessage(int hwnd, int wMsg, int wParam, object lParam);
private const int WM_NCLBUTTONDOWN = 161;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(), WM_NCLBUTTONDOWN, 2, 0);
}
.................................
جابه جا کردن فرم با کليک بر روي هر قسمت آن
private bool dragging;
private Point pointClicked;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Turn drag mode on and store the point clicked.
dragging = true;
pointClicked = new Point(e.X, e.Y);
}
else
{
dragging = false;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
Point pointMoveTo;
// Find the current mouse position in screen coordinates.
pointMoveTo = this.PointToScreen(new Point(e.X, e.Y));
// Compensate for the position the control was clicked.
pointMoveTo.Offset(-pointClicked.X, -pointClicked.Y);
// Move the form.
this.Location = pointMoveTo;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
dragging = false;
}
.....................................
نقل قول: قطعه کد برای بردر استایل (مهم)
داداش خیلی ببخشیدا ولی من هنگ کردم میشه واضع تر بگی من فقط میخام وقتی با موس اون پنل بالا رو تکون میدم کلا برنامه هم با این کار جا به جا بتونم بکنم همین.
یا بهم واضع تر بگو لطفا یا به یه برنامه خودت تستی بساز بدش بهم.واقعا ممنونت میشم.
نقل قول: قطعه کد برای بردر استایل (مهم)
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern int ReleaseCapture();
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
static extern int SendMessage(int hwnd, int wMsg, int wParam, object lParam);
private const int WM_NCLBUTTONDOWN = 161;
public Form1()
{
InitializeComponent();
}
private void Panel1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(), WM_NCLBUTTONDOWN, 2, 0);
}
}
}
یا
یکی از قابلیت های ساده اما بسیار کاربردی که راحتی کار با برنامه شما را برای کاربر بیشتر می کند ، انتفال فرم با ماوس با کلیک کردن روی هر نقطه ای از آن است .
با استفاده از کد زیر که از توابع API در آن استفاده شده است ، می توانید به آسانی این کار را انجام دهید .
ابتدا فضای نام زیر را در برنامه وارد کنید
using System.Runtime.InteropServices;
سپس از کد زیر در رویداد MouseDown فرم استفاده کنید :
[DllImport("user32.dll")]
static extern int ReleaseCapture();
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
static extern int SendMessage(int hwnd, int wMsg, int wParam, object lParam);
private const int WM_NCLBUTTONDOWN = 161;
private void Panel1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(), WM_NCLBUTTONDOWN, 2, 0);
}
منبع : w3-farsi.com
نقل قول: قطعه کد برای بردر استایل (مهم)
داداش کد دئمی خوب دادی ولی من میخام وقتی روی panel1 کلیک کردن و اونو darg کرد بتونه جا به جا کنه فقط اون قسمتو بتونه
نقل قول: قطعه کد برای بردر استایل (مهم)
نقل قول:
نوشته شده توسط
amir000555
داداش کد دئمی خوب دادی ولی من میخام وقتی روی panel1 کلیک کردن و اونو darg کرد بتونه جا به جا کنه فقط اون قسمتو بتونه
کد رو اصلاح کردم، اگر panel رو Dock کردین، تو رویداد mouseDown پنل بنویسین درست میشه
نقل قول: قطعه کد برای بردر استایل (مهم)
یه اصلاح کنید دوباره ارور می ده کاراکتر های { این ارور میده
نقل قول: قطعه کد برای بردر استایل (مهم)
حق با شماست کد زیر اصلا مشکل نداره
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;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[System.Runtime.InteropServices.DllImportAttribute( "user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImportAttribute( "user32.dll")]
public static extern bool ReleaseCapture();
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
}
نقل قول: قطعه کد برای بردر استایل (مهم)
این را باید کجا قرار بدم؟
نقل قول: قطعه کد برای بردر استایل (مهم)
ببینید من این کد زیر را وارد کردم
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace New_Browser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
}
ولی ارور میده میشه روی همین بگین
1 ضمیمه
نقل قول: قطعه کد برای بردر استایل (مهم)
نقل قول:
نوشته شده توسط
amir000555
این را باید کجا قرار بدم؟
یه کم به کد بالا دقت کنید متوجه میشین
ضمیمه 143952
نقل قول: قطعه کد برای بردر استایل (مهم)
مرسی داداش درستش کردم واقعا کمکم کردی خیلی کمک بزرگی بود.راستی میخوام بهم یاد بدی سی شارپ آخه سال بعد این را باید بلد باشیم ولی من بلد نیستم می تونی بهم یا دبدی؟