خیلی ممنون دوست گرامی .مشکلم حل شد. البته چیزی که من می خوایستم این بود که با یه راست کلیک یه پیکچرباکس نمایش داده بشه و مدام همراه موس حرکت کنه و با کلیک چپ پیکچرباکس رو نمایش نده.سورس کدش رو اینجا میذارم هرکی خواست استفاده کنه
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test1
{
class dragcontrol
{
public enum direction
{
any,
horizental,
vertical
}
public static void init(Control control, Control container, direction direction=direction.any)
{
bool dragging = false;
Point dragstart = Point.Empty;
{ control.MouseDown += delegate (object sender, MouseEventArgs e)
{
dragging = true;
dragstart = new Point(e.X, e.Y);
control.Capture = true;
};
}
control.MouseUp += delegate (object sender, MouseEventArgs e)
{
if(dragging)
{
dragging = false;
control.Capture = false;
}
};
control.MouseMove += delegate (object sender, MouseEventArgs e)
{
if (true)
{
if (direction != direction.vertical)
container.Left = Math.Max(0, e.X + container.Left - dragstart.X);
if (direction != direction.horizental)
container.Top = Math.Max(0, e.Y + container.Top - dragstart.Y);
}
};
}
}
}
///////////////////////////////////////
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.Data.SqlClient;
namespace test1
{
public partial class Form1 : Form
{
private bool mouseDown;
public Form1()
{
InitializeComponent();
test1.dragcontrol.init(this.tt,this.tt);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
mouseDown = true;
tt.Location = new Point(e.X, e.Y);
tt.Visible = true;
}
else
{
mouseDown = false;
tt.Visible = false;
}
}
private void tt_MouseClick(object sender, MouseEventArgs e)
{
tt.Visible = false;
}
private void Form1_MouseMove_1(object sender, MouseEventArgs e)
{
if (mouseDown)
{
tt.Location = e.Location;
}
}
private void tt_Click(object sender, EventArgs e)
{
tt.Visible = false;
}
private void Form1_Click(object sender, EventArgs e)
{
tt.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if(tt.Visible)
{
tt.BringToFront();
}
}
}
}
خیلی ممنون دوست عزیز بابت راهنمایی. مشکل حل شد.
البته اون چیزی که من میخواستم این بود که با یه راست کلیک یه پیکچرباکس نمایش داده بشه و مدام با حرکت موس حرکت کنه.سرس کدش رو هم گذاشتم برای هرکسی که لازمش شد