Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Is it normal for these codes to be in the main project after class library has been placed on the form?

Here:

VB
Private Sub InitializeComponent()
       Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
       Me.CustomButton1 = New Custom_Button.CustomButton
       Me.CustomButton21 = New Custom_Button.CustomButton2
       Me.SuspendLayout()
       '
       'CustomButton1
       '
       Me.CustomButton1.BackgroundImage = CType(resources.GetObject("CustomButton1.BackgroundImage"), System.Drawing.Image)
       Me.CustomButton1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch
       Me.CustomButton1.Cursor = System.Windows.Forms.Cursors.Hand
       Me.CustomButton1.FlatAppearance.BorderSize = 0
       Me.CustomButton1.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent
       Me.CustomButton1.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent
       Me.CustomButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
       Me.CustomButton1.ForeColor = System.Drawing.Color.White
       Me.CustomButton1.Location = New System.Drawing.Point(29, 12)
       Me.CustomButton1.Name = "CustomButton1"
       Me.CustomButton1.Size = New System.Drawing.Size(265, 93)
       Me.CustomButton1.TabIndex = 0
       Me.CustomButton1.UseVisualStyleBackColor = True
       '
       'CustomButton21
       '
       Me.CustomButton21.BackgroundImage = CType(resources.GetObject("CustomButton21.BackgroundImage"), System.Drawing.Image)
       Me.CustomButton21.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch
       Me.CustomButton21.Cursor = System.Windows.Forms.Cursors.Hand
       Me.CustomButton21.FlatAppearance.BorderSize = 0
       Me.CustomButton21.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent
       Me.CustomButton21.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent
       Me.CustomButton21.FlatStyle = System.Windows.Forms.FlatStyle.Flat
       Me.CustomButton21.ForeColor = System.Drawing.Color.White
       Me.CustomButton21.Location = New System.Drawing.Point(29, 111)
       Me.CustomButton21.Name = "CustomButton21"
       Me.CustomButton21.Size = New System.Drawing.Size(265, 98)
       Me.CustomButton21.TabIndex = 1
       Me.CustomButton21.UseVisualStyleBackColor = True
       '
       'Form1
       '
       Me.ClientSize = New System.Drawing.Size(324, 223)
       Me.Controls.Add(Me.CustomButton21)
       Me.Controls.Add(Me.CustomButton1)
       Me.Name = "Form1"
       Me.ResumeLayout(False)

   End Sub


Thanks.
Posted
Comments
Richard Deeming 14-Oct-14 13:45pm    
Yes. That's standard code generated by the Windows Forms designer.
Doughnatch 14-Oct-14 14:01pm    
It's not in the designer. The only codes in the designer are these:


<global.microsoft.visualbasic.compilerservices.designergenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form



Friend WithEvents CustomButton1 As Custom_Button.CustomButton
Friend WithEvents CustomButton21 As Custom_Button.CustomButton2
End Class
Sergey Alexandrovich Kryukov 14-Oct-14 14:08pm    
Then it's bad. Create your own method, don't call it "InitializeComponent".
Did you or someone copy the auto-generated code to some other place? Do yourself a favor, stay out of trouble.
—SA
Doughnatch 14-Oct-14 14:10pm    
I haven't tried it on another form. It had trouble at first when I immediately deleted the .dll file then browse for it again. I'll just try it later .

1 solution

It should be in the designer source files, unless you have moved the InitilizeComponent method into your own code - that is (as Richard says) standard framework initialization code which is normally in the "MyForm.designer.vb" file - except in very early versions of VS for .NET (IIRC) which didn't separate the two as well as they do now.
 
Share this answer
 
Comments
Richard Deeming 14-Oct-14 14:41pm    
It was probably VS.NET and VS.NET 2003 - partial classes weren't added until .NET 2.0, with VS2005.
OriginalGriff 14-Oct-14 14:53pm    
Ah! Yes, you're right - that was before my C# / .NET experience started (thankfully).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900