Hi,
If I want to pass a form (forms I have created) to a
function what would I set the declaration as
for example
Dim p as existingForm
OpenForm (p, existingForm)
Function (P as windows.forms.f orm, thisForm as *******)
p=NEW thisForm
.....
What do I put in *******? 10 4320
as ExistingForm. If I'm reading this right, you don't even need to pass the
P.
"Sebastian Santacroce" <se******@ilogi c.com> wrote in message
news:82******** *************** *****@phx.gbl.. . Hi, If I want to pass a form (forms I have created) to a function what would I set the declaration as
for example
Dim p as existingForm OpenForm (p, existingForm)
Function (P as windows.forms.f orm, thisForm as *******) p=NEW thisForm ....
What do I put in *******?
Dim p as existingForm
OpenForm(p)
Function(ByRef theForm as existingForm)
End Function
"Sebastian Santacroce" <se******@ilogi c.com> wrote in message
news:82******** *************** *****@phx.gbl.. . Hi, If I want to pass a form (forms I have created) to a function what would I set the declaration as
for example
Dim p as existingForm OpenForm (p, existingForm)
Function (P as windows.forms.f orm, thisForm as *******) p=NEW thisForm ....
What do I put in *******?
Sebastian Santacroce wrote: Hi, If I want to pass a form (forms I have created) to a function what would I set the declaration as
for example
Dim p as existingForm OpenForm (p, existingForm)
Function (P as windows.forms.f orm, thisForm as *******) p=NEW thisForm ....
What do I put in *******?
If I read this right, you want to have a function that create an instance of
a type, without knowing a priori exactly what that type will be. Because
..Net doesn't have generics (yet), the only way to do this is using
reflection. Note that the example below will be slower than just using 'p =
new existingForm'.
First, I'd think the design of your program through to decide if you
*really* need this. But if you must do it, this is how:
Imports System.Reflecti on
Public Sub OpenForm(ByVal p As Windows.Forms.F orm, ByVal thisForm As Type)
Dim ci As ConstructorInfo = thisForm.GetCon structor(Type.E mptyTypes)
p = ci.Invoke(Nothi ng)
' do something with p.
End Sub
Dim p As existingForm
OpenForm(p, Type.GetType("Y ourNamespace.ex istingForm"))
Again, only do this if you have absolutely no alternative. It is ugly code,
hell to maintain, not very performant, and not type-safe.
--
Sven Groot http://unforgiven.bloghorn.com
* "Sebastian Santacroce" <se******@ilogi c.com> scripsit: If I want to pass a form (forms I have created) to a function what would I set the declaration as
for example
Dim p as existingForm OpenForm (p, existingForm)
Function (P as windows.forms.f orm, thisForm as *******) p=NEW thisForm ....
What do I put in *******?
I am not sure what you want to do, but maybe you are looking for this:
\\\
Private Function CreateClassByNa me( _
ByVal PartialAssembly Name As String, _
ByVal QualifiedClassN ame As String _
) As Object
Return _
Activator.Creat eInstance( _
[Assembly].LoadWithPartia lName( _
PartialAssembly Name _
).GetType(Quali fiedClassName) _
)
End Function
///
Usage:
\\\
Dim c As Control = _
DirectCast( _
CreateClassByNa me( _
"System.Windows .Forms", _
"System.Windows .Forms.Button" _
), _
Control _
)
With c
.Location = New Point(10, 10)
.Size = New Size(80, 26)
.Text = "Hello World"
End With
Me.Controls.Add (c)
///
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
This is exactly what I was looking for but its not
working.
The
Type.GetType("Y ourNamespace.ex istingForm")
is returning "Nothing".
What would I put under "YourNamespace" ?
would one always exist.
This solution has only one project and I haven't created
any namespaces but the form is in a solution folder.
Is there something I'm missing?
Thanks. -----Original Message----- Sebastian Santacroce wrote: Hi, If I want to pass a form (forms I have created) to a function what would I set the declaration as
for example
Dim p as existingForm OpenForm (p, existingForm)
Function (P as windows.forms.f orm, thisForm as *******) p=NEW thisForm ....
What do I put in *******? If I read this right, you want to have a function that
create an instance ofa type, without knowing a priori exactly what that type
will be. Because..Net doesn't have generics (yet), the only way to do
this is usingreflection. Note that the example below will be slower
than just using 'p =new existingForm'.
First, I'd think the design of your program through to
decide if you*really* need this. But if you must do it, this is how:
Imports System.Reflecti on
Public Sub OpenForm(ByVal p As Windows.Forms.F orm, ByVal
thisForm As Type) Dim ci As ConstructorInfo = thisForm.GetCon structor
(Type.EmptyType s) p = ci.Invoke(Nothi ng) ' do something with p. End Sub
Dim p As existingForm OpenForm(p, Type.GetType("Y ourNamespace.ex istingForm"))
Again, only do this if you have absolutely no
alternative. It is ugly code,hell to maintain, not very performant, and not type-safe.
-- Sven Groot
http://unforgiven.bloghorn.com
.
"Sebastian Santacroce" <se*******@ilog ic.com> schrieb This is exactly what I was looking for but its not working. The Type.GetType("Y ourNamespace.ex istingForm")
is returning "Nothing". What would I put under "YourNamespace" ? would one always exist. This solution has only one project and I haven't created any namespaces but the form is in a solution folder. Is there something I'm missing?
Open the class view or the object browser.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Sebastian Santacroce wrote: This is exactly what I was looking for but its not working. The Type.GetType("Y ourNamespace.ex istingForm")
is returning "Nothing". What would I put under "YourNamespace" ? would one always exist.
The default root namespace for a VB.NET project is always the project name,
unless specified otherwise in the project properties.
--
Sven Groot http://unforgiven.bloghorn.com
Sven Groot wrote: Public Sub OpenForm(ByVal p As Windows.Forms.F orm, ByVal thisForm As Type)
Upon re-reading, it occurred to me you probably want the form instance to be
accessible through the passed first parameter once OpenForm has returned. In
which case you should put:
Public Sub OpenForm(ByRef p As Windows.Forms.F orm, ByVal thisForm As Type)
Note the ByRef instead of ByVal for the first parameter.
--
Sven Groot http://unforgiven.bloghorn.com
So that worked great now.
I need to check if the form has been closed ie, the
variable has been disposed so I can recreate the form.
How would I check if the variable is disposed? -----Original Message----- Sebastian Santacroce wrote: This is exactly what I was looking for but its not working. The Type.GetType("Y ourNamespace.ex istingForm")
is returning "Nothing". What would I put under "YourNamespace" ? would one always exist. The default root namespace for a VB.NET project is always
the project name,unless specified otherwise in the project properties.
-- Sven Groot
http://unforgiven.bloghorn.com
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: domeceo |
last post by:
can anyone tell me why I cannot pass values in a setTimeout function
whenever I use this function it says "menu is undefined" after th
alert.
function imgOff(menu, num) {
if (document.images) {
document.images.src = eval("mt" +menu+ ".src")
}
alert("imgOff_hidemenu");
hideMenu=setTimeout('Hide(menu,num)',500);
|
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of code...
TCHAR myArray;
DoStuff(myArray);
|
by: Mark Anderson |
last post by:
I have code to develop result page links (like a search engine) for some
results being passed from a database where I've no server-sdide acces -
thus JS.
The code is below and works fine except the function in the onClick
event of the link being written on screen fails indicating 'theForm' as
being passed through is 'not defined'. The form is being passed as
"document.resultAdd" and can be checked as arriving in my function.
So what...
|
by: Mike MacSween |
last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime
ago.
Then remembered that arguments are passed by reference, by default.
Does the fact that this slowed me down indicate:
a) That I don't know enough
b) Passing arguments by ref is bad
|
by: Max |
last post by:
Last time I tried to explain this on another forum it didn't go too
well, so I'll try my best and if you know what I'm talking about then
please tell me how to do this.
I have a class, inside I have some public functions and private
variables. Inside the class I also have a declaration of a new form
object. One of the functions of the class takes that form object, shows
it with showdialog and the basically passes the control to the form...
| |
by: ged |
last post by:
Hi,
i am a oo (c#) programmer, and have not used javascript for a while and
i cant work out how javascript manages its references. Object
References work for simple stuff, but once i have an object collection
and stanrd using it it starts to fall apart.
Clearly there is something about javascript's usage of passing "By ref"
that i am not getting. i have had a look on the web and found some
examples, but i cant see why my code does not...
|
by: Deano |
last post by:
Apparently you can only do this with one value i.e Call
MyAssetLocationZoom(Me!txtLocation, "Amend data")
This runs;
Public Sub MyAssetLocationZoom(ctl As Control, formName As String)
On Error GoTo err_zoom
strFormName = formName
|
by: Andrew Bullock |
last post by:
Hi,
I have two classes, A and B,
B takes an A as an argument in its constructor:
A a1 = new A();
B b = new B(a1);
|
by: mark.e.nelson |
last post by:
Hi,
I am trying to pass a pointer to a struct to a function that uses the
data in the struct, and also happens to use ncurses. I always get a
segmentation violation when the program exits. I have experimented
with passing a pointer to a struct as an argument to a function that
does not use ncurses and that seems to work fine.
Can anyone provide any advice? I apologise if this is the wrong place
to ask - I am just coming back to C...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |