Public Class Form1 Dim ContextMenuStrip1 As New ContextMenuStrip Private toolStripNumeric1 As ToolStripNumericUpDown Protected Overrides Sub OnLoad(ByVal e As EventArgs) MyBase.OnLoad(e) toolStripNumeric1 = New ToolStripNumericUpDown() ContextMenuStrip1.Items.Add(toolStripNumeric1) Me.ContextMenuStrip = ContextMenuStrip1 AddHandler toolStripNumeric1.Click, AddressOf N1 End Sub
Private Sub N1(ByVal sender As System.Object, ByVal e As System.EventArgs) MessageBox.Show((CType(toolStripNumeric1.Control, NumericUpDown).Value)) End Sub End Class
Public Class ToolStripNumericUpDown Inherits ToolStripControlHost Public Sub New() MyBase.New(New NumericUpDown()) End Sub End Class
Public Class Form1 Dim ContextMenuStrip1 As New ContextMenuStrip Private toolStripNumeric1 As ToolStripNumericUpDown Protected Overrides Sub OnLoad(ByVal e As EventArgs) MyBase.OnLoad(e) toolStripNumeric1 = New ToolStripNumericUpDown() ContextMenuStrip1.Items.Add(toolStripNumeric1) toolStripNumeric1.AutoSize = False toolStripNumeric1.Width = 80 toolStripNumeric1.Height = 24
Me.ContextMenuStrip = ContextMenuStrip1 AddHandler toolStripNumeric1.Click, AddressOf N1 End Sub
Private Sub N1(ByVal sender As System.Object, ByVal e As System.EventArgs) MessageBox.Show((CType(toolStripNumeric1.Control, NumericUpDown).Value)) End Sub End Class
Public Class ToolStripNumericUpDown Inherits ToolStripControlHost Public Sub New() MyBase.New(New NumericUpDown()) End Sub End Class
分類:[.NET]
つぎのようにしてContextMenuStripにNumericUpDownを表示させたのですが
メニュー自体が上下に窮屈な表示になり,しかも下げボタン(数値の上げ下げ
ではなくメニュー自体の上下幅についているボタン)を押すとエラーです.
数値の上下ボタンを押すとちゃんとした大きさになり,エラーも出ません.
一回数値ボタンを押すと2回目以降は表示の大きさも問題ないです.
エラー回避と,できたら最初から本来のNumericUpDownの大きさが表示される
ようにしたいのですが方法はあるでしょうか.
Public Class Form1
Dim ContextMenuStrip1 As New ContextMenuStrip
Private toolStripNumeric1 As ToolStripNumericUpDown
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
toolStripNumeric1 = New ToolStripNumericUpDown()
ContextMenuStrip1.Items.Add(toolStripNumeric1)
Me.ContextMenuStrip = ContextMenuStrip1
AddHandler toolStripNumeric1.Click, AddressOf N1
End Sub
Private Sub N1(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show((CType(toolStripNumeric1.Control, NumericUpDown).Value))
End Sub
End Class
Public Class ToolStripNumericUpDown
Inherits ToolStripControlHost
Public Sub New()
MyBase.New(New NumericUpDown())
End Sub
End Class