« 10.16 今年も注文。 | ココ | 10.18 ムツゴロウ動物王国が閉園 »

2007年10月17日

トップレベルを真にすると  このエントリーを含むはてなブックマーク 

大問題発生。

Me.Hide()
Me.TopLevel = True

せっかくHideで非表示にしたのに、TopLevelをTrueにしただけでフォームが表示されてしまう。これはバグと言うべきなのか、仕様なので仕方ないのか。

ただし、フツーにやってもこの現象は起きなかった。1度でも、Opacityプロパティで透過率を変更すると、TopLevel = TrueでVisible = Trueになる。



Control.SetTopLevel Method
(ref. msdn2)

Remarks

If you call the SetTopLevel method of a Form and pass in a value of false, the form will not be visible until you call SetTopLevel again, passing in a value of true.

…「SetTopLevel(True)をするまでフォームは表示されませんよ」、ということはSetTopLevel(True)をするとフォームが表示される、のか?

まあ、とりあえず順番入れ替えてなんとかドッキング、フローティングを切り替えるプロパティができた。

Public Property BehaveAsControl() As Boolean
  Get
    ' トップレベルコントロールか=子コントロールか
    Return Not Me.TopLevel
  End Get
  Set(ByVal Value As Boolean)
    Me.Hide()
    If Value And Me.TopLevel Then
      ' フローティング→ドッキング
      If Not IsNothing(Me.Owner) Then _internalDesktopBounds = Me.DesktopBounds
      Me.TopLevel = False
      _internalParent.Controls.Add(Me)

    ElseIf Not (Value Or Me.TopLevel) Then
      ' ドッキング→フローティング
      Me.Parent.Controls.Remove(Me)

    End If
    Me.FormBorderStyle = IIf(Value, FormBorderStyle.None, FormBorderStyle.SizableToolWindow)
    Me.Dock = IIf(Value, DockStyle.Fill, DockStyle.None)
    If _internalDesktopBounds.IsEmpty Then
      Me.DesktopLocation = _internalParent.PointToScreen(Point.Empty)
    Else
      Me.DesktopBounds = _internalDesktopBounds
    End If
    Me.TopLevel = Not Value
    If Me.TopLevel Then Me.Owner = _internalParent.FindForm()
    Me.Show()

  End Set
End Property

By ただ at 21:02 カテゴリー ; PinMarch Samples , VB, VB .net , プログラミング単語帳 , mein Erbe

« 10.16 今年も注文。 | 10月の記事 | 10.18 ムツゴロウ動物王国が閉園 »




トラックバック

このエントリーのトラックバックURL:
http://pinmarch.sakura.ne.jp/mt/mt-tb.cgi/1106