here is my code. I am somewhat of a newbie to VB.net but have done alot of
programming in FoxPro.
Imports System.Text
<Serializable()> Public Class BaseControl
Inherits System.Windows.Forms.UserControl
Private lFirstRun As Boolean
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
Dim ctl As Object, myForm As System.Windows.Forms.Form
'This call is required by the Windows Form Designer.
InitializeComponent()
lFirstRun = True
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl 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
'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()
'
'BaseControl
'
Me.Name = "BaseControl"
End Sub
#End Region
Private Declare Ansi Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As
String, ByVal _
lpKeyName As String, ByVal lpDefault As String, ByVal
lpReturnedString As _
StringBuilder, ByVal nSize As Int32, ByVal lpFileName As String)
As Int32
Private Declare Ansi Function WritePrivateProfileString _
Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Integer
Private m_ioValue As Boolean, m_IO As Short, m_ioMaster As IOMaster,
m_ioObject As IO
Protected Const INIFILE = "HMI.ini"
#Region "Properties"
Public Property IOValue() As Boolean
Get
IOValue = m_ioValue
End Get
Set(ByVal Value As Boolean)
Value = m_ioValue
End Set
End Property
Public Property IO() As Short
Get
IO = m_IO
End Get
Set(ByVal Value As Short)
m_IO = Value
addHandlerEvent()
End Set
End Property
Public Property IOMaster() As IOMaster
Get
IOMaster = m_ioMaster
End Get
Set(ByVal Value As IOMaster)
m_ioMaster = Value
addHandlerEvent()
End Set
End Property
#End Region
#Region "Subs and Functions"
Private Sub addHandlerEvent()
'remove the old handler if there is one
If Not m_ioObject Is Nothing Then
RemoveHandler m_ioObject.IOChange, AddressOf Me.ChangeIOValue
End If
If Not m_ioMaster Is Nothing And m_IO > 0 Then
m_ioObject = m_ioMaster.IOObject(m_IO)
If Not m_ioObject Is Nothing Then
'bind the changeIovalue sub to the event IOChange of the io
object
AddHandler m_ioObject.IOChange, AddressOf Me.ChangeIOValue
Else
'MsgBox("ioobject is nothing")
End If
Else
'MsgBox("iomaster is nothing " & m_IO.ToString)
End If
End Sub
Private Sub ChangeIOValue()
'The io Value changed so update the data and raise the IOChange
Event
m_ioValue = m_ioObject.IOValue
RaiseEvent IOChange()
End Sub
Protected Overridable Sub GetIO()
Dim RetVal As StringBuilder, X As Integer
RetVal = New StringBuilder(255)
X = GetPrivateProfileString("IO", Me.Name, "", RetVal, 255, CurDir()
& "\" & INIFILE)
If X > 0 Then
Me.IO = Val(RetVal.ToString)
Else
WritePrivateProfileString("IO", Me.Name, "0", CurDir() & "\" &
INIFILE)
End If
End Sub
#End Region
Public Event IOChange()
Private Sub BaseControl_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If lFirstRun Then
lFirstRun = False
GetIO()
End If
End Sub
End Class
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
Altman, When are the values that I set in design mode available?
At run time, the values you set at design time are available when you set
them, hence you need to do "something" with them in the Property Set
procedures. HOWEVER! the "do "something"" is the tricky part, for example
in a Color property the Property Set procedure may save the color value,
and then call Invalidate on the control, allowing the Paint event to
repaint the control in the new color...
Also remember that you can actually set the values at any time you want...
What are you wanting to do with them at Load time? Specifically.
Hope this helps
Jay
"Altman" <No******@SickOfSpam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...I guess that what I am noticing is that any property that I set in the
design mode does not show up with the correct value in the load event. I
have changed other properties in design mode and I noticed that at the
load event, these values are not there. When are the values that I set in
design mode available?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl... "Altman" <No******@SickOfSpam.com> schrieb:
Ok I have a control that is inherited from another class.
In the child I put msgbox(me.name) in the load event. What
always pops up is the name of the parent class and not the
name of the instance of the object.
The name of the parent class is the same as the name of your class,
because your object is an instance of its base class too. 'Name' is
inherited, not duplicated.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>