❔ Add textbox.text from Form1 to another class
Hi, i want to add textbox9.text from Form1 to the filename that is in another class. Ive made it public, but it doesnt work. Thanks
8 Replies
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Also, nobody is going to download a rar file just to help.
Please paste the important snippets to the site linked above and add way more context regarding your issue.
public System.Windows.Forms.TextBox textBox9;
Object newFileName = Path.Combine(_fileInfo.DirectoryName, "docs", _fileInfo.Name + DateTime.Now.ToString("ddMMyy"));
the textbox9 seems to be public
namespace BlankiDoc___Lekari
{
class WordHelper
{
private FileInfo _fileInfo;
public WordHelper(string fileName) {
if (File.Exists(fileName)) { _fileInfo = new FileInfo(fileName); } else { throw new ArgumentException("File not found"); } }
internal bool Process(Dictionary<string, string> items) { Word.Application app = null; try { app = new Word.Application(); Object file = _fileInfo.FullName;
Object missing = Type.Missing;
app.Documents.Open(file); foreach (var item in items) { Word.Find find = app.Selection.Find; find.Text = item.Key; find.Replacement.Text = item.Value; Object wrap = Word.WdFindWrap.wdFindContinue; Object replace = Word.WdReplace.wdReplaceAll; find.Execute(FindText: Type.Missing, MatchCase: false, MatchWholeWord: false, MatchWildcards: false, MatchSoundsLike: missing, MatchAllWordForms: false, Forward: true, Wrap: wrap, Format: false, ReplaceWith: missing, Replace: replace);
} Object newFileName = Path.Combine(_fileInfo.DirectoryName, "docs", _fileInfo.Name + DateTime.Now.ToString("ddMMyy")); app.ActiveDocument.SaveAs2(newFileName); app.ActiveDocument.Close(); MessageBox.Show("Документът : " + newFileName + " е успешно създаден.");
return true; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (app != null) { app.Quit(); } } return false;
} } }
private FileInfo _fileInfo;
public WordHelper(string fileName) {
if (File.Exists(fileName)) { _fileInfo = new FileInfo(fileName); } else { throw new ArgumentException("File not found"); } }
internal bool Process(Dictionary<string, string> items) { Word.Application app = null; try { app = new Word.Application(); Object file = _fileInfo.FullName;
Object missing = Type.Missing;
app.Documents.Open(file); foreach (var item in items) { Word.Find find = app.Selection.Find; find.Text = item.Key; find.Replacement.Text = item.Value; Object wrap = Word.WdFindWrap.wdFindContinue; Object replace = Word.WdReplace.wdReplaceAll; find.Execute(FindText: Type.Missing, MatchCase: false, MatchWholeWord: false, MatchWildcards: false, MatchSoundsLike: missing, MatchAllWordForms: false, Forward: true, Wrap: wrap, Format: false, ReplaceWith: missing, Replace: replace);
} Object newFileName = Path.Combine(_fileInfo.DirectoryName, "docs", _fileInfo.Name + DateTime.Now.ToString("ddMMyy")); app.ActiveDocument.SaveAs2(newFileName); app.ActiveDocument.Close(); MessageBox.Show("Документът : " + newFileName + " е успешно създаден.");
return true; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (app != null) { app.Quit(); } } return false;
} } }
share code through this https://paste.mod.gg/
BlazeBin
A tool for sharing your source code with the world!
BlazeBin Basic - yxoohugpkmez
A tool for sharing your source code with the world!
BlazeBin - yxoohugpkmez
A tool for sharing your source code with the world!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.