2017-10-08 37 views
0

我正在爲此工作一些日子。現在我有另一個問題。所以,我有這在我的zzz.cs顯示新表格不起作用

private void button3_Click_1(object sender, EventArgs e) 
{ 
    scraper zzz = new scraper(); 
    zzz.Show(); 
} 

對於1個原因,不想要打開叫做scraper.cs其他窗口的形式。我的zzz.csscraper.cs具有相同的命名空間。這怎麼能工作?什麼是修復?

編輯:

的問題已得到修復,但現在從login.cs它並不去zzz.cs.我的代碼是:

MessageBox.Show("You are logged in successfully"); 
    zzz zzz = new zzz(); 
    zzz.Show(); 
    this.Close(); 

但現在不起作用。如何解決這個問題?之前它的工作,現在不再...

我再次嘗試。我看到zzz.cs打開。然後用照片直接代碼將關閉:0。這裏是我的zzz.cs再次:

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

namespace Login 
{ 
    public partial class zzz : Form 
    { 
     public static List<string> proxies { get; set; } = new List<string>(); 
     public static List<string> Links { get; set; } = new List<string>(); 
     public static string path; 
     public zzz() 
     { 
      InitializeComponent(); 
     } 
     private void button1_Click_1(object sender, EventArgs e) 
     { 
      Logs.Items.Clear(); 
      if (radioButton1.Checked == true) 
      { 
       bool useproxies = true; 
       Logs.Items.Add("Using proxies enabled!"); 
       scrape(); 
      } 
      else 
      { 
       bool useproxies = false; 
       Logs.Items.Add("Using proxies disabled!"); 
      } 
      void scrape() 
      { 
       int omg = proxyscraper(); 
      } 
     } 

     private void groupBox1_Enter(object sender, EventArgs e) 
     { 

     } 

     public int proxyscraper() 
     { 
      return 0; 
     } 

     private void button3_Click_1(object sender, EventArgs e) 
     { 
      //Form1 aaa = new Form1(); 
      //aaa.Show(); 
     } 
    } 
} 

這裏是我的inlogin.cs:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.IO; 
using System.Linq; 
using System.Net; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace Login 
{ 
    public partial class MainForm : Form 
    { 
     public MainForm() 
     { 
      InitializeComponent(); 

     } 
     //Enter code here for your version of username and userpassword 
     Login login = new Login("admin", "1234"); 


     private void button1_Click(object sender, EventArgs e) 
     { 
      //define local variables from the user inputs 
      string user = nametxtbox.Text; 
      string pass = pwdtxtbox.Text; 
      //check if eligible to be logged in 

      string login(string lol,string lel) 
      { 
       try 
       { 
        var request = (HttpWebRequest)WebRequest.Create("http://SNIP/mama.php?user=" + lol + "&password=" + lel); 
        var response = (HttpWebResponse)request.GetResponse(); 
        string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); 
        return responseString; 
       } 
       catch 
       { 
        string responseString = "NO"; 
        return responseString; 
       } 
      } 
      string wat = "YES"; 
      if (login(user, pass) == wat) 
      { 
       MessageBox.Show("You are logged in successfully"); 
       zzz aaa = new zzz(); 
       aaa.Show(); 
       this.Close(); 
      } 
      else 
      { 
       //show default login error message 
       MessageBox.Show("Login Error!"); 
      } 
     } 

     private void label2_Click(object sender, EventArgs e) 
     { 

     } 

     private void label1_Click(object sender, EventArgs e) 
     { 

     } 
    } 
} 

Howwww ....

+0

1.什麼是'scraper'的定義。 2. WinForms? – Richard

+0

您是否嘗試過通過在Click-Method中設置斷點來調試它?你有沒有發現這個事件?你能爲我們提供你們班的代碼嗎? –

+0

請閱讀[清單](https://meta.stackoverflow.com/questions/260648)並將其應用於您的問題[編輯]。相關:[mcve] – rene

回答

1

你有沒有試圖編譯你的代碼?它不應該。

原因之一是你在混合文件名itselve和類名。這是不同的名字。

你必須創建你的類的一個實例。在這種情況下你的表單通過使用它的構造函數。

private void button3_Click_1(object sender, EventArgs e) 
{ 
    Form1 aaa = new Form1() 
    aaa.Show(); 
} 

也可以重命名你的類Form1Scrapper,並呼籲

private void button3_Click_1(object sender, EventArgs e) 
{ 
    Scrapper aaa = new Scrapper() 
    aaa.Show(); 
} 

回答您的編輯

您正在使用zzz.Show()剛剛打開的非模態對話框zzz和 在th內執行下一個方法點擊方法。這是this.Close();。這將關閉您當前的登錄表單,這也會關閉您的zzz。您可以使用zzz.ShowDialog();開啓zzz。現在登錄對話框是'等待',直到你的sxrapper對話框關閉。之後,登錄屏幕通過致電this.Close();自行關閉。

我建議你改變你的應用程序流程。 首先打開你的登錄界面,在關閉成功之後再打開你的刮刀。如果您button3_Click_1

檢查:

舉個例子,你可以在你的ProgramProgram.cs文件中改變你的Main方法:

static void Main() 
{ 
    Application.EnableVisualStyles(); 
    Application.SetCompatibleTextRenderingDefault(false); 

    var loginForm = new YourLoginDialog(); 
    var result = YourLoginDialog.ShowDialog(); 
    if (result == DialogResult.Yes) 
    { 
     Application.Run(new Scrapper()); 
    } 
    else 
    { 
     MessageBox.Show("Login failed"); 
    } 
} 

在這種情況下它仍然沒有工作連接到您的button3。 有很多方法可以做到這一點,但常用的方法是使用VisualStudio屬性窗口F4選擇您的button3並選擇bolt /事件選項卡並選擇您的button3_Click_1方法用於點擊事件。
InitializeComponent();

this.button3.Click += new System.EventHandler(this.button3_Click_1); 

呼叫從上述評論回答你的問題後,加入這個下面一行到你的構造:

刮刀是Windows窗體IDK的如何查找出

您的ScrapperForm1)類繼承System.Windows.Forms.Form,因爲類定義中的: Form

public partial class Form1 : Form 
{ 
    // ... 
} 

也許你應該看看Classes and Structs (C# Programming Guide)

+0

啊謝謝!我再次編輯我的文章。因爲現在從inlog到zzz不起作用... –

+0

@Justanotheryoutuber:我只是想檢查你是否看到我的編輯,如果你需要進一步的幫助關於我提供的答案。 –