Say you have a custom control which has a PictureBox. And you drop this control on a form. But you want to be able to Code the MouseDown, MouseMove, MouseUp and Paint event of the PictureBox control that is on your custom control, and you want to code those events in the Form, not the control You still with me? You also don't want to create another control that inherits from your custom control to do this. How can you do this?
There are actually a number of ways to do this. Below are three ways:
1. The easiest way to do this is to just raise an event in the Custom Control and handle that event in the Form.
Public Event LinkClicked(ByVal sender As Object, ByVal e As EventArgs)
Private Sub LinkLabel1_LinkClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
RaiseEvent LinkClicked(sender, e)
End Sub
2. Another way is to have a PictureBox value in the form point to the PictureBox that is on the control. And then address the Mouse events there. You'll need a way to return the Control to you via a FindControl routine in your Custom Control
Public Function FindControl(ByVal Name As String) As Control
For Each c As Control In Me.Controls
If c.Name.ToLower = Name.ToLower Then
Return c
End If
Next
End Function
Then in your Form you would do the following:
WithEvents MyFullImage As PictureBox
And in your Form_Load event:
MyFullImage = ImgEditor1.FindControl("FullImage") 'This is assuming the FullImage is the name of the Picturebox in your Control
And then you can do the following:
Private Sub MyFullImage_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyFullImage.MouseDown
End Sub
3. Lastly you would still use the FindControl mentioned in method 2, but do the following
'Add this to form_load
Dim pctBox as PictureBox = MyUserControl1.FindControl("FullImage")
AddHandler pctBox.Click, AddressOf TestClick
Private Sub TestClick(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox("Testing AddHandler Method")
End Sub
Monday, December 29, 2008
Wednesday, December 24, 2008
Referenced DLL kept getting deleted in vb.net project
I had a VB.NET project which referenced a specific DLL that came from another source (I didn't have the code just the dll file). I added the dll to my project by browsing to the dll. The problem occurred when I tried to rebuild the project. All of a sudden I got a reference not found, and when I went to the directory where the dll was located it was no longer there. The solution was simple one. When adding the dll, in the Reference Properties window, you need to specify the "Specific Version" field to "True" instead of the default which is "False". By doing this you don't delete the dll.
Tuesday, December 23, 2008
Passing an array of Structures with an array to unmanaged code from VB.NET
I had an array of structures and in the structure was an array. There were a couple of issues. The first thing was that I couldn't initialize the array while defining the structure (still haven't figured this one out yet). The second thing was that when I passed the array to unmanaged code byref and when the unmanaged dll returned I would get an error.
What ended up fixing my problem was that in my structure was a Boolean variable. When I changed that Boolean to Integer then all of a sudden everything worked.
I'll post code samples shortly.
What ended up fixing my problem was that in my structure was a Boolean variable. When I changed that Boolean to Integer then all of a sudden everything worked.
I'll post code samples shortly.
Wednesday, December 10, 2008
Stop the Windows Authentication in Firefox
Whenever I have to go to the know or to timecard or to a teamsite, I get this dialog box which prompts me to enter a username and password in firefox. I don't get this in IE. The fix in firefox is this:
1. Open Firefox
2. Navigate to the url about:config
3. Locate the following preference names and put as the value the comma separated values of the address roots.
network.automatic-ntlm-auth.trusted-uris
network.negotiate-auth.delegation-uris
network.negotiate-auth.trusted-uris
Your value should look something like this: localhost,companyname.org
Subscribe to:
Posts (Atom)