Repairing VB.NET project - vb.net

I throw in huge troubles with recreating a multproject solution into a single project solution where my program become unusable.
I have all code files saved and problem is with showing designer in IDE and errors connecting with that.
Situation:
All forms are subclassed with class called cls_transform which make form transparent while moving.
Public Class cls_transform
Inherits System.Windows.Forms.Form
Private _OpacityMove As Double = 0.5
Private _OpacityOriginal As Double = 1
Private Const WM_NCLBUTTONDOWN As Long = &HA1
Private Const WM_NCLBUTTONUP As Long = &HA0
Private Const WM_MOVING As Long = &H216
Private Const WM_SIZE As Long = &H5
Private Sub cls_transform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Protected Overrides Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
Static LButtonDown As Boolean
If CLng(m.Msg) = WM_NCLBUTTONDOWN Then
LButtonDown = True
ElseIf CLng(m.Msg) = WM_NCLBUTTONUP Then
LButtonDown = False
End If
If LButtonDown Then
If CLng(m.Msg) = WM_MOVING Then
If Me.Opacity <> _OpacityMove Then
_OpacityOriginal = Me.Opacity
Me.Opacity = _OpacityMove
End If
End If
ElseIf Not LButtonDown Then
If Me.Opacity <> _OpacityOriginal Then Me.Opacity = _OpacityOriginal
End If
MyBase.DefWndProc(m)
End Sub
Public Property OpacityMove() As Double
Get
Return _OpacityMove
End Get
Set(ByVal Value As Double)
_OpacityMove = Value
End Set
End Property
Private Sub InitializeComponent()
Me.SuspendLayout()
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Name = "cls_transform"
Me.ResumeLayout(False)
End Sub
End Class
This is how code of one empty form "frm_myForm" look like:
Public Class frm_myForm
Inherits cls_transform
Private Sub frm_myForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
And this is Designer code of that form:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frm_myForm
Inherits cls_transform
'Form 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.SuspendLayout()
'
'frm_myForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Name = "frm_myForm"
Me.Text = "frm_myForm"
Me.ResumeLayout(False)
End Sub
End Class
When I try to "View Designer" from IDE instead of to see a form I get white screen with error:
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: frm_myForm --- The base class 'noviprog.cls_transform' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
That happen with all forms which inherits from cls_transform.
When cls_transform was in separate library (separate project of same solution) which was referenced to actual project that works.
Is it possible to get this working when code files and that class would be in same project and how to get this working?

Related

how to safe call a control from another thread using Timers.Timer

I read various posts, and made a practice project, but it does not works.
The form have a button and a text box with a default text 'Updated 0 times'. On button click starts the timer and each time update the text with the number of times the text was updated.
The exception of cross thread calls is not thrown, but when calling the text box, its .Text = "", the text is updated but not the text box on the form. And InvokeRequired is always false.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Here the textBox.Text = "Updated 0 times."
Dim checking_text As String = Me.TextBox1.Text
TimerTest.StartTimer()
End Sub
Delegate Sub UpdateTextInvoke(ByVal new_text As String)
Public Sub UpdateText(ByVal new_text As String)
'Here the textBox.Text = ""
Dim txtB As TextBox = Me.TextBox1
'InvokeRequired always = False.
If txtB.InvokeRequired Then
Dim invk As New UpdateTextInvoke(AddressOf UpdateText)
txtB.Invoke(invk, New Object() {new_text})
Else
'The value of this text box is updated, but the text on the form TextBox1 never changes
txtB.Text = new_text
End If
End Sub
End Class
Public Class TimerTest
Private Shared tmr As New System.Timers.Timer
Private Shared counter As Integer
Public Shared Sub StartTimer()
tmr.Interval = 5000
AddHandler tmr.Elapsed, AddressOf UdpateText
tmr.Enabled = True
End Sub
Public Shared Sub UdpateText(ByVal sender As Object, ByVal e As System.EventArgs)
counter += 1
Form1.UpdateText(String.Format("Updated {0} time(s).", counter))
End Sub
End Class
SOLVED
In the Class TimerTest added this code 'Private Shared myform As Form1 = Form1'
then changed 'Form1.UpdateText' To 'myform.UpdateText'
As indicated in the comments, you are using the default form instance feature of VB.Net. You could pass an instance of the form to the TimerTest class, and replace the reference to Form1 with the instance.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim checking_text As String = Me.TextBox1.Text
TimerTest.StartTimer(Me)
End Sub
Public Sub UpdateText(new_text As String)
If TextBox1.InvokeRequired Then
Dim invk As New Action(Of String)(AddressOf UpdateText)
TextBox1.Invoke(invk, {new_text})
Else
TextBox1.Text = new_text
End If
End Sub
End Class
Public Class TimerTest
Private Shared tmr As New System.Timers.Timer()
Private Shared counter As Integer
Private Shared instance As Form1
Public Shared Sub StartTimer(formInstance As Form1)
instance = formInstance
tmr.Interval = 5000
AddHandler tmr.Elapsed, AddressOf UdpateText
tmr.Enabled = True
End Sub
Public Shared Sub UdpateText(ByVal sender As Object, ByVal e As System.EventArgs)
counter += 1
instance.UpdateText(String.Format("Updated {0} time(s).", counter))
End Sub
End Class

how to save an image from a picturebox vb

I am interested in vb and am confused how to save the contents of a Picturebox as a png file when button1 is clicked. When I try to do it now, it produces the error I show below. I can't figure out how to fix this because I'm new to using visual basic. The debugger seemed to catch something but I can't make sense of it. I would be extremely pleased if someone would help me to fix this. Here is the code:
'*** Acknowlegements ***
'Ideas for this code came from the MicroSoft "Scribble" sample code,
'Christian Graus's excellent arcticle on a C++ code called "Doodle"
'and the MicroSoft website.
'By John Buettner
'26 July 2003
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form
'Namespace myPaint
Inherits System.Windows.Forms.Form ' Of course ;)
Dim mousePath As New System.Drawing.Drawing2D.GraphicsPath() 'declare a new Graphic path to follow the mouse movement
'*** below I declare some values for an Alpha and other user selected variables
'these will be used as I expand this program for a higher level use.
Dim myAlpha As Integer = 100 ' declare a Alpha variable
Dim myUserColor As New Color() 'this is a color the user selects
Friend WithEvents Button1 As Button
Friend WithEvents SaveFileDialog1 As SaveFileDialog
Dim myPenWidth As Single = 5 'set pen width variable
'**************************************************************
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form))
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'PictureBox1
'
Me.PictureBox1.BackColor = System.Drawing.Color.GhostWhite
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.PictureBox1.Location = New System.Drawing.Point(0, 33)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(696, 423)
Me.PictureBox1.TabIndex = 2
Me.PictureBox1.TabStop = False
'
'Button1
'
Me.Button1.Image = Global.Ubernote.My.Resources.Resources.fl
Me.Button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.Button1.Location = New System.Drawing.Point(12, 4)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 3
Me.Button1.Text = "Save"
Me.Button1.UseVisualStyleBackColor = True
'
'SaveFileDialog1
'
'
'Form
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(696, 456)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.PictureBox1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Form"
Me.Text = "Draw"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down
mousePath.StartFigure() ' The L mouse is down so we need to start a new line in mousePath
End If
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down
Try
mousePath.AddLine(e.X, e.Y, e.X, e.Y) 'Add mouse coordiantes to mousePath
Catch
MsgBox("No way, Hose!")
End Try
End If
PictureBox1.Invalidate() 'Repaint the PictureBox using the PictureBox1 Paint event
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
' Here is where we do the actual painting
Try ' error trapping
myUserColor = (System.Drawing.Color.Black) 'You can remove this line and add a user selected color to
'change the value of myUserColor
myAlpha = 100 ' This will give the color a Alpha effect, you can set this to 255 if you want a full color
Dim CurrentPen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Set up the pen
e.Graphics.DrawPath(CurrentPen, mousePath) 'draw the path! :)
Catch
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
SaveFileDialog1.ShowDialog()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub SaveFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Try
' Dim FileToSaveAs As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, SaveFileDialog1.FileName)
' PictureBox1.Image.Save(FileToSaveAs, System.Drawing.Imaging.ImageFormat.Jpeg)
'PictureBox1.Image.Save(FileToSaveAs)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Dim path As String
Dim pic As Image
pic = PictureBox1.Image
SaveFileDialog1.ShowDialog()
pic.Save(SaveFileDialog1.FileName)
End Sub
try this

VB.NET Drag text, set focus and enter key issue

I have an app that allows for text to be dragged-dropped into a text box. I also have a check box that allows the app to always be on top of all windows. My issues is when I drag text into the text box and I hit the enter key, it does not run the function unless I have the window in actual focus (by clicking on it).
My question is, how can I make sure when I drag text into the text box, it will make the window be the focus so when I hit the enter key, it will run my function?
Here is what I am trying with no luck:
Private Sub Form1_DragEnter(sender As Object, e As DragEventArgs) Handles Me.DragEnter
Me.Focus()
End Sub
Private Sub Form1_DragOver(sender As Object, e As DragEventArgs) Handles Me.DragOver
Me.Focus()
End Sub
I am posting the code as it works fine for me, try it on new project:
Public Class Form1
Private Sub TextBox1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
' Check the format of the data being dropped.
If (e.Data.GetDataPresent(DataFormats.Text)) Then
' Display the copy cursor.
e.Effect = DragDropEffects.Copy
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TextBox1_DragDrop(sender As Object, e As DragEventArgs) Handles TextBox1.DragDrop
' Drop text and move cursor to end of drag-dropped text
TextBox1.Text = e.Data.GetData(DataFormats.Text)
TextBox1.SelectionStart = TextBox1.Text.Length + 1
TextBox1.Focus()
Me.Activate()
End Sub
End Class
and designer:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form 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.TextBox1 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.AllowDrop = True
Me.TextBox1.Location = New System.Drawing.Point(30, 54)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(216, 125)
Me.TextBox1.TabIndex = 0
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.TopMost = True
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Class
Try to use Me.Activate() instead in DragEnter it should be enough

vb.net listen for parent form event on each child form

I am trying to implement a function on my parent form, that when the event fires, I want to perform actions on all of the child forms that are open. Because any given child form may or may not be open at a given time, I can't handle it directly from the event on the parent form: i.e., cant do the following as Child1 may not be initiated at the time:
--Parent Form--
Public Sub ParentEvent()
DoParentAction()
DoChild1Action()
DoChild2Action()
End Sub
Is there a way on each child page to listen for ParentEvent() to be fired? essentially, what I want to do is handle the ParentEvent() being fired, on the child page the same as if a button was clicked on the child page, something like this:
--Child1--
Public Sub ChildEvent() Handles ParentForm.DoParentAction()
DoChild1Action()
End Sub
This is easy to do, you just have to step around VB's WithEvents and Handles syntax to get at it.
Public Class ParentForm
Event OnDoSomething()
Private Sub DoSomething()
RaiseEvent OnDoSomething()
End Sub
End Class
and then
Public Class ChildForm
Public Sub New()
InitializeComponent()
AddHandler ParentForm.OnDoSomething, AddressOf DoSomething
End Sub
Private Sub DoSomething()
' do something
End Sub
Private Sub ChildForm_FormClosing(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles MyBase.FormClosing
RemoveHandler ParentForm.OnDoSomething, AddressOf DoSomething
End Sub
End Class
It's important to always make sure the event handler is removed before disposing the child form (else you end up with a memory leak).
The above assumes you are using the VB default instance of ParentForm - if you're not, obviously you have to reference things accordingly. A better approach might be to make the parent an argument in the constructor like:
Public Sub New(ByVal parent as ParentForm)
InitializeComponent()
AddHandler parent.OnDoSomething, AddressOf DoSomething
End Sub
also, of course, modifying the RemoveHandler section as well (you'd need to keep a reference to the parent). Another option is to hook/unhook in the ParentChanged event if this is an MDI application.
The only other caveat is that you can't create any of the child forms in the constructor of the parent form since you end up with self-reference during construction.
Sure.
Add a public event to the parent form:
Public Event EventFired(ByVal timestamp As DateTime)
In each child form, add a handler:
Public Sub ParentEventFired(ByVal timestamp As DateTime)
Label1.Text = "Child 1: Parent Event Fired (" & timestamp.ToLongTimeString() & ")"
End Sub
When you create the child form, add a handler:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim l_child1 = New ChildForm1()
AddHandler Me.EventFired, AddressOf l_child1.ParentEventFired
l_child1.Show(Me)
End Sub
You can use this approach whether you are using an MDI or simply free-floating windows.
FULL CODE
ParentForm Designer
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class ParentForm
Inherits System.Windows.Forms.Form
'Form 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.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(12, 12)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(166, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Open Child 1"
Me.Button1.UseVisualStyleBackColor = True
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(12, 41)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(166, 23)
Me.Button2.TabIndex = 0
Me.Button2.Text = "Open Child 2"
Me.Button2.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(12, 231)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(166, 23)
Me.Button3.TabIndex = 0
Me.Button3.Text = "Fire Event"
Me.Button3.UseVisualStyleBackColor = True
'
'ParentForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Name = "ParentForm"
Me.Text = "ParentForm"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
End Class
ParentForm Code Behind
Public Class ParentForm
Public Event EventFired(ByVal timestamp As DateTime)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim l_child1 = New ChildForm1()
AddHandler Me.EventFired, AddressOf l_child1.ParentEventFired
l_child1.Show(Me)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim l_child2 = New ChildForm2()
AddHandler Me.EventFired, AddressOf l_child2.ParentEventFired
l_child2.Show(Me)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
RaiseEvent EventFired(DateTime.Now)
End Sub
End Class
ChildForm1 Designer
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class ChildForm1
Inherits System.Windows.Forms.Form
'Form 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.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 9)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
'ChildForm1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Label1)
Me.Name = "ChildForm1"
Me.Text = "ChildForm1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
End Class
ChildForm1 Code Behind
Public Class ChildForm1
Public Sub ParentEventFired(ByVal timestamp As DateTime)
Label1.Text = "Child 1: Parent Event Fired (" & timestamp.ToLongTimeString() & ")"
End Sub
End Class
ChildForm2 Designer
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class ChildForm2
Inherits System.Windows.Forms.Form
'Form 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.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 9)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Label1"
'
'ChildForm2
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Label1)
Me.Name = "ChildForm2"
Me.Text = "ChildForm2"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
End Class
ChildForm2 Code Behind
Public Class ChildForm2
Public Sub ParentEventFired(ByVal timestamp As DateTime)
Label1.Text = "Child 2: Parent Event Fired (" & timestamp.ToLongTimeString() & ")"
End Sub
End Class

Inheritance works for first descendant but not next. Why?

Form1
Public Class Form1
Private Sub But_Bell_Click(sender As System.Object, e As System.EventArgs) Handles But_Bell.Click
MessageBox.Show("Ding a ling")
End Sub
End Class
First Decendant
Public Class BellsAndWhistles
Inherits Form1
Friend WithEvents But_Whistle As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.But_Whistle = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'But_Whistle
'
Me.But_Whistle.Location = New System.Drawing.Point(112, 38)
Me.But_Whistle.Name = "But_Whistle"
Me.But_Whistle.Size = New System.Drawing.Size(75, 23)
Me.But_Whistle.TabIndex = 1
Me.But_Whistle.Text = "Whistle"
Me.But_Whistle.UseVisualStyleBackColor = True
'
'BellsAndWhistles
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.But_Whistle)
Me.Name = "BellsAndWhistles"
Me.Text = "Bells & Whistles"
Me.Controls.SetChildIndex(Me.But_Whistle, 0)
Me.ResumeLayout(False)
End Sub
Private Sub But_Whistle_Click(sender As System.Object, e As System.EventArgs) Handles But_Whistle.Click
MessageBox.Show("Toot Toot")
End Sub
End Class
Second Descendant
Public Class MoreBellsAndWhistles
Inherits BellsAndWhistles
Friend WithEvents MoreBells As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.MoreBells = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'MoreBells
'
Me.MoreBells.Location = New System.Drawing.Point(30, 145)
Me.MoreBells.Name = "MoreBells"
Me.MoreBells.Size = New System.Drawing.Size(75, 23)
Me.MoreBells.TabIndex = 1
Me.MoreBells.Text = "More Bells"
Me.MoreBells.UseVisualStyleBackColor = True
'
'MoreBellsAndWhistles
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.MoreBells)
Me.Name = "MoreBellsAndWhistles"
Me.Text = "MoreBellsAndWhistles"
Me.Controls.SetChildIndex(Me.MoreBells, 0)
Me.ResumeLayout(False)
End Sub
Private Sub MoreBells_Click(sender As System.Object, e As System.EventArgs) Handles MoreBells.Click
MessageBox.Show("Ting TIng")
End Sub
Private Sub MoreBellsAndWhistles_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Where has the whistle button gone?
The class part of the inheritance has works because you can access it via code.
Try calling MyBase.InitializeComponent() from the second descendant. You'll probably have to change the access level of it, too.
EDIT
This was bugging me all night. It turns out that its a case of missing constructors. If you use reflector you'll see that Form1 has a constructor that calls Me.InitializeComponent() even though that doesn't exist in either Form1.vb or Form1.Designer.vb.
<DesignerGenerated> _
Public Class Form1
Inherits Form
' Methods
Public Sub New()
Me.InitializeComponent
End Sub
...
End Class
If you create a C# WinForms app the constructor is visible so this makes me think its a VB thing to hide it. Also, if you manually add a Sub New to Form1 it will fill in some code for you, essentially "unhiding it".
I'm guessing that VS looked at your code and realized that it was a descendant of System.Windows.Forms.Form but technically it was done improperly since it didn't call MyBase.New() (since it couldn't because it didn't exist) so it was just trying to guess. It "knows" to add a call to InitializeComponent() in the form that it created and it "knows" to do that for the form that you're looking at but it isn't bothering to walk the chain of forms and do it for all of them. Bug? Maybe.
When you set MoreBellsAndWhistles as a startup form you never see either of the new buttons, right? This is how you can tell its more of a VS trickery involved.
Anyway, the solution to the entire problem is to add this to both sub classes:
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
And add this to Form1:
Public Sub New()
InitializeComponent()
End Sub