How do I make an IDE panel in Visual Studio with C#, where it copies my movement like Power Automate, I created a code here it is repeating my movement so I want it to copy information like a copy and paste, I wanted to include it in my code But it keeps giving error c3, please help me!?
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace AutomationDesktop
{
public partial class Form1 : Form
{
List<Commands> commands = new List<Commands>();
private bool start_mapeamento = false;
public int stepe = 1;
public Form1()
{
InitializeComponent();
}
private void bt_mapear_Click(object sender, EventArgs e)
{
start_mapeamento = true;
bt_mapear.Visible = false;
bt_parar.Visible = true;
new Thread(new ThreadStart(Mapear)).Start();
}
private void Mapear()
{
while (start_mapeamento)
{
int x = MousePosition.X;
int y = MousePosition.Y;
this.Invoke((MethodInvoker)delegate
{
this.lbl_x.Text = "X:" + x.ToString();
this.lbl_y.Text = "Y:" + y.ToString();
});
}
}
private void Form1_Deactivate(object sender, EventArgs e)
{
if (start_mapeamento)
{
new Thread(new ThreadStart(CallFormAgain)).Start();
commands.Add(new Commands { Type = "Click", Value = MousePosition });
lv_itens.Items.Add(new ListViewItem(new String[] { stepe.ToString(), "Click", $"{MousePosition.X},{MousePosition.Y}" }));
stepe++;
}
}
private void CallFormAgain()
{
this.Invoke((MethodInvoker)delegate
{
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
else
{
WindowState = FormWindowState.Normal;
TopMost = true;
BringToFront();
}
Activate();
});
}
private void bt_parar_Click(object sender, EventArgs e)
{
start_mapeamento = false;
bt_mapear.Visible = true;
bt_parar.Visible = false;
}
private void bt_add_texto_Click(object sender, EventArgs e)
{
if (start_mapeamento)
{
start_mapeamento = false;
}
string promptValue = ShowDialog("Informa um valor", "RPA");
if (!string.IsNullOrEmpty(promptValue))
{
commands.Add(new Commands { Type = "Text", Value = promptValue });
lv_itens.Items.Add(new ListViewItem(new String[] { stepe.ToString(), "Text", promptValue }));
stepe++;
}
}
public static string ShowDialog(string text, string caption)
{
Form prompt = new Form()
{
Width = 500,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = caption,
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Left = 50, Top = 20, Text = text };
TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textBox);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
private void bt_start_Click(object sender, EventArgs e)
{
new Thread(new ThreadStart(StartProccess)).Start();
}
private const int MOUSEEVENTF_LEFTDOWN = 0x0002;
private const int MOUSEEVENTF_LEFTUP = 0x0004;
[DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
private void StartProccess()
{
foreach (var command in commands)
{
if (command.Type == "Click")
{
this.Invoke((MethodInvoker)delegate
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Thread.Sleep(1000);
Cursor.Position = command.Value;
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Thread.Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
});
}
else
{
SendKeys.SendWait(command.Value);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (lv_itens.SelectedItems.Count > 0)
{
string selectedText = lv_itens.SelectedItems[0].SubItems[2].Text;
Clipboard.SetText(selectedText);
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Código adicional de inicialização, se necessário.
}
#region Windows Form Designer generated code
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
bt_mapear = new Button();
bt_parar = new Button();
bt_add_texto = new Button();
bt_start = new Button();
lbl_x = new Label();
lbl_y = new Label();
lv_itens = new ListView();
step = new ColumnHeader();
Tipoe = new ColumnHeader();
value = new ColumnHeader();
button1 = new Button();
SuspendLayout();
//
// bt_mapear
//
bt_mapear.Location = new Point(195, 33);
bt_mapear.Margin = new Padding(3, 4, 3, 4);
bt_mapear.Name = "bt_mapear";
bt_mapear.Size = new Size(86, 31);
bt_mapear.TabIndex = 0;
bt_mapear.Text = "MAPEAR";
bt_mapear.UseVisualStyleBackColor = true;
bt_mapear.Click += new EventHandler(bt_mapear_Click);
//
// bt_parar
//
bt_parar.Location = new Point(299, 31);
bt_parar.Margin = new Padding(3, 4, 3, 4);
bt_parar.Name = "bt_parar";
bt_parar.Size = new Size(86, 31);
bt_parar.TabIndex = 1;
bt_parar.Text = "PARAR";
bt_parar.UseVisualStyleBackColor = true;
bt_parar.Visible = false;
bt_parar.Click += new EventHandler(bt_parar_Click);
//
// bt_add_texto
//
bt_add_texto.Location = new Point(195, 85);
bt_add_texto.Margin = new Padding(3, 4, 3, 4);
bt_add_texto.Name = "bt_add_texto";
bt_add_texto.Size = new Size(190, 31);
bt_add_texto.TabIndex = 2;
bt_add_texto.Text = "ADICIONAR TEXTO";
bt_add_texto.UseVisualStyleBackColor = true;
bt_add_texto.Click += new EventHandler(bt_add_texto_Click);
//
// bt_start
//
bt_start.Location = new Point(195, 139);
bt_start.Margin = new Padding(3, 4, 3, 4);
bt_start.Name = "bt_start";
bt_start.Size = new Size(190, 31);
bt_start.TabIndex = 3;
bt_start.Text = "START";
bt_start.UseVisualStyleBackColor = true;
bt_start.Click += new EventHandler(bt_start_Click);
//
// lbl_x
//
lbl_x.AutoSize = true;
lbl_x.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
lbl_x.Location = new Point(29, 31);
lbl_x.Name = "lbl_x";
lbl_x.Size = new Size(28, 28);
lbl_x.TabIndex = 4;
lbl_x.Text = "X:";
//
// lbl_y
//
lbl_y.AutoSize = true;
lbl_y.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
lbl_y.Location = new Point(29, 88);
lbl_y.Name = "lbl_y";
lbl_y.Size = new Size(27, 28);
lbl_y.TabIndex = 5;
lbl_y.Text = "Y:";
//
// lv_itens
//
lv_itens.Columns.AddRange(new ColumnHeader[] { step, Tipoe, value });
lv_itens.Location = new Point(0, 193);
lv_itens.Margin = new Padding(3, 4, 3, 4);
lv_itens.Name = "lv_itens";
lv_itens.Size = new Size(438, 283);
lv_itens.TabIndex = 6;
lv_itens.UseCompatibleStateImageBehavior = false;
lv_itens.View = View.Details;
//
// step
//
step.Text = "Etapa";
//
// Tipoe
//
Tipoe.Text = "Tipo";
Tipoe.Width = 120;
//
// value
//
value.Text = "Valor";
value.Width = 100;
//
// button1
//
button1.Location = new Point(391, 87);
button1.Name = "button1";
button1.Size = new Size(164, 29);
button1.TabIndex = 7;
button1.Text = "copiar texto";
button1.UseVisualStyleBackColor = true;
button1.Click += new EventHandler(button1_Click);
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(567, 475);
Controls.Add(button1);
Controls.Add(lv_itens);
Controls.Add(lbl_y);
Controls.Add(lbl_x);
Controls.Add(bt_start);
Controls.Add(bt_add_texto);
Controls.Add(bt_parar);
Controls.Add(bt_mapear);
KeyPreview = true;
Margin = new Padding(3, 4, 3, 4);
Name = "Form1";
Text = "Painel - IDE";
Deactivate += new EventHandler(Form1_Deactivate);
Load += new EventHandler(Form1_Load);
KeyDown += new KeyEventHandler(Form1_KeyDown);
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button bt_mapear;
private Button bt_parar;
private Button bt_add_texto;
private Button bt_start;
private Label lbl_x;
private Label lbl_y;
private ListView lv_itens;
private ColumnHeader step;
private ColumnHeader Tipoe;
private ColumnHeader value;
private Button button1;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back)
{
// Ação a ser executada quando a tecla Backspace for pressionada
MessageBox.Show("Backspace pressionado!");
e.Handled = true;
}
}
}
public class Commands
{
public string Type { get; set; }
public dynamic Value { get; set; }
}
}
............................................ separating the line of code, the top one would be Form1.Designer.cs and the bottom one would be Form1.cs.......................................
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace AutomationDesktop
{
public partial class Form1 : Form
{
List<Commands> commands = new List<Commands>();
private bool start_mapeamento = false;
public int stepe = 1;
public Form1()
{
InitializeComponent();
}
private void bt_mapear_Click(object sender, EventArgs e)
{
start_mapeamento = true;
bt_mapear.Visible = false;
bt_parar.Visible = true;
new Thread(new ThreadStart(Mapear)).Start();
}
private void Mapear()
{
while (start_mapeamento)
{
int x = MousePosition.X;
int y = MousePosition.Y;
this.Invoke((MethodInvoker)delegate
{
this.lbl_x.Text = "X:" + x.ToString();
this.lbl_y.Text = "Y:" + y.ToString();
});
}
}
private void Form1_Deactivate(object sender, EventArgs e)
{
if (start_mapeamento)
{
new Thread(new ThreadStart(CallFormAgain)).Start();
commands.Add(new Commands { Type = "Click", Value = MousePosition });
lv_itens.Items.Add(new ListViewItem(new String[] { stepe.ToString(), "Click", $"{MousePosition.X},{MousePosition.Y}" }));
stepe++;
}
}
private void CallFormAgain()
{
this.Invoke((MethodInvoker)delegate
{
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
else
{
WindowState = FormWindowState.Normal;
TopMost = true;
BringToFront();
}
Activate();
});
}
private void bt_parar_Click(object sender, EventArgs e)
{
start_mapeamento = false;
bt_mapear.Visible = true;
bt_parar.Visible = false;
}
private void bt_add_texto_Click(object sender, EventArgs e)
{
if (start_mapeamento)
{
start_mapeamento = false;
}
string promptValue = ShowDialog("Informa um valor", "RPA");
if (!string.IsNullOrEmpty(promptValue))
{
commands.Add(new Commands { Type = "Text", Value = promptValue });
lv_itens.Items.Add(new ListViewItem(new String[] { stepe.ToString(), "Text", promptValue }));
stepe++;
}
}
public static string ShowDialog(string text, string caption)
{
Form prompt = new Form()
{
Width = 500,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = caption,
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Left = 50, Top = 20, Text = text };
TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textBox);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
private void bt_start_Click(object sender, EventArgs e)
{
new Thread(new ThreadStart(StartProccess)).Start();
}
private const int MOUSEEVENTF_LEFTDOWN = 0x0002;
private const int MOUSEEVENTF_LEFTUP = 0x0004;
[DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
private void StartProccess()
{
foreach (var command in commands)
{
if (command.Type == "Click")
{
this.Invoke((MethodInvoker)delegate
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Thread.Sleep(1000);
Cursor.Position = command.Value;
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Thread.Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
});
}
else
{
SendKeys.SendWait(command.Value);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (lv_itens.SelectedItems.Count > 0)
{
string selectedText = lv_itens.SelectedItems[0].SubItems[2].Text;
Clipboard.SetText(selectedText);
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Código adicional de inicialização, se necessário.
}
#region Windows Form Designer generated code
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
bt_mapear = new Button();
bt_parar = new Button();
bt_add_texto = new Button();
bt_start = new Button();
lbl_x = new Label();
lbl_y = new Label();
lv_itens = new ListView();
step = new ColumnHeader();
Tipoe = new ColumnHeader();
value = new ColumnHeader();
button1 = new Button();
SuspendLayout();
//
// bt_mapear
//
bt_mapear.Location = new Point(195, 33);
bt_mapear.Margin = new Padding(3, 4, 3, 4);
bt_mapear.Name = "bt_mapear";
bt_mapear.Size = new Size(86, 31);
bt_mapear.TabIndex = 0;
bt_mapear.Text = "MAPEAR";
bt_mapear.UseVisualStyleBackColor = true;
bt_mapear.Click += new EventHandler(bt_mapear_Click);
//
// bt_parar
//
bt_parar.Location = new Point(299, 31);
bt_parar.Margin = new Padding(3, 4, 3, 4);
bt_parar.Name = "bt_parar";
bt_parar.Size = new Size(86, 31);
bt_parar.TabIndex = 1;
bt_parar.Text = "PARAR";
bt_parar.UseVisualStyleBackColor = true;
bt_parar.Visible = false;
bt_parar.Click += new EventHandler(bt_parar_Click);
//
// bt_add_texto
//
bt_add_texto.Location = new Point(195, 85);
bt_add_texto.Margin = new Padding(3, 4, 3, 4);
bt_add_texto.Name = "bt_add_texto";
bt_add_texto.Size = new Size(190, 31);
bt_add_texto.TabIndex = 2;
bt_add_texto.Text = "ADICIONAR TEXTO";
bt_add_texto.UseVisualStyleBackColor = true;
bt_add_texto.Click += new EventHandler(bt_add_texto_Click);
//
// bt_start
//
bt_start.Location = new Point(195, 139);
bt_start.Margin = new Padding(3, 4, 3, 4);
bt_start.Name = "bt_start";
bt_start.Size = new Size(190, 31);
bt_start.TabIndex = 3;
bt_start.Text = "START";
bt_start.UseVisualStyleBackColor = true;
bt_start.Click += new EventHandler(bt_start_Click);
//
// lbl_x
//
lbl_x.AutoSize = true;
lbl_x.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
lbl_x.Location = new Point(29, 31);
lbl_x.Name = "lbl_x";
lbl_x.Size = new Size(28, 28);
lbl_x.TabIndex = 4;
lbl_x.Text = "X:";
//
// lbl_y
//
lbl_y.AutoSize = true;
lbl_y.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
lbl_y.Location = new Point(29, 88);
lbl_y.Name = "lbl_y";
lbl_y.Size = new Size(27, 28);
lbl_y.TabIndex = 5;
lbl_y.Text = "Y:";
//
// lv_itens
//
lv_itens.Columns.AddRange(new ColumnHeader[] { step, Tipoe, value });
lv_itens.Location = new Point(0, 193);
lv_itens.Margin = new Padding(3, 4, 3, 4);
lv_itens.Name = "lv_itens";
lv_itens.Size = new Size(438, 283);
lv_itens.TabIndex = 6;
lv_itens.UseCompatibleStateImageBehavior = false;
lv_itens.View = View.Details;
//
// step
//
step.Text = "Etapa";
//
// Tipoe
//
Tipoe.Text = "Tipo";
Tipoe.Width = 120;
//
// value
//
value.Text = "Valor";
value.Width = 100;
//
// button1
//
button1.Location = new Point(391, 87);
button1.Name = "button1";
button1.Size = new Size(164, 29);
button1.TabIndex = 7;
button1.Text = "copiar texto";
button1.UseVisualStyleBackColor = true;
button1.Click += new EventHandler(button1_Click);
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(567, 475);
Controls.Add(button1);
Controls.Add(lv_itens);
Controls.Add(lbl_y);
Controls.Add(lbl_x);
Controls.Add(bt_start);
Controls.Add(bt_add_texto);
Controls.Add(bt_parar);
Controls.Add(bt_mapear);
KeyPreview = true;
Margin = new Padding(3, 4, 3, 4);
Name = "Form1";
Text = "Painel - IDE";
Deactivate += new EventHandler(Form1_Deactivate);
Load += new EventHandler(Form1_Load);
KeyDown += new KeyEventHandler(Form1_KeyDown);
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button bt_mapear;
private Button bt_parar;
private Button bt_add_texto;
private Button bt_start;
private Label lbl_x;
private Label lbl_y;
private ListView lv_itens;
private ColumnHeader step;
private ColumnHeader Tipoe;
private ColumnHeader value;
private Button button1;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back)
{
// Ação a ser executada quando a tecla Backspace for pressionada
MessageBox.Show("Backspace pressionado!");
e.Handled = true;
}
}
}
public class Commands
{
public string Type { get; set; }
public dynamic Value { get; set; }
}
}
help me!! I’m going crazy trying to insert this copy and paste button
help me!! I’m going crazy trying to insert this copy and paste button
user25067902 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.