我有两个按钮都打开filedialog我想要的两个按钮应该总是打开他们相关的目录在filedialog当他们按下.在我的情况下filedialog保持最后打开目录,我不想要.
我正在尝试使用公钥编写代码来加密文本,并使用私钥和密码来解密.
我对编程语言不太熟悉,因为我不是编程学生.但对于我的迷你项目,我需要编写一些关于加密的程序.
对于以下代码,使用我的c驱动器中的文本文件来使用公钥进行编码.但我想使用openfiledialog来选择文件,而不是手动指向它(不是很实用)
真的很感激,如果有人可以帮我编辑代码.PS我真的不知道如何将openfiledialog应用于我的代码.当我使用youtubes和google的信息时,我不断收到错误.
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.Windows.Forms;
using System.IO;
using DidiSoft.Pgp;
namespace TEST2
{
public partial class Form1 : Form
{
PGPLib pgp = new PGPLib();
public Form1()
{
InitializeComponent();
}
private void encryptButton_Click(object sender, EventArgs e)
{
string testingstring = pgp.EncryptString(testTextBox.Text, new FileInfo(@"c:\TCkeyPublic.txt"));
encryptedtextTextBox.Text = testingstring;
}
private void decryptButton_Click(object sender, EventArgs e)
{
try
{
String plainString = pgp.DecryptString(encryptedtextTextBox.Text,
new FileInfo(@"c:\TCkeyPrivate.txt"), passphraseTextBox.Text);
decryptedtextTextBox.Text …Run Code Online (Sandbox Code Playgroud) 我不确定如何使用我创建的字典,当我点击一个按钮,这意味着我无法从另一个功能中引用它.这可能是非常基本的,但我根本不记得这是怎么做的.
这是打开文件对话框的按钮,然后读取文件中的每一行,并将内容存储在字典中:
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Mod Pack Configuration file|*.mcf";
openFileDialog1.Title = "Load Mod Pack Configuration File";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
Dictionary<string, string> loadfile =
File.ReadLines(openFileDialog1.FileName)
.Select(line => line.Split(';'))
.ToDictionary(parts => parts[0], parts => parts[1]);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我加载一个函数,将加载的文件,字符串放在表单内的不同控件中.但是下面的代码不起作用,因为找不到"loaddfile":
public void getDefaultSettings()
{
if (Properties.Settings.Default.modsDestDropDown != "")
{
modsDestDropDown.SelectedIndex = Convert.ToInt32(loadfile['modsDestDropDown']);
}
}
Run Code Online (Sandbox Code Playgroud)
我当然可以在button1 click事件中编写函数,但是因为我在其他地方的程序中使用了这个函数,所以稍后会给我一些麻烦
我正在使用openFileDialog和showFileDialog图标创建一个窗体.但是当我运行表单时,我看不到左上角的选项.是否有一些我需要更改为可见的属性?任何帮助将不胜感激.