DOBON.NETプログラミング道掲示板

■35306 / 5階層)  ラジオボタンの一括設定
□投稿者/ 魔界の仮面弁士 大御所(1508回)-(2022/12/26(Mon) 09:53:31)
  • アイコンNo35303に返信(ま〜さんの記事)
    >>いや、その <Type1> と <Type2> が何であったのかが重要なのですけれど?
    > 貼り付けました。

    画像でも良いですが、エラー一覧の内容は
    右クリック操作もしくは Ctrl+C を使って
    テキストとしてコピーできますよ。


    エラー BC30311 型 'RadioButton' の値を 'VisualStyleElement.Button.RadioButton' に変換できません。

    …というエラーメッセージは、代入式の右辺が `RadioButton` 型であるの対して、
    代入先の左辺の RadioButton 型が `VisualStyleElement.Button.RadioButton` 型という、
    「型名はどちらも RadioButton 型だが、所属する名前空間の異なる別物」への操作だと思われています。



    今回の場合、プロジェクト作成時のテンプレートとして、おそらく
     ★Windows フォーム アプリケーション (.NET Framework)
     ★Windows フォーム アプリ
    のいずれかを選択されている状況なのでしょう。

    そして現在は、Form1.vb ファイルの冒頭に、普段は記述されていないはずの
     Imports System.Windows.Forms.VisualStyles.VisualStyleElement.Button
    というコードが追加されている状況であると想像できます。もしそうなら、
     Dim Radio0() As RadioButton = {RadioButton1, RadioButton2, RadioButton3}
    という代入式左辺の As RadioButton とは
     As System.Windows.Forms.VisualStyles.VisualStyleElement.Button.RadioButton
    の意味になっています。一方、代入式右辺にある RadioButotn1〜3 は
     As System.Windows.Forms.RadioButton
    に相当するデータ型を意味するため、型の不一致でコンパイルエラーとなります。


    解決策としては、こんな感じ。

    (案1) 冒頭の「Imports System.Windows.Forms.VisualStyles.VisualStyleElement.Button」宣言を取り除く
    (案2) 変数宣言時に、クラス名だけでなく名前空間も明示するようにする
     Dim Radio1() As RadioButton = {…}
    →Dim Radio1() As Global.System.Windows.Forms.RadioButton = {…}


    > TEXTの方は問題ないです
    もしも「Imports System.Windows.Forms.VisualStyles.VisualStyleElement」という宣言が
    追加されていたら、As TextBox も同様の競合問題が発生していたことでしょう。


    なお、今回は状況的に Windows Forms での事象だったのでしょうけれども
    その他プロジェクトでも同種の問題は起こりえます。

    "RadioButton" ひとつとっても、これだけの種類があるので…。

    ・System.Windows.Forms.RadioButton クラス (System.Windows.Forms.dll)
    ・System.Windows.Forms.VisualStyles.VisualStyleElement.Button.RadioButton クラス (System.Windows.Forms.dll)
    ・System.Windows.Controls.RadioButton クラス (PresentationFramework.dll)
    ・System.Web.UI.WebControls.RadioButton クラス (System.Web.dll)
    ・System.Windows.Automation.ControlType.RadioButton フィールド (UIAutomationTypes.dll)
    ・System.Windows.Automation.Peers.AutomationControlType.RadioButton 列挙値 (PresentationFramework.dll)
    ・Microsoft.Windows.Themes.ClassicBorderStyle.RadioButton 列挙値 (PresentationFramework.Classic.dll)
違反を報告
削除キー/

前の記事(元になった記事) 次の記事(この記事の返信)
←Re[4]: ラジオボタンの一括設定 /ま〜 1671985404.jpg/13KB →Re[6]: ラジオボタンの一括設定 /ま〜
 
上記関連ツリー

Nomalアイコン ラジオボタンの一括設定 / ま〜 (22/12/23(Fri) 18:39) #35297
Nomalアイコン Re[1]: ラジオボタンの一括設定 / 魔界の仮面弁士 (22/12/23(Fri) 20:19) #35298
  └Nomalアイコン Re[2]: ラジオボタンの一括設定 / ま〜 (22/12/23(Fri) 20:43) #35299
    └Nomalアイコン Re[3]: ラジオボタンの一括設定 / 魔界の仮面弁士 (22/12/23(Fri) 22:45) #35300
      └Nomalアイコン Re[4]: ラジオボタンの一括設定 / ま〜 (22/12/26(Mon) 01:23) #35303 1671985404.jpg/13KB
        ├Nomalアイコン ラジオボタンの一括設定 / 魔界の仮面弁士 (22/12/26(Mon) 09:53) #35306 ←Now
        │└Nomalアイコン Re[6]: ラジオボタンの一括設定 / ま〜 (22/12/26(Mon) 16:11) #35307 解決み!
        └Nomalアイコン Re[5]: ラジオボタンの一括設定 / KOZ (22/12/26(Mon) 09:51) #35305

All 上記ツリーを一括表示 / 上記ツリーをトピック表示
 
上記の記事へ返信

Mode/  Pass/


- Child Tree -