2015-09-29 53 views
-5

我使用C#.NET的Microsoft Visual Vtudio .NET Framework版本4.5.2C#.NET錯誤

我真的不想讓這個問題,但我有這樣的代碼,我現在在做什麼什麼將編輯txt文件,然後將編輯後的txt文件寫入磁盤並使用cmd和命令「certutil」來加密它。 然後它會在文本文件中的加密行的前端和末尾添加@echo(加密文本代碼編輯的內容)>> C:\ users \%username%\ appdata \ file.txt。 也許我可以直接編輯資源文件?但是,然後命令「certutil」無法訪問該文件,因爲它在.exe中。我想我需要將文件寫入磁盤,然後執行「certutil」,然後將文件讀回資源?

我想爲此製作生成器,所以我/別人不需要每次都編輯它,然後使用crypt,然後編輯蝙蝠,當它將加密的文本回顯到appdata並運行它時。

我遇到了一些問題,因爲我在一週前開始學習c。然後我發現你不能有c的GUI,然後開始使用visual studio來製作東西。

這是錯誤:

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

namespace WindowsFormsApplication5 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      if (radioButton2.Checked) 
      { 
       string text = Properties.Resources.bindyes; 
      } 
      else if(radioButton1.Checked) 
      { 
       string text = Properties.Resources.bindno; 
      } 
      bool downurl = textBox1; 
      var downexe = textBox2; 
      var bindurl = textBox4; 
      var bindexe = textBox3; 
      File.WriteAllText("C:\\Users\\Karl\\Desktop\\downloader.bat",); 
     } 
    } 
} 

我想從代碼

if (radioButton2.Checked) 
{ 
    string text = Properties.Resources.bindyes; 
    return text; 
} 
else if(radioButton1.Checked) 
    string text = Properties.Resources.bindno; 
return text; 
{ 

返回此值,但我得到這個錯誤:

Error Since 'Form1.button1_Click(object, EventArgs)' returns void, a return keyword must not be followed by an object expression .

我真的不想要問這個問題,但我現在已經在這個1天半的時間裏掙扎了。

有沒有解決這個問題?

所以金正日嘗試從平板電腦

我要讓建設者什麼都會寫在文件中適當的地方插入用戶信息的文件,然後使用CMD隱窩文件讓它有點clearer.writing。然後在每行「@echo」的前面加上這個,並在我想寫的每一行的末尾添加「>> c:users \%username%\ appdata \ file.txt

和其他部分類似的代碼

CERTUTIL decodehex(或解碼)C:\文件路徑\文件(解碼文件路徑)

所以我想如果做這樣statemnt如果radiobox1.checked它會爲文本字符串設定爲 如果(radiobox1.Checked) { String text = Properties.Resources.nobind Else String text = Properties.resources.yesbind 返回文本; } 我是從頭寫的

然後我想將資源寫入到c:\ filepath。 但我不能返回:\

我希望解釋坑更好一點

+4

這真的不清楚這段代碼在做什麼(沒有縮進不起作用),但錯誤非常明顯。如果一個方法有一個'void'返回類型,那麼你不能從該方法返回任何東西。 – David

+1

好的。將這些字符串返回到 –

+0

[如果一棵樹落在森林裏,沒有人會聽到它,它會發出聲音](https://en.wikipedia.org/wiki/If_a_tree_falls_in_a_forest)...爲什麼你會想要從點擊處理程序返回值 - 沒有代碼期待結果...一些澄清和格式化將使您的帖子更好(並給予某人回答的機會)。 –

回答

-4

我不知道C#,但我認爲你需要改變private void button1_Click(object sender, EventArgs e)private string button1_Click(object sender, EventArgs e)。由於'虛空'的意思是你沒有返回任何東西。希望這有助於。

+0

您不能擅自更改方法簽名而不破壞其他代碼。除了方法的名稱和參數的名稱之外,這是你根本無法改變的之一,必須保留返回類型和參數類型/順序。 –

+1

如果你不確定你的回答是否正確,請發表評論 –

+0

好的,所以他們是預先定義的方法。對不起,我不知道C#。如果程序是用於應用程序開發的,那麼他可以將結果顯示在消息框或文本框中? – Mutex202

0

如果您要求如何將變量text寫入文件,那麼您所需要做的就是將該變量的聲明移至if-else之外。在{中聲明變量.. }塊意味着它不存在於外部。

string text; // declare it here 
if (radioButton2.Checked) 
{ 
    text = Properties.Resources.bindyes; 
} 
else if (radioButton1.Checked) 
{ 
    text = Properties.Resources.bindno; 
} 

File.WriteAllText("C:\\Users\\Karl\\Desktop\\downloader.bat", text);