2016-12-16 5 views
0

私はここ1枚のパネルと4ラベル内部に4つのラベルを持つ独自のパネルを作成するにはどうすればいいですか?

は私が追加しようとするとこれは、デザイナーファイル

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ 
Partial Class OrderPanel 
    Inherits System.Windows.Forms.UserControl 

    'UserControl overrides dispose to clean up the component list. 
    <System.Diagnostics.DebuggerNonUserCode()> _ 
    Protected Overrides Sub Dispose(ByVal disposing As Boolean) 
     Try 
      If disposing AndAlso components IsNot Nothing Then 
       components.Dispose() 
      End If 
     Finally 
      MyBase.Dispose(disposing) 
     End Try 
    End Sub 

    'Required by the Windows Form Designer 
    Private components As System.ComponentModel.IContainer 

    'NOTE: The following procedure is required by the Windows Form Designer 
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor. 
    <System.Diagnostics.DebuggerStepThrough()> _ 
    Private Sub InitializeComponent() 
     Me.Label1 = New System.Windows.Forms.Label() 
     Me.Label2 = New System.Windows.Forms.Label() 
     Me.Label3 = New System.Windows.Forms.Label() 
     Me.Label4 = New System.Windows.Forms.Label() 
     Me.SuspendLayout() 
     ' 
     'Label1 
     ' 
     Me.Label1.AutoSize = True 
     Me.Label1.Font = New System.Drawing.Font("Microsoft YaHei", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) 
     Me.Label1.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(161, Byte), Integer), CType(CType(218, Byte), Integer)) 
     Me.Label1.Location = New System.Drawing.Point(3, 2) 
     Me.Label1.Name = "Label1" 
     Me.Label1.Size = New System.Drawing.Size(59, 21) 
     Me.Label1.TabIndex = 0 
     Me.Label1.Text = "Label1" 
     ' 
     'Label2 
     ' 
     Me.Label2.AutoSize = True 
     Me.Label2.Font = New System.Drawing.Font("Microsoft YaHei", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) 
     Me.Label2.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(161, Byte), Integer), CType(CType(218, Byte), Integer)) 
     Me.Label2.Location = New System.Drawing.Point(3, 23) 
     Me.Label2.Name = "Label2" 
     Me.Label2.Size = New System.Drawing.Size(59, 21) 
     Me.Label2.TabIndex = 1 
     Me.Label2.Text = "Label2" 
     ' 
     'Label3 
     ' 
     Me.Label3.AutoSize = True 
     Me.Label3.Font = New System.Drawing.Font("Microsoft YaHei", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) 
     Me.Label3.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(161, Byte), Integer), CType(CType(218, Byte), Integer)) 
     Me.Label3.Location = New System.Drawing.Point(3, 44) 
     Me.Label3.Name = "Label3" 
     Me.Label3.Size = New System.Drawing.Size(59, 21) 
     Me.Label3.TabIndex = 2 
     Me.Label3.Text = "Label3" 
     ' 
     'Label4 
     ' 
     Me.Label4.Font = New System.Drawing.Font("Microsoft YaHei", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
     Me.Label4.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(161, Byte), Integer), CType(CType(218, Byte), Integer)) 
     Me.Label4.Location = New System.Drawing.Point(257, 0) 
     Me.Label4.Name = "Label4" 
     Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.Yes 
     Me.Label4.Size = New System.Drawing.Size(128, 23) 
     Me.Label4.TabIndex = 3 
     Me.Label4.Text = "Label4" 
     Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft 
     ' 
     'OrderPanel 
     ' 
     Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) 
     Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font 
     Me.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle 
     Me.Controls.Add(Me.Label4) 
     Me.Controls.Add(Me.Label3) 
     Me.Controls.Add(Me.Label2) 
     Me.Controls.Add(Me.Label1) 
     Me.Name = "OrderPanel" 
     Me.Size = New System.Drawing.Size(386, 66) 
     Me.ResumeLayout(False) 
     Me.PerformLayout() 

    End Sub 

    Friend WithEvents Label1 As Label 
    Friend WithEvents Label2 As Label 
    Friend WithEvents Label3 As Label 
    Friend WithEvents Label4 As Label 
End Class 

ある

Public Class OrderPanel 
    Inherits Panel 

    Public ItemName As String 
    Public Quantity As Integer 
    Public Price As Decimal 
    Public DiscountType As Boolean 
    Public DiscountAmount As Decimal 
    Public Properties As String 
    Public SubTotal As Decimal 
End Class 

これまでにしようとするものである含めるユーザーコントロールを作成したいですこのユーザーが私のフォームにこのエラーを受け取りました

"ツールボックス項目を読み込めませんでした。ツールボックスから削除されます" error image

どうすれば問題を解決できますか?あなたのOrderPanelクラスは、ユーザーコントロール

Public Class OrderPanel 
    Inherits UserControl 
+0

ルックデザイナーファイルとコードファイルの上部に表示されます。 'UserControl'とVB.NETでは許可されていない' Panel'の2つの継承があります。デザイナファイルの継承を削除し、コードファイル内の 'Panel'を保持するか、またはその反対に、デザイナファイルを変更して' Panel'を継承し、コードファイルで削除します。 –

+1

@AlexB。私たちはほぼ同じような答えに近づいたように見えます。私があなたのために私のものを取るようにしたい場合は、私に教えてください。 –

+0

@AndrewMortimer私たちの答えはまったく同じではありません。 UserControlの代わりに継承をPanelに変更することをお勧めします。これは、OrderPanelクラスのPanel固有のすべてのプロパティを削除するためです。意味があれば私の答えを見てください。あなたはあなたのことを確かに保つことができます。 –

答えて

2

から継承されなければならない

1

アンドリューの答えは結構ですが、あなたがUserControlに継承を変更するときは、OrderPanelクラス内のすべてのPanel特定のプロパティ(のようなAutoScaleDimensions)を失うことになります。

それでは、私がお勧めすることはPanel継承を維持するが、生成されたものを削除することです:

OrderPanel.designer.vb

Partial Class OrderPanel 
     'Inherits System.Windows.Forms.UserControl' <--- delete this 
     Inherits Panel '<--- add this 

OderPanel.vb

Public Class OrderPanel 
    'Inherits Panel <--- delete this 
関連する問題