2017-07-01 9 views
1
public partial class displayvoltage : UserControl 
{ 
    public displayvoltage() 
    { 
     InitializeComponent(); 
     if (!this.ratio_1.Checked && !this.ratio_12.Checked && !this.ratio_34.Checked && !this.ratio_14.Checked) 
      this.ratio_1.Checked = true; 
    } 

    public double Ratio 
    { 
     get 
     { 
      if (this.ratio_1.Checked) return 1.0; 
      if (this.ratio_1.Checked) return 4.0/3.0; 
      if (this.ratio_1.Checked) return 2.0; 
      return 4.0; 
     } 
    } 

    public int SetRatio 
    { 
     set 
     { 
      if (value == 1) this.ratio_1.Checked = true; 
      if (value == 2) this.ratio_34.Checked = true; 
      if (value == 3) this.ratio_12.Checked = true; 
      if (value == 4) this.ratio_14.Checked = true; 
      SetRatio = value; 
     } 
    } 

    [DefaultValue(0.0)] 
    public double Voltage 
    { 
     get { return Voltage * this.Ratio; } 
     set { Voltage = value; } 
    } 

    private bool DisplayVoltage = false; 
    private bool Pause = false; 

    private void ratio_CheckedChanged(object sender, EventArgs e) 
    { 
     RadioButton r = (RadioButton)sender; 

     if (r.Checked) Invalidate(); 
    } 
} 

デザイナーだけで4つのラジオと1つのパネルで作成されました。 コントロールVSのプロパティを表示したい場合でも、プログラムを起動するとクラッシュします。何が問題なの?この単純なユーザー制御コードはVS2015をクラッシュさせます。理由は分かりません

私は取得のみでプロパティを持つことはできますか?

+1

SetRatioとVoltageでスタックオーバーフロー例外を作成します。 VSがあなたのコントロールをロードすると、このコードを実行するとOSがシャットダウンします。 –

答えて

2

が、これはStackOverflowのが原因無限ループを引き起こしているので、それはいくつかの理由であってもよいが、最も可能性が高いでした:

public int SetRatio 
{ 
    set 
    { 
     if (value == 1) this.ratio_1.Checked = true; 
     if (value == 2) this.ratio_34.Checked = true; 
     if (value == 3) this.ratio_12.Checked = true; 
     if (value == 4) this.ratio_14.Checked = true; 
     SetRatio = value; 
    } 
} 

SetRatioがコードになりSetRatioプロパティのセッターを呼び出すことができ、最後の行

if (value == 1) this.ratio_1.Checked = true; 
if (value == 2) this.ratio_34.Checked = true; 
if (value == 3) this.ratio_12.Checked = true; 
if (value == 4) this.ratio_14.Checked = true; 
SetRatio = value; 

から繰り返し実行してください。 VSと.NETは、スタックオーバーフローやメモリ不足例外をあまりうまく処理しません。

試してみてください。

int setRatio; 
public int SetRatio 
{ 
    set 
    { 
     if (value == 1) this.ratio_1.Checked = true; 
     if (value == 2) this.ratio_34.Checked = true; 
     if (value == 3) this.ratio_12.Checked = true; 
     if (value == 4) this.ratio_14.Checked = true; 
     setRatio = value; 
    } 
} 

例外をスローするコンストラクタを持つコントロールが同様にクラッシュするVSを引き起こす可能性があるので、それはそれが問題を引き起こしているかどうかを確認するために、あなたのコンストラクタを変更してみてください動作しない場合:

public displayvoltage() 
{ 
    InitializeComponent(); 
    //if (!this.ratio_1.Checked && !this.ratio_12.Checked && !this.ratio_34.Checked && !this.ratio_14.Checked) 
    // this.ratio_1.Checked = true; 
} 
+0

コンストラクタが問題を引き起こしていましたが、ソリューションをビルドしていただけでもクラッシュし始めました。ありがとうございました。 –

関連する問題