VB.NET - Subclassing System.Windows.Forms.Form? 
Author Message
 VB.NET - Subclassing System.Windows.Forms.Form?

I have built a subclassed form for System.Windows.Forms.Form that simply overrides the OnLoad  and OnClosing functions to save the form dimensions to the registry (see code below).

Whenever I create a new form based on this subclassed form, the program will run and will save and restore correctly, but I cannot use the form designer any more.  It says something about dev,exe not recognizing the file.  My workaround is to change the Inherites back to System.Windows.Forms.Form, make changes, then set it back to my subclass.

Any ideas why this is not editable?


The SubClassed Window Code
Option Explicit On
Imports System
Imports System.Windows.Forms
Imports System.Reflection
Public Class C_PersistantForm
Inherits System.Windows.Forms.Form
#Region " Constants "
Dim REG_TOP As String = "top"
Dim REG_LEFT As String = "left"
Dim REG_WIDTH As String = "width"
Dim REG_HEIGHT As String = "height"
Dim REG_WINDOWSTATE As String = "windowstate"
Dim REG_OPACITY As String = "opacity"
Dim REG_TOPMOST As String = "topmost"
#End Region
#Region " Interface "
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
' load form into previous coordinates
Top = Application.UserAppDataRegistry.GetValue(REG_TOP, 0)
Left = Application.UserAppDataRegistry.GetValue(REG_LEFT, 0)
Width = Application.UserAppDataRegistry.GetValue(REG_WIDTH, 640)
Height = Application.UserAppDataRegistry.GetValue(REG_HEIGHT, 480)
WindowState = Application.UserAppDataRegistry.GetValue(REG_WINDOWSTATE, FormWindowState.Normal)
Opacity = Application.UserAppDataRegistry.GetValue(REG_OPACITY, 100)
TopMost = Application.UserAppDataRegistry.GetValue(REG_TOPMOST, False)
Text = Application.ProductName
End Sub
Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
' load form into previous coordinates
If WindowState = FormWindowState.Normal Then
Application.UserAppDataRegistry.SetValue(REG_TOP, Top)
Application.UserAppDataRegistry.SetValue(REG_LEFT, Left)
Application.UserAppDataRegistry.SetValue(REG_WIDTH, Width)
Application.UserAppDataRegistry.SetValue(REG_HEIGHT, Height)
End If
Dim nWindowState As Integer = WindowState
Application.UserAppDataRegistry.SetValue(REG_WINDOWSTATE, nWindowState)
Dim bTopmost As Integer = TopMost
Application.UserAppDataRegistry.SetValue(REG_TOPMOST, bTopmost)
Dim nOpacity As Integer = Opacity
Application.UserAppDataRegistry.SetValue(REG_OPACITY, nOpacity)
End Sub
#End Region
End Class
Creating a new form with the Subclass

Option Explicit On
Imports C_PersistentForm.C_PersistentForm
Public Class formMain
Inherits C_PersistentForm.C_PersistentForm

#Region " Windows Form Designer generated code "
Public Sub New()
'This call is required by the Windows Form Designer.
'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
End If
End If
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.De{*filter*}StepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
Me.Text = "formMain"
End Sub
#End Region

End Class

Fri, 17 Dec 2004 12:37:06 GMT  
 [ 1 post ] 

 Relevant Pages 

1. exception on form.show (vb.Net windows forms)

2. Deploying vb.net windows form application on a pc without the .net framework

3. Unhandled exception in system.windows.forms.dll (in my main form) - argh

4. Error in System.Windows.Forms.Form.UpdateLayered()

5. how to use the system.net.sockets and system.net in VB.net

6. Subclassing a form to get windows messages

7. VB.NET Windows form - Error Provider not blinking.

8. How to launch Internet Explorer from within VB.NET Windows Forms application

9. Plotting Graph in VB.Net and windows Form

10. vb.net windows forms ... copy from clipboard

11. Disposing VB.net Windows Forms

12. Sending email from VB.NET - Windows form


Powered by phpBB® Forum Software