Local
Python ile çalışma videosu
2mb'tan büyük olduğundan DM'yeyükledim
https://dai.ly/x8yskp6
Deneme imkanım olmadığını belirterek bir örnek veriyorum.
C# ile bu işlevselliği sağlamak için iki form oluşturacağız: Form1 ve Form2. Form1'de bir buton ve bir TextBox olacak; butona tıklandığında Form2 açılacak. Form2'de bir ListView olacak ve ListView'deki ürünlerden birine çift tıklayınca bu ürün Form1'deki TextBox'a aktarılacak ve Form2 kapanacak.
Aşağıda bu işlevselliği sağlayan örnek kodlar bulunmaktadır:
Form1.cs:
using System;
using System.Windows.Forms;
namespace WindowsFormsApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.ItemSelected += Form2_ItemSelected;
form2.Show();
}
private void Form2_ItemSelected(object sender, string item)
{
textBox1.Text = item;
}
}
}
Form1.Designer.cs:
namespace WindowsFormsApp
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
// button1
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Open Form2";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
// textBox1
this.textBox1.Location = new System.Drawing.Point(12, 41);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(260, 20);
this.textBox1.TabIndex = 1;
// Form1
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 81);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
}
}
Form2.cs:
using System;
using System.Windows.Forms;
namespace WindowsFormsApp
{
public partial class Form2 : Form
{
public event EventHandler<string> ItemSelected;
public Form2()
{
InitializeComponent();
LoadItems();
}
private void LoadItems()
{
string[] items = { "Item1", "Item2", "Item3" };
foreach (var item in items)
{
listView1.Items.Add(item);
}
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
string selectedItem = listView1.SelectedItems[0].Text;
ItemSelected?.Invoke(this, selectedItem);
this.Close();
}
}
}
}
Form2.Designer.cs:
namespace WindowsFormsApp
{
partial class Form2
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.ListView listView1;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
// listView1
this.listView1.Location = new System.Drawing.Point(12, 12);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(260, 237);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.List;
this.listView1.DoubleClick += new System.EventHandler(this.listView1_DoubleClick);
// Form2
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.listView1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
}
}