Well, I have managed to create controls during runtime.

        Dim Rbut As New Button()
        Dim Lbut As New Button()
        With Rbut
                    .Location = New Point(590, y + 15)
                    .Text = "Remove"
                    .Name = FontName(ListBoxCount)
        End With
        With Lbut
                    .Location = New Point(590, y + 45)
                    .Text = "Lock"
                    .Name = FontName(ListBoxCount)
        End With
                Me.Panel1.Controls.Add(Rbut)
                Me.Panel1.Controls.Add(Lbut)
                AddHandler Rbut.Click, AddressOf RemButton_Click
                AddHandler Lbut.Click, AddressOf LocButton_Click

    Private Sub RemButton_Click(ByVal Sender As Object, ByVal e As System.EventArgs)
        ListBox1.Items.Remove(Sender.Name)
    End Sub

    Private Sub LocButton_Click(ByVal Sender As Object, ByVal e As System.EventArgs)
        ListBox1.SelectedItem = Sender.Name
    End Sub

Here Rbut is Remove Button and Lbut is Lock Button. Both are created during runtime and there are maximum 10 buttons with different name from the array [FontName(ListBoxCount)]. Now, Am wondering how to disable RButton on pressing LButton.

I used RemButton_click.sender.enabled=false but in vain. Just a code snippet will make it for me. Thanks!

cobj("name of the control").enabled = False

fine.. my problem is now what is the name of the control? During runtime, it carries the name of the font selected, but in coding, if it is in same sub-routine, its sender.name but i want to call from another sub-routine..

Rbut.Enabled = False

Just make sure that Rbut has the proper scope (ie don't declare it in the sub that creates it)

Public Class Form1

    Public Rbut As Button
    Public Lbut As Button

    etc.

Uff.. I tried but couldn't.. it does nothing when declared as public. When i tried

sender.name.enabled=false 

it just disables the lock button and not remove button.

You said you wanted to disable it, not remove it. If you want it to disappear I suggest you use the "Visible" property. This will effectively remove it from the form but leave it available in case you want to restore it. If you really want to remove it then

Me.Controls.Remove(Rbut)

will do it

Oh I think you misunderstood my language. Actually "Remove" and "Lock" are the names of the button. When I press "Remove" Button, the "Lock" Button is to be disabled. Both are created during runtime. There are more than 5 similar such buttons as pair.

Then do what I suggested and declare the Button variables at the class level and use Rbut.Enabled = False and it should work. I do it frequently.

Thanks, but I tried it, all the Rbut buttons are disabled rather than particular one. Better have a look at this so you will understand,

http://sourceforge.net/projects/cpsfontviewer/

In the software, the second window- on pressing filter window, my problem exists there! Hope you can help me out.

Try the following code

Public Class Form1

    Dim Lbut(2) As Button
    Dim Rbut(2) As Button

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Dim row As Integer = 0

        For y As Integer = 13 To 113 Step 50
            Lbut(row) = MakeButton(13, y, 75, 23, row, "Left")
            Rbut(row) = MakeButton(93, y, 75, 23, row, "Right")
            row += 1
        Next

    End Sub

    Private Function MakeButton(x As Integer, y As Integer, w As Integer, h As Integer, row As Integer, text As String) As Button

        Dim btn As New Button
        btn.Size = New Size(w, h)
        btn.Location = New Point(x, y)
        btn.Text = text
        btn.Tag = row

        AddHandler btn.Click, AddressOf Button_Click

        Me.Controls.Add(btn)

        Return btn

    End Function

    Private Sub Button_Click(sender As System.Object, e As System.EventArgs)

        Dim btn As Button = sender
        Dim row As Integer = btn.Tag

        If btn.Text = "Left" Then
            Rbut(row).Enabled = Not Rbut(row).Enabled
        End If

    End Sub

End Class

Thanks for your reply with a most needed code! Am just working on the idea you have given for me, will post and reply you once I find the exact one. Thanks for the code, this gives me an idea.

Glad to be of help. Please remember to mark this thread as solved if it works out for you.

sure.. Your help was most needed one..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.