Arama butonu
Bu konudaki kullanıcılar: 1 misafir
1
Cevap
3555
Tıklama
0
Öne Çıkarma
c# baska class'tan objeye erisim ?
E
13 yıl
Teğmen
Konu Sahibi

merhaba arkadaslar, eskiden yazdigim delphi programlari simdi c# icin port ediyorum henuz c# ogrenme/ilerletme asamasindayim ve bazi programlarim binlerce satir simdilik sadece calissinlar istiyorum ilerde duzeltme yapicam.

formumda bir button bir de textbox var

asagidaki koddan da goreceginiz uzere yap(this); deyince calisiyor ve text kutusuna abc yaziyor... fakat ben yaz ile kullanmak istiyorum.

Biliyorum iyi bir kullanim metodu degil ve yaz metodunuda parametre vererek kullanabilirim ama dedigim gibi binlerce satir ve onlarca sinif port ediyorum su an icin bana sadece bu yontem lazim yani kisacasi her class icinden windows formuma ulasmak istiyorum.

cok tesekkurler


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace deneme
{
public partial class MainForm : Form
{



public class Toye{


public void yap(MainForm frm){
frm.textBox1.Text = "abc";

}

public void yaz(){
yap( ?? ); //veya
textBox1.Text = "abc";
}

}
public static Toye oye = new Toye();

public MainForm()
{
InitializeComponent();
}

void Button1Click(object sender, EventArgs e)
{
oye.yap(this);
oye.yaz();

}

}
}

DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.

Üye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.

Üye Ol Şimdi Değil





< Bu mesaj bu kişi tarafından değiştirildi elmek6 -- 31 Temmuz 2012; 8:51:24 >

E
13 yıl
Teğmen
Konu Sahibi

Inadim inat bi insanimdir sabah 11 da basladim denemeye ve gece 2 oldu buldum :)

public partial class MainForm : Form{
//bu satirin altina sunu ekliyorum

public static MainForm frm;

//ve

public MainForm()
{
frm = this;
Yep()

}


baska siniftan erismek icin bu da yapilir gayette guzel olur

public Yep(){
frm.textbox1.text = ":D";

}

ingilizce forumlarda da cok aradim buraya ingilizcesinide yazalimda google da bizim sitemizde ciksin :)
tags: label, textbox, class, ui, gui, access, class

I was thinking out, how can I access C# object (user interface like labels, textboxes) from another class in my project (like delphi or old visual basic style) After a lot of google search found nothing.
Than I wrote these lines. I know maybe it's not good to do that but I just want to access my all object in my whole class (or form).
If you want to do it, just add bold lines to your original codes and when you need to access the object such a textbox just type the name for example frm.textbox1.text in your class.
Don't forget the add first line to declare frm is MainForm (or form1 what ever you have)



DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.