C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


(過去ログ 112 を表示中)
■66192 / )  NullReferenceException
□投稿者/ 名無しさん@C#初心者 (1回)-(2013/04/07(Sun) 22:28:56)

分類:[C#] 

2013/04/07(Sun) 22:29:29 編集(投稿者)
2013/04/07(Sun) 22:29:20 編集(投稿者)

配列でタブページ・ブラウザを作り、タブページにブラウザを貼り付けました。実行してみたらNullReferenceExceptionという例外が発生したので、調べてみたところ、nullとか空白を表すものが選択されると起こるようなので空白の配列を探しましたが、よくわかりませんでした。解決策はありますか?
-----以下コード-----
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Permissions;
using Microsoft.Win32;

namespace WebBrowser
{
    public partial class Form1 : Form
    {
        public System.Windows.Forms.TabPage[] tabPages;
        public System.Windows.Forms.WebBrowser[] webBrowsers;
        public Form1()
        {
            InitializeComponent();                                 //GUiエディタではメニューバーとステータスバーしか貼り付けていません。
            String fn = System.Environment.GetCommandLineArgs()[0];
            String fbe = @"Software/Microsoft/InternetExplorer/Main/wb1/emulation";
            String fdcm = @"SoftWare/Microsoft/InternetExplorer/Main/wb1/mode";
            using (RegistryKey regkey1 = Registry.CurrentUser.CreateSubKey(fbe)) 
            using (RegistryKey regkey2 = Registry.CurrentUser.CreateSubKey(fdcm)) 
            {
                regkey1.SetValue(fn, 8000, RegistryValueKind.DWord);  //UserAgent変更(IE8)
                regkey2.SetValue(fn, 80000, RegistryValueKind.DWord); //レンダリングモード(IE8)
                regkey1.Close();
                regkey2.Close();
            }
            TabControl tabControl1 = new TabControl()
            {
                Dock = DockStyle.Fill,
            };
            this.SuspendLayout();
            this.webBrowsers = new System.Windows.Forms.WebBrowser[5];
            for (int x = 0; x < this.webBrowsers.Length; x++)
            {
                this.webBrowsers[x] = new System.Windows.Forms.WebBrowser();
                this.webBrowsers[x].Name = "webBrowser" + x.ToString();
                this.webBrowsers[x].Url = new Uri("http://google.com");
                this.webBrowsers[x].ScrollBarsEnabled = true;
                this.webBrowsers[x].Dock = DockStyle.Fill;
            }
            this.tabPages = new System.Windows.Forms.TabPage[5];
            for (int i = 0; i < this.tabPages.Length; i++)
            {
                this.tabPages[i] = new System.Windows.Forms.TabPage();
                this.tabPages[i].Name = "TabPage" + i.ToString();
                this.tabPages[i].Text = "タブ" + i;
                this.tabPages[i].AutoScroll = true;
                this.Controls.AddRange(this.webBrowsers);
                tabControl1.Controls.AddRange(tabPages);
            }
            this.Controls.Add(tabControl1);
        }
    }
}

返信 編集キー/


管理者用

- Child Tree -