Click here to Skip to main content
15,930,792 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Open a form when the name is known only on runtime Pin
satc4-Jun-15 9:57
satc4-Jun-15 9:57 
GeneralRe: Open a form when the name is known only on runtime Pin
Sascha Lefèvre4-Jun-15 10:41
professionalSascha Lefèvre4-Jun-15 10:41 
GeneralRe: Open a form when the name is known only on runtime Pin
satc4-Jun-15 18:26
satc4-Jun-15 18:26 
GeneralRe: Open a form when the name is known only on runtime Pin
Sascha Lefèvre4-Jun-15 18:42
professionalSascha Lefèvre4-Jun-15 18:42 
GeneralRe: Open a form when the name is known only on runtime Pin
satc4-Jun-15 19:44
satc4-Jun-15 19:44 
GeneralRe: Open a form when the name is known only on runtime Pin
Sascha Lefèvre4-Jun-15 19:56
professionalSascha Lefèvre4-Jun-15 19:56 
GeneralRe: Open a form when the name is known only on runtime Pin
satc4-Jun-15 20:10
satc4-Jun-15 20:10 
GeneralRe: Open a form when the name is known only on runtime Pin
Sascha Lefèvre4-Jun-15 21:17
professionalSascha Lefèvre4-Jun-15 21:17 
Suggested solution: A custom base class for your forms:
VB
Imports System.Reflection
Imports System.Windows.Forms

Public Class MyBaseForm
    Inherits Form

    Public Function IsControlEnabled(controlMemberName As String) As Boolean
        Dim control As Object = Me.GetType().GetProperty(controlMemberName, BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public).GetValue(Me, Nothing)
        Return CBool(GetType(Control).GetProperty("Enabled").GetValue(control, Nothing))
    End Function
End Class

In case you already have a custom base class for your forms you can just copy that method in there.

In the previously posted code you have to change accordingly from Form to MyBaseForm:
VB
Dim form As MyBaseForm = DirectCast(Activator.CreateInstance(formType), MyBaseForm)

And then you can simply call form.IsControlEnabled("MyControlName") to get the value of the Enabled-property of the control with the specified member-name.

edit: Don't know why I didn't think of that in the first place - it would make sense to implement it as an extension method for the Form-class instead.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson


modified 5-Jun-15 3:36am.

Questionvb.net 2010 desktop application add listbox Pin
dcof3-Jun-15 7:16
dcof3-Jun-15 7:16 
AnswerRe: vb.net 2010 desktop application add listbox Pin
Mycroft Holmes3-Jun-15 14:06
professionalMycroft Holmes3-Jun-15 14:06 
QuestionThe shortest way to do this ? Pin
satc2-Jun-15 13:35
satc2-Jun-15 13:35 
GeneralRe: The shortest way to do this ? Pin
PIEBALDconsult2-Jun-15 14:45
mvePIEBALDconsult2-Jun-15 14:45 
GeneralRe: The shortest way to do this ? Pin
Mycroft Holmes2-Jun-15 15:36
professionalMycroft Holmes2-Jun-15 15:36 
GeneralRe: The shortest way to do this ? Pin
PIEBALDconsult2-Jun-15 15:49
mvePIEBALDconsult2-Jun-15 15:49 
GeneralRe: The shortest way to do this ? Pin
satc2-Jun-15 15:58
satc2-Jun-15 15:58 
GeneralRe: The shortest way to do this ? Pin
PIEBALDconsult2-Jun-15 16:07
mvePIEBALDconsult2-Jun-15 16:07 
GeneralRe: The shortest way to do this ? Pin
satc2-Jun-15 16:11
satc2-Jun-15 16:11 
GeneralRe: The shortest way to do this ? Pin
PIEBALDconsult2-Jun-15 18:07
mvePIEBALDconsult2-Jun-15 18:07 
GeneralRe: The shortest way to do this ? Pin
Mycroft Holmes2-Jun-15 20:38
professionalMycroft Holmes2-Jun-15 20:38 
GeneralRe: The shortest way to do this ? Pin
PIEBALDconsult3-Jun-15 12:39
mvePIEBALDconsult3-Jun-15 12:39 
GeneralRe: The shortest way to do this ? Pin
Richard Deeming2-Jun-15 22:11
mveRichard Deeming2-Jun-15 22:11 
GeneralRe: The shortest way to do this ? Pin
satc2-Jun-15 23:35
satc2-Jun-15 23:35 
GeneralRe: The shortest way to do this ? Pin
Richard Deeming3-Jun-15 0:20
mveRichard Deeming3-Jun-15 0:20 
QuestionI can't solve following coding~~~ Pin
Wathon Aung2-Jun-15 1:24
Wathon Aung2-Jun-15 1:24 
AnswerRe: I can't solve following coding~~~ Pin
Chris Quinn2-Jun-15 2:24
Chris Quinn2-Jun-15 2:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.