質問編集履歴
3
画像を添付する。
title
CHANGED
File without changes
|
body
CHANGED
@@ -139,4 +139,7 @@
|
|
139
139
|
ただし、これを実行したらなぜかエラーが
|
140
140
|
|
141
141
|
CS1061 'object' に 'Tostring' の定義が含まれておらず、型 'object' の最初の引数を受け付ける拡張メソッド 'Tostring' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足していないことを確認してください。 66 アクティブ
|
142
|
-
と変更されていました。
|
142
|
+
と変更されていました。
|
143
|
+
|
144
|
+
ソリューションエクスプローラーの画面です。
|
145
|
+

|
2
回答者に伝えたいコードを伝えたいが、返信文ではコードを添付できない
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[このサイト](https://msdn.microsoft.com/ja-jp/library/system.windows.forms.systeminformation.bootmode(v=vs.110).aspx)にあるプログラムなんですが、
|
1
|
+
[このサイト](https://msdn.microsoft.com/ja-jp/library/system.windows.forms.systeminformation.bootmode(v=vs.110).aspx)にあるプログラムなんですが、(参照先のプログラムを参考にしてください)
|
2
2
|
フォームアプリとして起動して、リストボックスにある項目を選択すると
|
3
3
|
イベントハンドラーが発動するようになっていると思います。
|
4
4
|
イベントハンドラーの内容としていろんな状態を表すもの?となっています。
|
@@ -6,8 +6,29 @@
|
|
6
6
|
それで質問なんですが
|
7
7
|
|
8
8
|
|
9
|
+
listboxのbootmodeを選択して、Normalの値が帰った時、何かしら実行するようにしたいのです。それで、
|
9
10
|
```C#
|
11
|
+
prop = pi[i];
|
12
|
+
break;
|
13
|
+
}
|
14
|
+
object propval = prop.GetValue(null, null);
|
15
|
+
textBox1.Text += "\r\nThe value of the "+propname+" property is: "+propval.ToString();
|
16
|
+
|
17
|
+
```
|
18
|
+
この部分のコードの下に
|
19
|
+
```C#
|
20
|
+
if(propval.Tostring() == "Normal"){
|
21
|
+
Console.WriteLine("hello!")
|
22
|
+
}
|
23
|
+
コード
|
24
|
+
```
|
25
|
+
以上のようなコードを加えると
|
26
|
+
stringを暗黙でbool形に変換できませんとエラーが出てきます。
|
27
|
+
|
28
|
+
listboxのbootmodeを選択して、Normalの値が帰った時、何かしら実行するプログラムを作りたいので、だれか適切な助言をください。
|
29
|
+
※補足
|
10
|
-
|
30
|
+
以下のコードは実際打ったコードの全体です。
|
31
|
+
```C#
|
11
32
|
using System;
|
12
33
|
using System.Collections;
|
13
34
|
using System.ComponentModel;
|
@@ -15,64 +36,70 @@
|
|
15
36
|
using System.Reflection;
|
16
37
|
using System.Windows.Forms;
|
17
38
|
|
18
|
-
namespace
|
39
|
+
namespace jikannwoenntyousuru
|
19
40
|
{
|
20
41
|
public class SystemInfoBrowserForm : System.Windows.Forms.Form
|
21
42
|
{
|
22
43
|
private System.Windows.Forms.ListBox listBox1;
|
23
|
-
private System.Windows.Forms.TextBox textBox1;
|
44
|
+
private System.Windows.Forms.TextBox textBox1;
|
24
45
|
|
25
46
|
public SystemInfoBrowserForm()
|
26
|
-
|
47
|
+
{
|
27
48
|
this.SuspendLayout();
|
28
49
|
InitForm();
|
29
50
|
|
30
51
|
// Add each property of the SystemInformation class to the list box.
|
31
|
-
Type t = typeof(System.Windows.Forms.SystemInformation);
|
52
|
+
Type t = typeof(System.Windows.Forms.SystemInformation);
|
32
|
-
PropertyInfo[] pi = t.GetProperties();
|
53
|
+
PropertyInfo[] pi = t.GetProperties();
|
33
|
-
for
|
54
|
+
for (int i = 0; i < pi.Length; i++)
|
34
|
-
listBox1.Items.Add(
|
55
|
+
listBox1.Items.Add(pi[i].Name);
|
35
|
-
textBox1.Text = "The SystemInformation class has "+pi.Length.ToString()+" properties.\r\n";
|
56
|
+
textBox1.Text = "The SystemInformation class has " + pi.Length.ToString() + " properties.\r\n";
|
36
57
|
|
37
58
|
// Configure the list item selected handler for the list box to invoke a
|
38
59
|
// method that displays the value of each property.
|
39
60
|
listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
|
40
61
|
this.ResumeLayout(false);
|
41
|
-
|
62
|
+
}
|
42
63
|
|
43
64
|
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
|
44
65
|
{
|
45
66
|
// Return if no list item is selected.
|
46
|
-
if
|
67
|
+
if (listBox1.SelectedIndex == -1) return;
|
47
68
|
// Get the property name from the list item.
|
48
69
|
string propname = listBox1.Text;
|
49
70
|
|
50
|
-
if
|
71
|
+
if (propname == "PowerStatus")
|
51
72
|
{
|
52
73
|
// Cycle and display the values of each property of the PowerStatus property.
|
53
|
-
textBox1.Text += "\r\nThe value of the PowerStatus property is:";
|
74
|
+
textBox1.Text += "\r\nThe value of the PowerStatus property is:";
|
54
75
|
Type t = typeof(System.Windows.Forms.PowerStatus);
|
55
|
-
PropertyInfo[] pi = t.GetProperties();
|
76
|
+
PropertyInfo[] pi = t.GetProperties();
|
56
|
-
for
|
77
|
+
for (int i = 0; i < pi.Length; i++)
|
57
78
|
{
|
58
|
-
object propval = pi[i].GetValue(SystemInformation.PowerStatus, null);
|
79
|
+
object propval = pi[i].GetValue(SystemInformation.PowerStatus, null);
|
59
|
-
textBox1.Text += "\r\n PowerStatus."+pi[i].Name+" is: "+propval.ToString();
|
80
|
+
textBox1.Text += "\r\n PowerStatus." + pi[i].Name + " is: " + propval.ToString();
|
60
81
|
}
|
61
82
|
}
|
62
83
|
else
|
63
84
|
{
|
64
85
|
// Display the value of the selected property of the SystemInformation type.
|
65
86
|
Type t = typeof(System.Windows.Forms.SystemInformation);
|
66
|
-
PropertyInfo[] pi = t.GetProperties();
|
87
|
+
PropertyInfo[] pi = t.GetProperties();
|
67
88
|
PropertyInfo prop = null;
|
68
|
-
for
|
89
|
+
for (int i = 0; i < pi.Length; i++)
|
69
|
-
if
|
90
|
+
if (pi[i].Name == propname)
|
70
91
|
{
|
71
92
|
prop = pi[i];
|
72
|
-
break;
|
93
|
+
break;
|
73
94
|
}
|
74
|
-
object propval = prop.GetValue(null, null);
|
95
|
+
object propval = prop.GetValue(null, null);
|
75
|
-
textBox1.Text += "\r\nThe value of the "+propname+" property is: "+propval.ToString();
|
96
|
+
textBox1.Text += "\r\nThe value of the " + propname + " property is: " + propval.ToString();
|
97
|
+
if (propval.Tostring() == "Normal")
|
98
|
+
{
|
99
|
+
Console.WriteLine("hello!");
|
100
|
+
}
|
101
|
+
|
102
|
+
|
76
103
|
}
|
77
104
|
}
|
78
105
|
|
@@ -80,51 +107,36 @@
|
|
80
107
|
{
|
81
108
|
// Initialize the form settings
|
82
109
|
this.listBox1 = new System.Windows.Forms.ListBox();
|
83
|
-
this.textBox1 = new System.Windows.Forms.TextBox();
|
110
|
+
this.textBox1 = new System.Windows.Forms.TextBox();
|
84
|
-
this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
111
|
+
this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
85
112
|
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
|
86
113
|
this.listBox1.Location = new System.Drawing.Point(8, 16);
|
87
114
|
this.listBox1.Size = new System.Drawing.Size(172, 496);
|
88
|
-
this.listBox1.TabIndex = 0;
|
115
|
+
this.listBox1.TabIndex = 0;
|
89
|
-
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
116
|
+
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
90
117
|
| System.Windows.Forms.AnchorStyles.Right)));
|
91
118
|
this.textBox1.Location = new System.Drawing.Point(188, 16);
|
92
119
|
this.textBox1.Multiline = true;
|
93
|
-
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
120
|
+
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
94
121
|
this.textBox1.Size = new System.Drawing.Size(420, 496);
|
95
|
-
this.textBox1.TabIndex = 1;
|
122
|
+
this.textBox1.TabIndex = 1;
|
96
|
-
this.ClientSize = new System.Drawing.Size(616, 525);
|
123
|
+
this.ClientSize = new System.Drawing.Size(616, 525);
|
97
124
|
this.Controls.Add(this.textBox1);
|
98
|
-
this.Controls.Add(this.listBox1);
|
125
|
+
this.Controls.Add(this.listBox1);
|
99
|
-
this.Text = "Select a SystemInformation property to get the value of";
|
126
|
+
this.Text = "Select a SystemInformation property to get the value of";
|
100
127
|
}
|
101
128
|
|
102
129
|
[STAThread]
|
103
|
-
static void Main()
|
130
|
+
static void Main()
|
104
131
|
{
|
105
132
|
Application.Run(new SystemInfoBrowserForm());
|
106
133
|
}
|
107
134
|
}
|
108
135
|
}
|
109
|
-
```
|
110
136
|
|
111
|
-
listboxのbootmodeを選択して、Normalの値が帰った時、何かしら実行するようにしたいのです。それで、
|
112
|
-
```C#
|
113
|
-
prop = pi[i];
|
114
|
-
break;
|
115
|
-
}
|
116
|
-
object propval = prop.GetValue(null, null);
|
117
|
-
textBox1.Text += "\r\nThe value of the "+propname+" property is: "+propval.ToString();
|
118
|
-
|
119
137
|
```
|
120
|
-
この部分のコードの下に
|
121
|
-
```C#
|
122
|
-
if(propval.Tostring() == "Normal"){
|
123
|
-
Console.WriteLine("hello!")
|
124
|
-
}
|
125
|
-
コード
|
126
|
-
```
|
127
|
-
|
138
|
+
コピーしてみて試してみてください。
|
128
|
-
|
139
|
+
ただし、これを実行したらなぜかエラーが
|
129
140
|
|
130
|
-
|
141
|
+
CS1061 'object' に 'Tostring' の定義が含まれておらず、型 'object' の最初の引数を受け付ける拡張メソッド 'Tostring' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足していないことを確認してください。 66 アクティブ
|
142
|
+
と変更されていました。
|
1
参照先のハイパーリンクのつけ忘れ
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
このサイトにあるプログラムなんですが、
|
1
|
+
[このサイト](https://msdn.microsoft.com/ja-jp/library/system.windows.forms.systeminformation.bootmode(v=vs.110).aspx)にあるプログラムなんですが、
|
2
2
|
フォームアプリとして起動して、リストボックスにある項目を選択すると
|
3
3
|
イベントハンドラーが発動するようになっていると思います。
|
4
4
|
イベントハンドラーの内容としていろんな状態を表すもの?となっています。
|