1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
|
Public Class InteropUserControl
#Region "VB6 Interop Code"
#If COM_INTEROP_ENABLED Then
#Region "COM Registration"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "4d98c4df-113f-4b2d-a5d8-141e7167487c"
Public Const InterfaceId As String = "75232e50-1dfe-42d2-af2c-01c15c9541b5"
Public Const EventsId As String = "f91c84a5-2c50-4ff5-8e4e-1c2fcdff1499"
'These routines perform the additional COM registration needed by ActiveX controls
<EditorBrowsable(EditorBrowsableState.Never)> _
<ComRegisterFunction()> _
Private Shared Sub Register(ByVal t As Type)
ComRegistration.RegisterControl(t)
End Sub
<EditorBrowsable(EditorBrowsableState.Never)> _
<ComUnregisterFunction()> _
Private Shared Sub Unregister(ByVal t As Type)
ComRegistration.UnregisterControl(t)
End Sub
#End Region
#Region "VB6 Events"
'This section shows some examples of exposing a UserControl's events to VB6. Typically, you just
'1) Declare the event as you want it to be shown in VB6
'2) Raise the event in the appropriate UserControl event.
Public Shadows Event Click() 'Event must be marked as Shadows since .NET UserControls have the same name.
Public Event DblClick()
Private Sub InteropUserControl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
RaiseEvent Click()
End Sub
Private Sub InteropUserControl_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick
RaiseEvent DblClick()
End Sub
#End Region
#Region "VB6 Properties"
'The following are examples of how to expose typical form properties to VB6.
'You can also use these as examples on how to add additional properties.
'Must Shadow this property as it exists in Windows.Forms and is not overridable
Public Shadows Property Visible() As Boolean
Get
Return MyBase.Visible
End Get
Set(ByVal value As Boolean)
MyBase.Visible = value
End Set
End Property
Public Shadows Property Enabled() As Boolean
Get
Return MyBase.Enabled
End Get
Set(ByVal value As Boolean)
MyBase.Enabled = value
End Set
End Property
Public Shadows Property ForegroundColor() As Integer
Get
Return ActiveXControlHelpers.GetOleColorFromColor(MyBase.ForeColor)
End Get
Set(ByVal value As Integer)
MyBase.ForeColor = ActiveXControlHelpers.GetColorFromOleColor(value)
End Set
End Property
Public Shadows Property BackgroundColor() As Integer
Get
Return ActiveXControlHelpers.GetOleColorFromColor(MyBase.BackColor)
End Get
Set(ByVal value As Integer)
MyBase.BackColor = ActiveXControlHelpers.GetColorFromOleColor(value)
End Set
End Property
Public Overrides Property BackgroundImage() As System.Drawing.Image
Get
Return Nothing
End Get
Set(ByVal value As System.Drawing.Image)
If value IsNot Nothing Then
MsgBox("Setting the background image of an Interop UserControl is not supported, please use a PictureBox instead.", MsgBoxStyle.Information)
End If
MyBase.BackgroundImage = Nothing
End Set
End Property
#End Region
#Region "VB6 Methods"
Public Overrides Sub Refresh()
MyBase.Refresh()
End Sub
'Ensures that tabbing across VB6 and .NET controls works as expected
Private Sub UserControl_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
ActiveXControlHelpers.HandleFocus(Me)
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
'Raise Load event
Me.OnCreateControl()
End Sub
<SecurityPermission(SecurityAction.LinkDemand, Flags:=SecurityPermissionFlag.UnmanagedCode)> _
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_SETFOCUS As Integer = &H7
Const WM_PARENTNOTIFY As Integer = &H210
Const WM_DESTROY As Integer = &H2
Const WM_LBUTTONDOWN As Integer = &H201
Const WM_RBUTTONDOWN As Integer = &H204
If m.Msg = WM_SETFOCUS Then
'Raise Enter event
Me.OnEnter(New System.EventArgs)
ElseIf m.Msg = WM_PARENTNOTIFY AndAlso _
(m.WParam.ToInt32 = WM_LBUTTONDOWN OrElse _
m.WParam.ToInt32 = WM_RBUTTONDOWN) Then
If Not Me.ContainsFocus Then
'Raise Enter event
Me.OnEnter(New System.EventArgs)
End If
ElseIf m.Msg = WM_DESTROY AndAlso Not Me.IsDisposed AndAlso Not Me.Disposing Then
'Used to ensure that VB6 will cleanup control properly
Me.Dispose()
End If
MyBase.WndProc(m)
End Sub
'This event will hook up the necessary handlers
Private Sub InteropUserControl_ControlAdded(ByVal sender As Object, ByVal e As ControlEventArgs) Handles Me.ControlAdded
ActiveXControlHelpers.WireUpHandlers(e.Control, AddressOf ValidationHandler)
End Sub
'Ensures that the Validating and Validated events fire appropriately
Friend Sub ValidationHandler(ByVal sender As Object, ByVal e As EventArgs)
If Me.ContainsFocus Then Return
'Raise Leave event
Me.OnLeave(e)
If Me.CausesValidation Then
Dim validationArgs As New CancelEventArgs
Me.OnValidating(validationArgs)
If validationArgs.Cancel AndAlso Me.ActiveControl IsNot Nothing Then
Me.ActiveControl.Focus()
Else
'Raise Validated event
Me.OnValidated(e)
End If
End If
End Sub
#End Region
#End If
#End Region
'Please enter any new code here, below the Interop code
'ICI COMMENCE LE CODE PERSONNEL
Public Event onParam1 As EventHandler
Public Event onParam2 As EventHandler
Public Event onParam3 As EventHandler
Public Event onChaine As EventHandler
'CHARGEMENT DU CONTROLE.IL N' Y A PAS DE SUB NEW ATTENTION C'EST RESERVE
Private Sub InteropUserControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.m_param1 = 0.0
Me.m_param2 = 0.0
Me.m_param3 = 1.0
Me.rdButtonDouble.Checked = True
Me.TextBoxChaine.Text = "Concatener 2 cellules"
AddHandler Me.onParam1, AddressOf affectParam1
AddHandler Me.onParam2, AddressOf affectParam2
AddHandler Me.onParam3, AddressOf affectParam3
AddHandler Me.onChaine, AddressOf affectChaine
End Sub
'ICI FONCTION DOUBLE
Public Function CalculDouble() As Double
Dim resultatDouble As Double = 0.0
Try
resultatDouble = Double.Parse(Me.lblParam1.Text) * Double.Parse(Me.lblParam2.Text) / Double.Parse(Me.lblParam3.Text)
Catch ex As Exception
MessageBox.Show("Erreur sur donnees cellules ..." & ex.Message)
End Try
Return resultatDouble
End Function
'ICI FONCTION ENTIER
Public Function CalculInteger() As Integer
Dim resultatInteger As Integer = 0
Try
resultatInteger = CInt(Double.Parse(Me.lblParam1.Text)) * CInt(Double.Parse(Me.lblParam2.Text)) / CInt(Double.Parse(Me.lblParam3.Text))
Catch ex As Exception
MessageBox.Show("Erreur sur donnees cellules ..." & ex.Message)
End Try
Return resultatInteger
End Function
Public Sub btnCalcul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcul.Click
If Me.rdButtonDouble.Checked Then
Me.TextBoxResult.Text = Me.CalculDouble.ToString
ElseIf Me.rdButtonInteger.Checked Then
Me.TextBoxResult.Text = Me.CalculInteger.ToString
End If
End Sub
'ICI PROPRIETES
Private m_param1 As Double
Public Property Param1() As Double
Get
Return m_param1
End Get
Set(ByVal value As Double)
Try
m_param1 = Double.Parse(value)
Catch ex As Exception
MessageBox.Show("erreur sur donnees cellules ..." & ex.Message)
End Try
End Set
End Property
Private m_param2 As Double
Public Property Param2() As Double
Get
Return m_param2
End Get
Set(ByVal value As Double)
Try
m_param2 = Double.Parse(value)
Catch ex As Exception
MessageBox.Show("erreur sur donnees cellules ..." & ex.Message)
End Try
End Set
End Property
Private m_param3 As Double
Public Property Param3() As Double
Get
Return m_param3
End Get
Set(ByVal value As Double)
Try
If Double.Parse(value) <> 0.0 Then
m_param3 = Double.Parse(value)
End If
Catch ex As Exception
MessageBox.Show("Erreur sur donnees cellules ..." & ex.Message)
End Try
End Set
End Property
Private m_chaine As String
Public Property Chaine() As String
Get
Return m_chaine
End Get
Set(ByVal value As String)
m_chaine = value
End Set
End Property
Private Sub btnParam1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParam1.Click
RaiseEvent onParam1(Me, EventArgs.Empty)
End Sub
Public Sub affectParam1()
Me.lblParam1.Text = Me.Param1
End Sub
Private Sub btnParam2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParam2.Click
RaiseEvent onParam2(Me, EventArgs.Empty)
End Sub
Public Sub affectParam2()
Me.lblParam2.Text = Me.Param1
End Sub
Private Sub btnParam3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParam3.Click
RaiseEvent onParam3(Me, EventArgs.Empty)
End Sub
Public Sub affectParam3()
Me.lblParam3.Text = Me.Param3
End Sub
Private Sub btnAfficheChaine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAfficheChaine.Click
RaiseEvent onChaine(Me, EventArgs.Empty)
End Sub
Public Sub affectChaine()
Me.TextBoxChaine.Text = Me.Chaine
End Sub
End Class |
Partager