Event Hook During Construction - Use Withevents If There Is No Benefit?

May 12, 2011

I must say personally, the WithEvents system is, shall we say, open to extreme false sense of security, so to speak. I like a lot of automation in my code, and tend to provide ways to do things manually, with a "default" behavior encoded. However, as I have just discovered, the withevents doesn't HOOK the event delegate until after creation. So even when you do New MyObject(), if an event is triggered during the Sub New() process, the delegate hasn't been assigned yet, and thus the event (which in my current situation is extremely important) never triggers. which begs the question the point of the WithEvents other than removing "AddHandler" lines from procedural code. Sure it saves on typing, due to code completion, but if that's it, that isn't much of a benefit. One would think that using the WithEvents would allow me to do:

PUblic Sub New()
MyBase.New()
RaiseEvent MyEvent()
End Sub

Tragically, this does NOT work, which royally screws up my lazy loading techniques and other such tricks that were supposed to make my code simpler to use, and instead has made things 10 times more complex, as I have to specifically alter class initialization sequences to be outside of class instantiation. (which should be one in the same, imho).Jaeden "Sifo Dyas" al'Raec Ruiner

"Never Trust a computer. Your brain is smarter than any micro-chip."

PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.

View 2 Replies


ADVERTISEMENT

Hook Into Scroll Event?

Dec 4, 2009

I have an app where I need to hook into a particular control's horizontal scroll event. I'm not real experienced in hooking into Windows events.

View 1 Replies

Hook Up An Event To Another Event?

Nov 10, 2009

Is it possible to hook up an event to another event in VB8?I have this code in C#...

public event ShowAboutDialog = delegate {};
private void hookupEvents() {
myButton.Click += ShowAboutDialog;
}

And am trying to convert it into VB8, but can't get it to work..

Public Event ShowAboutDialog As EventHandler
Private Sub HookupEvents()
AddHandler AboutMenuItem.Click, AddressOf ShowAboutDialog
End Sub

View 1 Replies

What The Benefit For Clean Selection In .net

Feb 18, 2009

What the benefit for Clean Selection in vb.net

View 2 Replies

Forms :: Get Benefit From A Listbox In A Detailsview With A Many-to-many Relationship?

Oct 29, 2009

I'm trying to design a detailsView form which contains [classes] --< [studentClasses] >-- [students] tables. There is a many to many relationship between [classes] and [students] through the third table [studentClasses]. I want to design the detailsView of [classes] such as that all [students] will be listed in a listbox but related students that take the class will be highlighted. And when I select/deselect students from the listbox and save I want the changes to be saved to respective tables.

View 2 Replies

VS 2008 Error "WithEvents Variable 'Move' Conflicts With Event 'Move' In The Base Class 'Control' And Should Be Declared Shadows"

Sep 3, 2010

What does this error mean? I havent modified anything in the designer code, but its giving me an error? WithEvents variable 'Move' conflicts with event 'Move' in the base class 'Control' and should be declared 'Shadows'. The error relates to Friend WithEvents Move As System.Windows.Forms.DataGridViewCheckBoxColumn

View 1 Replies

Benefit Of Isolating Win32 API Functions In A Single Module - Syntax And X32/x64 Compatibility

May 13, 2012

In developing a Windows Forms application (VS2010/VB) with several dozen classes and modules, I seem to have incorporated a variety of Win32 API function variations throughout my application, some of which seem to be duplicative/redundant. For improved code

[Code]....

View 5 Replies

Construction - Inherit A Class That Also Has A Constructor

Mar 15, 2010

i'm working with different classes and different constructors. It's working fine until i try to inherit a class that also has a constructor. vb asks for mybase.new but when i add that vb says that a constructor cannot call itself, when i try it in a different way vb asks the parameters of the constructor of the class that i want to inherit.

View 11 Replies

SerialPort DataReceived Buffer Construction?

Jun 15, 2011

I've managed to make an application at home using a serialport emulator and connector that will read text from a file on my desktop send it to com1 and then my connector program will merge com1 with com2. In short my program works at home but when I connect it to my device it appears the data in DataReceived is a fraction of what my simulator setup at home is producing, which apparently is completely normal according to all these threads I've read here.

[Code]...

View 4 Replies

VS 2005 XML Or .TXT To Store Class Construction?

Jan 18, 2010

I have an Object(Class) that consists of a few List Of(T)'s where T is other classes that can be defined by reading lines of a CSV file.I could (I imagine) do the same thing with XML.My question is when does one choose between the two.Are there cases where one is preferred over the other for data storage?

View 3 Replies

VS 2008 Referred To Itself During Construction From A Default Instance?

Jan 3, 2011

I desperately need someones help on this one, as I'm completely stumped where this error comes from.

System.InvalidOperationException was unhandled Message="An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'" Source="Training Database"

[Code]...

View 6 Replies

Iterate Through Controls Using Dynamic Construction Of Control Names?

Jan 29, 2009

I need to iterate through controls using dynamic construction of control names and it looks like this could be what I need, however I never used this before and it does not quite work. What am I doing wrong? GroupBox1 is what I am attempting

Dim x as Integer = 1 For Each ctrl As Control In CallByName(Me, "GroupBox" & CStr(x), CallType.Method).Controls The runtime error is "GroupBox1" not found on Form1 even though I can select Me.GroupBox1 from the dropdown list.

View 14 Replies

Process Of Developing A Construction Estimating Program With Vb 2008?

Apr 29, 2009

I'm in the process of developing a construction estimating program with vb 2008. Most of the programming I'm able to work myself through, but the problem and question that I have is I would like to incorporate a part of the program where I can import pdf, jpegs, tiffs of blueprints and have the ability to then set the scale, take area and length calculations, and basically do quantity takeoffs.

View 8 Replies

Basic Array Construction - One Column Or Entry Would Be A Single Integer

Oct 27, 2009

How you might construct an array like the following: one column or entry would be a single integer, like 0, 1, 2, 3, 4... - i need this as an index of each one's position in the list the second would be 0 or 1, or true or false the third would itself be a list of integers 0,4,5,2,7,2,5,2...

So all together one entry would be {0; 0; 0,4,5,2,7,2,5,2} while the next might be {1; 0; 6,8,2,5,2,3}

I'm having a terrible time wrapping my head around this. It's mostly the third column which is actually a list in itself, that is giving me trouble

View 13 Replies

Error - The Form Referred To Itself During Construction From A Default Instance, Which Led To Infinite Recursion

Apr 14, 2010

I have two forms. A main form and then another form that you can change settings in. Now when I click on the menu item to get to the settings form I get this error. "An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'"I've tried these codes.

frmSettings.Show()
Application.Run(frmSettings)

those didn't work so i tried these

dim settings as new form = frmSettings
settings.show()
dim settings as form

[code]....

and those didn't work. I'm using visual studio 2010 Pro.

View 6 Replies

VS 2010 How To 2nd Hook

May 30, 2011

almost perfectly works to disable specific keys. but 1problem. for example : checkbox1 checked and then press button1 L win key disable its okey.but then i press button2 to active keys and press again button1.this time not working disabling keys.

[Code]...

View 1 Replies

.net - Friend WithEvents In VB Vs Private In C#

Dec 17, 2009

Who knows, why in vb.net WinForm projects the designer by default use the Friend WithEvents attributes and in C# - private ones.

By ex, in a form.designer.

.cs

private Label Label1;

.vb

Friend WithEvents Label1 as Label;

For WithEvents is more or less clear(for using Handles, apparently). But why Friend in VB and private in C#...

View 4 Replies

Adding The Withevents Variable?

Jul 11, 2011

i have the folowing co

For x = 0 To 7 Step 1
For i = 0 To 7 Step 1
Dim rectangleShape1 As New Microsoft.VisualBasic.PowerPacks.RectangleShape() 'create a new object to assign to the array location
board(x, i) = New Microsoft.VisualBasic.PowerPacks.RectangleShape() 'create the new object in the array

[code].....

View 2 Replies

Clarification For WithEvents Handlers

Feb 11, 2010

When you declare an object 'WithEvents' and then utilize the "Handles" clause at the end of your event methods, how does Visual Basic manage a reference change for the object? In other words, if the withevents var is set to ObjectA, then later I switch it to ObjectB (or nothing), does Visual Basic automatically both remove those handler methods from ObjectA, and attach them to ObjectB? Or do I still have a ObjectA's events being handled behind the scenes?

I ask this because if instead you use AddHandler for an object, and then switch your reference, unless you removed the handler before switching, your original object is still handled (at least I'm pretty sure that's how it works).

View 13 Replies

Events - .NET: WithEvents Not Working?

Apr 21, 2010

I have the following classes: Public Class Email

[Code]...

If a create a wrong email lets say "email" the exception is correctly cached and a message is showed however is i input a valid email the event is not raised, the object is being created but no message is shown and no error or exception is thrown i suspect it has something to do with using "myemail = new Email(email)" but i have seen examples of using new with withevents with no problem.

View 2 Replies

Local Variable / WithEvents

May 17, 2010

Does anyone know why a local variable cannot be declared WithEvents?T

View 3 Replies

Multiple ChildForms With WithEvents?

Jun 9, 2011

I'm trying to create multiple instances of a child form. This form has an event that feeds a string variable back to the parent so I'm declaring it with WithEvents which is declared outside of the Sub - meaning multiple clicks will not open multiple forms.

another method of doing this while keeping the event?:

Dim WithEvents FRestoreDB As New FormRestoreDB()
Private Sub BtnOpenDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOpenDB.Click

[Code].....

View 2 Replies

Set To Nothing(in Dispose()) All WithEvents Fields?

Feb 24, 2010

Is it necessary to set to Nothing(in Dispose()) all WithEvents fields?

Apparently Handles keyword adds handlers to such fields, but does not remove it until this field is not Nothing, and this can generate memory leaks?!.

This should be specially actual on cases like

class Foo
{
Private WithEvents _bar as Bar

[Code].....

View 1 Replies

VS 2005 Experiencing WithEvents?

Feb 24, 2010

Protected WithEvents gel As New TabPage

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TabControl1.TabPages.Add(gel)
gel.Text = ("Gel")

Private Sub Gel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gel.Click
MsgBox("test") So my problem is that if I click on the tabpage gel, nothing happens.

View 15 Replies

VS 2010 Threading WithEvents?

Sep 7, 2011

I have an application that performs a lot of busy work. All of the work is performed using a BackgroundWorker and the point of execution is the DoWork Event of the BackgroundWorker.On the UI thread, before the workload begins, I display a PictureBox that contains an animated GIF that illustrates progress; for the most part this works fine and the UI thread is not paused or slowed while the BackgroundWorker does its job. There is however, one instance where the UI thread is impacted by the work being done and it defeats the whole purpose of putting this work in a separate thread. In this application, the user must wait until the work completes before they can move to the next step, so my sole reason for moving this all to a BackgroundWorker was so that I could display a smooth, uninterrupted progress indicator on the UI thread while this work was being done, so that the user could see that something was happening.

The case where the work being done is impacting the UI thread (pausing/delaying the PictureBox animation) deals with a referenced COM object.

[Code]...

All of the COM object event handlers and subsequent functions are appropriately using Delegates, but I am not sure why the ProcessFiles method would cause the UI thread to hang while the work completes; I thought that was the whole purpose of the BackgroundWorker.

View 6 Replies

WithEvents For Array Of Objects?

Dec 14, 2010

I'd like to create an array of objects with events. Where do I need to put the "WithEvents"? Should it be placed in the ReDim line or the next one?I'm trying to use a "global" event, like objects of people that recieve a time-event to get older.

[Code]...

View 18 Replies

Hook For Process Start?

Feb 10, 2010

Is there any way I can install a global hook or something else on the start of external process. WH_CBT hook, as it appears can only intercept events for processes that have windows, but what if I want to intercept the start/stop of a windowless application or a windows service? Is there any way to do it using .NET?Generally, I want my application to receive a notification of some process being launched knowing only an executable name.Presently I simply use a timer to iterate through running processes, but I wonder if there a better way to do it?

View 4 Replies

Hook Keyboard With Program?

Jul 14, 2011

I want to hook keyboard with vb , so that whenever my application written in vb runs it will capture all the keys pressed from the keyboard and show all the keys being pressed in a textbox on window's form

View 1 Replies

Low Level Mouse Hook In VB

Aug 4, 2011

I want to hook low level Mouse hook in vb, and after that I want to save the X-axis, Y-axis and clicks(Right/Left) into database for later use or automation..But I don't understand that how should I save the X-axis, Y-axis and clicks into a MS SQL databse and later retrieve them?

View 2 Replies

Low-level Keyboard Hook

Dec 18, 2009

I'm writing a code to use it in a keyboard spy program , and I'm using hook techneque with this , but the problem is that : if I ForExamle clicked on Shift and number 2 it doesn't give me At (@), I want it to give me at (@) ..

[Code]....

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved