Şimdi Ara

c# baska class'tan objeye erisim ?

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
1 Misafir - 1 Masaüstü
5 sn
3
Cevap
0
Favori
3.370
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • 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();

    }

    }
    }



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







  • 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)




  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.