473,788 Members | 2,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How add unknown control at runtime

Hi,

How i can add one new unknown control at runtime in my form1?

Thaks.
Nov 20 '05 #1
22 1882
I want create a control where i only have your type into a string.
Example:
c = "System.Windows .Forms.TextBox"

How can i do?
"José Teixeira Junior" <te************ *@stinfo.com.br > escreveu na mensagem
news:O0******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

How i can add one new unknown control at runtime in my form1?

Thaks.

Nov 20 '05 #2
Hi José, Morpheu,

Jose, I don't know how 'unknown' your control is but this may answer your
query. If not, tell me more about what you want to do.

Morpheu, the following will create a Control given a name such a "Button".

Public Function MakeControl (sTypeName As String) As Control
Dim sFormTypeName As String = GetType (Form).Assembly QualifiedName
sTypeName = sFormTypeName.R eplace ("Form,", sTypeName & ",")
Dim oType As Type = Type.GetType (sTypeName)
Return DirectCast (Activator.Crea teInstance (oType), Control)
End Function

This was given in answer to a similar query a week ago. For an explanation
of how it works, see
http://tinyurl.com/r393

Regards,
Fergus
Nov 20 '05 #3
* "José Teixeira Junior" <te************ *@stinfo.com.br > scripsit:
How i can add one new unknown control at runtime in my form1?


Please don't multipost.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Maybe you should put a bit of error checking in, You are using DirectCast,
but you aren't sure whether the user has specified a type derived from
control:

Replace:
Return DirectCast (Activator.Crea teInstance (oType), Control)
With:

' ///
Dim oObj As Object = Activator.Creat eInstance(oType )

If TypeOf oObj Is Control Then
Return DirectCast(oObj , Control)
Else
oObj = Nothing
Return Nothing
End If
' ///

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflecti on Master "

==== Converting to 2002 ====
Remove inline declarations
"Fergus Cooney" <fi******@tesco .net> wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl... Hi José, Morpheu,

Jose, I don't know how 'unknown' your control is but this may answer your query. If not, tell me more about what you want to do.

Morpheu, the following will create a Control given a name such a "Button".
Public Function MakeControl (sTypeName As String) As Control
Dim sFormTypeName As String = GetType (Form).Assembly QualifiedName
sTypeName = sFormTypeName.R eplace ("Form,", sTypeName & ",")
Dim oType As Type = Type.GetType (sTypeName)
Return DirectCast (Activator.Crea teInstance (oType), Control)
End Function

This was given in answer to a similar query a week ago. For an explanation of how it works, see
http://tinyurl.com/r393

Regards,
Fergus

Nov 20 '05 #5
Hi Tom,

What shall I do when I've trapped the error?

Regards,
Fergus
Nov 20 '05 #6
Hi again,

Oops, window too small - missed the bit below.

If I return Nothing, the caller is going to have to check whether the
Control is Nothing instead of trapping an Exception. I think it's preferable
to throw the Exception (especially as it is done for me). This is a more
violent way to bring the error to the caller's attention, true, but I think it
is preferable.

Regards,
Fergus


Nov 20 '05 #7
Hi Herfried,

Multipost? - did I miss the other one?

Regards,
Fergus
Nov 20 '05 #8
Hi Fergus,

Thank you for its help.
It worked as wanted.

Regards,
Morpheu
"Fergus Cooney" <fi******@tesco .net> escreveu na mensagem
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
Hi José, Morpheu,

Jose, I don't know how 'unknown' your control is but this may answer your query. If not, tell me more about what you want to do.

Morpheu, the following will create a Control given a name such a "Button".
Public Function MakeControl (sTypeName As String) As Control
Dim sFormTypeName As String = GetType (Form).Assembly QualifiedName
sTypeName = sFormTypeName.R eplace ("Form,", sTypeName & ",")
Dim oType As Type = Type.GetType (sTypeName)
Return DirectCast (Activator.Crea teInstance (oType), Control)
End Function

This was given in answer to a similar query a week ago. For an explanation of how it works, see
http://tinyurl.com/r393

Regards,
Fergus

Nov 20 '05 #9
Hi yet again Tom,

Third thoughts.

oType = GetType (SomeCrap) is likely to fail too. Before you know it the
whole thing is a mass of error handling and while it may be 'proper', it could
frighten off many a punter becaue it looks so horrendously complicated. That's
the tightrope we walk - give 'em something which will get them on their way,
or give 'em the full works which they might well reject despite it being
'perfect'. ;-)

Regards,
Fergus
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2823
by: Ivan Debono | last post by:
Hi, I keep getting an Unknown runtime error on line 3 below: 1 If oField.Type <> 136 Then 'adChapter 2 If Right(oField.name, 3) = "_id" Then 3 For Each oKey In oTable.Keys 4 If oKey.Type = 2 Then 'adKeyForeign 5 Set oCol = oKey.Columns(0)
7
509
by: José Teixeira Junior | last post by:
I need add one new unknown control at runtime and the only one information that i have is one string with type of control. Example: c = "System.Windows.Forms.TextBox" How i can create one textbox at runtime in my form1?
5
3096
by: TT (Tom Tempelaere) | last post by:
Hi, Once in a while my application throws an NullReferenceException at startup, however it appears to be occurring in an unknown module. If I debug it and ask to 'break', then there is no source code available (I am running in Debug mode of course). What could be the cause of this? Can someone shed some light on this matter? Kind regards,
5
20448
by: Lars-Erik Aabech | last post by:
Hi! Guess it's my day again.. Tried to deploy a test release of a new asp.net web today, and got a terrible error. The web is running swell on three development computers, but when it's copied to the test server it won't work at all. Looks like aspnet_wp is trying to compile it for five seconds, then it stops working what so ever. The system event log gets the following entry: Application popup: aspnet_wp.exe - Application Error : The...
6
1153
by: Morpheu | last post by:
Hello, I have other problem with the unknown control added at runtime: When i use a mdiformchild, the control don't appear. In a normal form, it works. Somebody? Thank you in advance. Morpheu
4
1688
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of Arraylists, meaning, I don't know how many I should create until runtime. I will be reading a table, and 0,1,2, or more fields have to be put into individual ArrayLists. How do I create an unknown number of ArrayLists? Right now I put all the values into one ArrayList. I know how many fields are in the ArrayList so I then know that every one, or every other one, or
7
38027
by: John | last post by:
Hi Everyone, I'm having this extremely annoying problem with Internet Explorer 6, giving me an error message saying "unknown runtime error" whenever I try to alter the contents of a <divelement using innerHTML. Now, I've researched this problem on the web, and found many references to it, but none of them quite addressed my specific situation, and since my experience with JavaScript is limited, I was not able to adapt the solutions I...
21
2130
by: sheldonlg | last post by:
I have googled for '"Internet Explorer" "Unknown runtime error"' and not found anything useful. I have the following (for simplicity of presentation here): <div><table><tr><th id="foo"></th></tr></table></div> In my javascript I have two lines: var titleObj = document.getElementById('foo'); titleObj.innerHTML = "Name is bar";
2
1463
by: comalco2000 | last post by:
If I place objects (i.e. image box controls containing graphics) onto a form at random during runtime, how can I then detect a button_down mouse event when I hover over one of those new controls if I don't have specific object_mousedown routines for those objects in my code? Is there a way of detecting which control a cursor is over and then passing this through to a "control-independent" mousemove subroutine, which could then be used to drag...
0
9498
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,...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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,...
0
9967
tracyyun
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...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
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();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.