質問編集履歴
4
コードに元のコードをコメントアウトで追加。元のプログラムの動作説明・今回の作成コードの経緯説明を追加。タイトルを実現したい内容に変更。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
WindowsフォームでPCカメラから読み込んだバーコードをWebブラウザの検索窓に入力し検索したい
|
body
CHANGED
@@ -106,6 +106,7 @@
|
|
106
106
|
//描画
|
107
107
|
graphic.DrawImage(bmp, 0, 0, frame.Cols, frame.Rows);
|
108
108
|
String text = scancode();
|
109
|
+
//Save(text); //参考にしたプログラムの元のコード
|
109
110
|
|
110
111
|
}
|
111
112
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
@@ -130,6 +131,24 @@
|
|
130
131
|
}
|
131
132
|
return text;
|
132
133
|
}
|
134
|
+
//参考にしたプログラムの元のコード
|
135
|
+
/*///<summary>
|
136
|
+
///データの保存
|
137
|
+
///</summary>
|
138
|
+
///<param name="text">
|
139
|
+
///</param>
|
140
|
+
private void Save(String text)
|
141
|
+
{
|
142
|
+
if (text == null)
|
143
|
+
{
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
String userProfilePath = Environment.GetEnvironmentVariable("userprofile");
|
147
|
+
String logPath = @"\Desktop\log.txt";
|
148
|
+
File.AppendAllText(userProfilePath + logPath, text + Environment.NewLine);
|
149
|
+
//メモを開く
|
150
|
+
System.Diagnostics.Process.Start("notepad.exe", userProfilePath + logPath);
|
151
|
+
}*/
|
133
152
|
|
134
153
|
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
|
135
154
|
{
|
@@ -149,6 +168,8 @@
|
|
149
168
|
}
|
150
169
|
}
|
151
170
|
```
|
171
|
+
参考にした元のプログラムは読み込んだバーコードを新規作成したメモ帳に入力・改行するものでした。
|
172
|
+
そのコードを参考にメモ帳ではなく検索窓に入力する方向にできないかと考え上記コードになりました。
|
152
173
|
|
153
174
|
参考資料:
|
154
175
|
https://belltree.life/windows-qr-code/
|
3
コードスレッドのイベントハンドラのpublicをprivateに変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -101,7 +101,7 @@
|
|
101
101
|
}
|
102
102
|
}
|
103
103
|
|
104
|
-
|
104
|
+
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
105
105
|
{
|
106
106
|
//描画
|
107
107
|
graphic.DrawImage(bmp, 0, 0, frame.Cols, frame.Rows);
|
@@ -119,7 +119,7 @@
|
|
119
119
|
/// <summary>
|
120
120
|
/// バーコードの解析
|
121
121
|
/// </summary>
|
122
|
-
|
122
|
+
private String scancode()
|
123
123
|
{
|
124
124
|
String text = null;
|
125
125
|
Result result = reader.Decode(frame.ToBitmap());
|
2
試したいことスレッドのコードをコードの挿入型に変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -161,7 +161,7 @@
|
|
161
161
|
Task.Delay(200).Wait():などの待機時間を入れて時間を何種類か変更して行いましたが、上記エラーが発生してしまします。
|
162
162
|
|
163
163
|
また、backgroundWorker1_ProgressChangedイベントハンドラにwebBrowser1_DocumentCompletedイベントハンドラを呼び出そうと以下の例の方法で行いましたが、HtmlElementCollection all = webBrowser1.Document.AllがwebBrowser1_DocumentCompletedイベントハンドラ内にないと上記のDocument.get nullのエラーが起きてしまいます。
|
164
|
-
|
164
|
+
```
|
165
165
|
private void button1_MouseMove(object sender, MouseEventArgs e)
|
166
166
|
{
|
167
167
|
mouseMove();
|
@@ -176,7 +176,7 @@
|
|
176
176
|
{
|
177
177
|
MessageBox.Show("Hey");
|
178
178
|
}
|
179
|
-
|
179
|
+
```
|
180
180
|
他のイベントハンドラに別のイベントハンドラを呼ぶ方法で解決するか、他の可能性としては、webBrowser1_DocumentCompletedイベントハンドラに代わるイベントハンドラではない処理方法を見つけるか、プログラムの組み方を改めて見直すかかと考えています。
|
181
181
|
未熟な故、長文かつ要領を得ないところもあると思いますがご教授いただければと思います。
|
182
182
|
よろしくお願い致します。
|
1
タイトル変更:更新前)DocumentCompletedイベントハンドラを別のイベントハンドラから呼び出す方法
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
DocumentCompletedイベントハンドラを別のイベントハンドラから呼び出
|
1
|
+
DocumentCompletedイベントハンドラの処理を別のイベントハンドラから呼び出したい
|
body
CHANGED
File without changes
|