У меня есть форма окна на C#, это выглядит как одинокая кнопка, даже без верхней панели "X". Я сделал это только кнопкой, и я хочу, чтобы, когда я касаюсь кнопки длинным касанием, я смогу переместить ее на свой экран.Как сделать вид окна для перемещения при длительном нажатии C#
Мне удалось это сделать, когда я касаюсь фона формы окон, я могу переместить его, но я хочу, чтобы это произошло, когда я касаюсь кнопки .
После просмотра в Интернете я сделал этот код, но я понятия не имею, что писать на moveApp() mehtod.
Это мой код:
namespace Print_My_Screen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void PrintScreen()
{
Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
string subPath = @"C:\PrintMyScreen";
bool exists = System.IO.Directory.Exists(subPath);
if (!exists)
System.IO.Directory.CreateDirectory(subPath);
printscreen.Save(@"C:\PrintMyScreen\printscreen.png", ImageFormat.Png);
printIt();
MessageBox.Show("Your screen has been printed successfully","",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
private void button1_Click(object sender, EventArgs e)
{
PrintScreen();
}
private void printIt()
{
PrintDocument pd = new PrintDocument();
// pd.PrintPage += PrintPage;
pd.PrintPage += (sender, args) =>
{
System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\PrintMyScreen\printscreen.png");
img.RotateFlip(RotateFlipType.Rotate90FlipXY);
args.Graphics.DrawImage(img, args.MarginBounds);
};
pd.Print();
}
private void PrintPage(object o, PrintPageEventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\PrintMyScreen\printscreen.png");
Point loc = new Point(100, 100);
e.Graphics.DrawImage(img, loc);
img.Dispose();
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x84:
base.WndProc(ref m);
if ((int)m.Result == 0x1)
m.Result = (IntPtr)0x2;
return;
}
base.WndProc(ref m);
}
private void moveApp()
{
}
public void Repeater(Button btn, int interval)
{
var timer = new Timer { Interval = interval };
timer.Tick += (sender, e) => moveApp();
btn.MouseDown += (sender, e) => timer.Start();
btn.MouseUp += (sender, e) => timer.Stop();
btn.Disposed += (sender, e) =>
{
timer.Stop();
timer.Dispose();
};
}
}
}