本文介绍了其他私人方法中的按钮单击结果重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面使用此代码将文件转换为Base64.这段代码
Hi,
I use this code below for converting files into Base64. This piece of code
textBoxDescribeIncident.Text = FileToBase64String(openDlg.FileName);
将文件转换为Base64.我如何在另一个私有的void button_Click中使用此结果?
在此先感谢!
convert files into Base64. How can I use this outcome in an other private void button_Click ???
Thanks in advance!!
private void buttonBrowse_Click(object sender, EventArgs e) {
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "All Supported Files (All Files (*.*)|*.*";
if (openDlg.ShowDialog(this) == DialogResult.OK) {
Cursor = Cursors.WaitCursor;
textBoxAttachFile.Text = openDlg.FileName;
try {
textBoxDescribeIncident.Text = FileToBase64String(openDlg.FileName);
} catch (Exception) {
MessageBox.Show(this, string.Format("An error occurred whilst converting to base-64."),
Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Cursor = Cursors.Default;
}
}
private void buttonCreate_Click(object sender, EventArgs e) {
1. First I select a files, this file will directly converted to Base64
2. I fillin all my other fields
3. When I click the button Create, I need the Base64 hashcode in this private methode
}
推荐答案
private void buttonBrowse_Click(object sender, EventArgs e) {
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "All Supported Files (All Files (*.*)|*.*";
if (openDlg.ShowDialog(this) == DialogResult.OK) {
Cursor = Cursors.WaitCursor;
textBoxAttachFile.Text = openDlg.FileName;
try {
textBoxDescribeIncident.Text = FileToBase64String(openDlg.FileName); //<<<---HERE!
} catch (Exception) {
MessageBox.Show(this, string.Format("An error occurred whilst converting to base-64."),
Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Cursor = Cursors.Default;
}
}
您可以通过其他按钮(只要它们具有相同的格式)进行访问:
You can access that from your other buttons, provided they are on the same form:
private void buttonCreate_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBoxDescribeIncident.Text))
{
MessageBox.Show("Here it is: " + textBoxDescribeIncident.Text);
}
}
如果您不想在文本框中显示信息,请声明一个私有字符串,然后将其放在那里.
如果您需要以其他形式使用它,那是另一回事-易于解决,但又有所不同!
If you don''t want to display the info in a text box, then declare a private string and put it there instead.
If you need it on a different form, then that''s another matter - easy to solve, but different!
这篇关于其他私人方法中的按钮单击结果重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!