Çözüldü C# formlar arası veri

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

ByWasco

Kilopat
Katılım
24 Ocak 2015
Mesajlar
236
Daha fazla  
Cinsiyet
Erkek
Form 2'nin botununu form 1'den kontrol etme, emir verme.
Böyle bir işlem yapmak istiyorum, nasıl yapabilirim acaba? Form 2'nin botununun modifiers özelliğini puclic yaptım.

1.png
2.png
 
Çözüm
@Nexor Aynen hocam.Çok yeniyim kavramakta zorlanıyorum da biraz.

Başlat butonunun ismi neyse button1 onunla değiştir.

C#:
var frm = Application.OpenForms.OfType<Form1>().Single();
if(frm != null)
{
    Button buton = (Button)frm.Controls.Find("button1", true).First();
    if(buton != null)
    {
        buton.PerformClick();
    }
}
Form 2'deki buttondan yeni public bir static Void'i çağır. Böylelikle form 1'den de o static Void'i çağırabilirsin.
 
Hocam yapamadım bir bakar mısınız?
@HaxinDog

[CODE title="Dosya İndirme Kodu"]using AltoHttp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Dosya_İndirme2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
HttpDownloader httpDownloader;
private void btnStart_Click(object sender, EventArgs e)
{
httpDownloader = new HttpDownloader(txtUrl.Text, $"{Application.StartupPath}\\{Path.GetFileName(txtUrl.Text)}");
httpDownloader.DownloadCompleted += HttpDownloader_DownloadCompleted;
httpDownloader.ProgressChanged += HttpDownloader_ProgressChanged;
httpDownloader.Start();
}

private void HttpDownloader_ProgressChanged(object sender, AltoHttp.ProgressChangedEventArgs e)
{
progressBar.Value = (int)e.Progress;
lblPercent.Text = $"{e.Progress.ToString("0.00")} %";
lblSpeed.Text = string.Format("{0} MB/s", (e.SpeedInBytes / 1024d / 1024d).ToString("0.00"));
lblDownloaded.Text = string.Format("{0} MB/s", (httpDownloader.TotalBytesReceived / 1024d / 1024d).ToString("0.00"));
blbStatus.Text = "İndiriliyor...";
}

private void HttpDownloader_DownloadCompleted(object sender, EventArgs e)

{
this.Invoke((MethodInvoker)delegate
{
blbStatus.Text = "İndirme Tamamlandı !";
lblPercent.Text = "100 %";
});

}

private void btnPause_Click(object sender, EventArgs e)
{
if (httpDownloader != null)
httpDownloader.Pause();
}

private void btnResume_Click(object sender, EventArgs e)
{
if (httpDownloader != null)
httpDownloader.Resume();
}

private void button1_Click(object sender, EventArgs e)
{
Form2 ff = new Form2();
ff.Show();
}
}
}
[/CODE]
 
@ByWasco Form1 açık olduğundan emin olun yoksa çalışmaz.

C#:
var frm = Application.OpenForms.OfType<Form1>().Single();
if(frm != null)
{
    frm.Text = "Form1 Başlığı Değişti!";
}
 
form2'deki bir düğmeye basmak (basılmış gibi olsun) istiyorsunuz. PerformClick() yöntemini kullanın.

C#:
//form2'yi, form1'de çağırın:
form2 frm2 = new form2();
frm2.btn.PerformClick();
 
Son düzenleme:

Yeni konular

Geri
Yukarı