SuspendLayout & ResumeLayout

B

Brent McIntyre

Good afternoon all,

I am having a little problem using the SuspendLayout & ResumeLayout
functions from a module.

This is the Delegate Declaration in the module:

Public Delegate Sub Delegate_Layout()
Public Delegate_Form_Layout() As Delegate_Layout = _
{ _
AddressOf Form_SuspendLayout, _
AddressOf Form_ResumeLayout _
}

This is the code from the main form:

Public Sub Form_SuspendLayout()
Me.SuspendLayout()
End Sub

Public Sub Form_ResumeLayout()
Me.ResumeLayout()
End Sub

Unfortunately the AddressOf Form_SuspendLayout and AddressOf
Form_ResumeLayout return errors saying that they are not declared.

I tried running the commands straight from the module:

form_main.activeform.suspendlayout

But it returned the following error:

An unhandled exception of type 'System.NullReferenceException' occurred
in Questionnaire - Employment Consultant.exe

Additional information: Object reference not set to an instance of an
object.

Anyhelp that anyone could provide to make this work would be much
appreciated, I really need to run these commands from multiple modules,
not just the Form_Main.VB where they run fine.

Yours sincerely,

Brent McIntyre
 
A

Armin Zingler

Brent McIntyre said:
Good afternoon all,

I am having a little problem using the SuspendLayout &
ResumeLayout functions from a module.

This is the Delegate Declaration in the module:

Public Delegate Sub Delegate_Layout()
Public Delegate_Form_Layout() As Delegate_Layout = _
{ _
AddressOf Form_SuspendLayout, _
AddressOf Form_ResumeLayout _
}

This is the code from the main form:

Public Sub Form_SuspendLayout()
Me.SuspendLayout()
End Sub

Public Sub Form_ResumeLayout()
Me.ResumeLayout()
End Sub

Unfortunately the AddressOf Form_SuspendLayout and AddressOf
Form_ResumeLayout return errors saying that they are not declared.

I tried running the commands straight from the module:

form_main.activeform.suspendlayout

Is Form_main the Form displayed? If it is: I think that form_main does not
contain another Form, consequently ActiveForm is Nothing (=> error).

But it returned the following error:

An unhandled exception of type 'System.NullReferenceException'
occurred in Questionnaire - Employment Consultant.exe

Additional information: Object reference not set to an instance of
an object.

<default answer>
If you want to access an object you need a reference. If you don't have a
reference you have to make it available. Where when and how depends on the
strcuture of your application.
</default answer>
 
A

Armin Zingler

Armin Zingler said:
Is Form_main the Form displayed? If it is: I think that form_main
does not contain another Form, consequently ActiveForm is Nothing (=>
error).

I wrote garbage, sorry. ActiveForm is a shared property (MSFT, please make
it (optionally) unavailable with object references!!!). Writing
form_main.activeform
is actually writing
System.Windows.Forms.Form.activeform
 
B

Brent McIntyre

Armin,

Thanks for you help, just to follow up though. The form 'Form_Main'
does not contain or link to any other forms, but the default for
accessing Suspend/Resume Layout is 'Form.ActiveForm.SuspendLayout()' so
I can not do it another way, can I ? I may be missing something, I
usually do. Secondly, I have fully referenced (Once again I may be
missing something) as seen in the previous description, but it still
will not work, I am thinking that you may not be able to use this type
of method through delegates, once again I am not sure.

Thanks for your help, if you have any further feedback it would be
greatly appreciated.

Yours sincerely,

Brent McIntyre
 
B

Brent McIntyre

Armin,

I am going crazy over this problem, any further help you may be able to
provide would be much appreciated.

If I try to use a delegate ie:

Module Code

Public Delegate Sub Delegate_Layout()
Public Delegate_Layout_Selection() As Delegate_Layout = _
{ _
AddressOf Update_Negative, _
AddressOf Update_Positive _
}

Form_Main.vb Code

Public Sub Update_Negative()

'Me.SuspendLayout()

End Sub

Public Sub Update_Positive()

'Me.ResumeLayout()

End Sub

then it can't find Update_Negative/Positive unless they are on another
Module. Does this mean I am not referencing the Form_Main.vb properley
?

If I try to put them in to an array loaded from a module, ie

Form_Main.vb Code

Load_001(me.suspendlayout, _
me.resumelayout)

Module Code

Public Update_Array(1) as control

Public Sub Load_001(ByVal Update_Negative as Control, _
ByVal Update_Positive as Control)

update_array(0) = Update_Negative
update_array(1) = Update_Positive

End Sub

then it can't understand the load_001 part as there seems to be a
problem with calling it a Control even though that is what Help tells me
it is, this is really driving me crazy it is the last part of a project
I need to do, without it the program looks terrible as it updates nearly
two hundred panels.

Any help you may be able to provide would be much appreciated.

Yours sincerely,

Brent McIntyre
 
A

Armin Zingler

Brent McIntyre said:
[...]

Any help you may be able to provide would be much appreciated.

Sorry, I read the whole post but I can not follow you. Why do you need a
module at all?
 
C

Chris Dunaway

AddressOf Update_Negative, _
AddressOf Update_Positive _

How does the AddressOf know where to find the methods? Would it be more
appropriate to use:

AddressOf Form_Main.Update_Negative, _
AddressOf Form_Main.Update_Positive

Where Form_Main is an instance of the form in question?

I'm not sure what you are attempting to accomplish, though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top