2011-10-11 22 views
10

मेरे पास एक विंडोज़ फॉर्म है जो सी # में लिखा गया है। जब कोई इसमें "स्पष्ट" बटन दबाता है तो मैं फॉर्म को फिर से लोड करना चाहता हूं। लेकिन मैं लोड इवेंट कॉल करने के लिए हासिल नहीं कर सका। ये लाइनें भी काम नहीं करतीं:बंद होने और फिर से खोलने के बिना विंडोज़ फॉर्म को फिर से लोड करना

this.Refresh(); 
    this.Load +=new EventHandler(Grafik_Load); // 'Grafik' is the name of the form. 

मुझे इसके बारे में क्या करना चाहिए? मदद के लिए धन्यवाद ..

+1

Application.Restart(); – Burimi

+0

को हल कर सकता है लेकिन यह एक झिलमिलाहट दिखाएगा (यह बंद हो रहा है और फॉर्म खोल रहा है) यही वह पोस्ट है जो पोस्ट से बचने के लिए कह रहा था। – Sandy

उत्तर

5

एक अलग फ़ंक्शन में 'लोड' कोड रखें और उस फ़ंक्शन को कॉल करें जो आपके कोड/लोड ईवेंट हैंडलर हैं।

+0

असल में मैं पहले से ही की तरह एक लोड समारोह है: निजी शून्य Grafik_Load (वस्तु प्रेषक, EventArgs ई) { .... } लेकिन मैं सही सिंटैक्स यह – user741319

+1

Grafik_Load कॉल करने के लिए नहीं मिला (शून्य, अशक्त) कार्य करना चाहिए। – CodingBarfield

0

मैंने पाया कि छुपा/शो, शो भाग एक ही रूप का एक और उदाहरण बनाता है, इसलिए मैं वर्तमान में बेहतर तरीके से निपटान करता हूं, इसका एक नया उदाहरण बनाता हूं, और इसे दिखाता हूं।

Grafik objFrmGrafik = new Grafik(); 
this.Dispose(); 
objFrmGrafik .Show(); 
0

होम एमडीआई-प्रपत्र नाम है। मैंने इसका परीक्षण किया है।

home.ActiveForm.Dispose(); 
      home sd = new home(); 
      sd.Show(); 
4
 private void callonload() 
     { 
      //code which u wrriten on load event 
     } 
     private void Form_Load(object sender, EventArgs e) 
     { 
      callonload(); 
     } 
     private void btn_clear_Click(object sender, EventArgs e) 
     { 
      callonload(); 
     } 
0
//it is a good idea to use the 'sender' object when calling the form load method 
//because doing so will let you determine if the sender was a button click or something else... 

private void button2_Click(object sender, EventArgs e) 
{ 
    //you may want to reset any global variables or any other 
    //housekeeping before calling the form load method 
    Form1_Load(sender, e); 
} 

private void Form1_Load(object sender, EventArgs e) 
{ 
    if (sender is Button) 
    { 
     //the message box will only show if the sender is a button 
     MessageBox.Show("You Clicked a button"); 
    } 
} 
+0

स्टैक ओवरव्लो में आपका स्वागत है। उनमें से केवल कोड के साथ उत्तर हटाने के लिए ध्वजांकित होते हैं क्योंकि वे "कम गुणवत्ता" हैं। सवालों के जवाब देने पर सहायता अनुभाग पढ़ें, फिर अपने उत्तर में कुछ टिप्पणी जोड़ने पर विचार करें। – Graham

संबंधित मुद्दे