Is it possible for a control to raise an event to remove itself ?
Specifically...
I have a FlowLayoutPanel that contains several instances of the same user
control.
Within each "user" control, I would like to place a buton that can remove
itself..
Please note that I want to "remove" the control as opposed to "clearing" it.
The clear does not shrink the overall panel space allocated in the
FlowLayoutPanel .
Thanks ! 8 1231
"Rob" <ro***@yahoo.co mwrote in message
news:f6******** *************** *******@comcast .com...
Is it possible for a control to raise an event to remove itself ?
Specifically...
I have a FlowLayoutPanel that contains several instances of the same user
control.
Within each "user" control, I would like to place a buton that can remove
itself..
Please note that I want to "remove" the control as opposed to "clearing"
it.
The clear does not shrink the overall panel space allocated in the
FlowLayoutPanel .
Thanks !
I would think it is ok since all you really have to do is remove the control
form the panels control collection. You don't really HAVE to get rid of the
control itself; just remove it from the collection of included controls so
it is no longer seen by the user.
My reason for thinking this...
I can program a button on a user control to clear it... and it works...
Me.Controls.Cle ar
But, it appears I cannot issue...
Me Controls.Remove
Am I missing something ?
"Ray Cassick" <rc******@enter procity.comwrot e in message
news:ez******** ******@TK2MSFTN GP06.phx.gbl...
"Rob" <ro***@yahoo.co mwrote in message
news:f6******** *************** *******@comcast .com...
>Is it possible for a control to raise an event to remove itself ?
Specifically.. .
I have a FlowLayoutPanel that contains several instances of the same user control. Within each "user" control, I would like to place a buton that can remove itself..
Please note that I want to "remove" the control as opposed to "clearing" it. The clear does not shrink the overall panel space allocated in the FlowLayoutPane l.
Thanks !
I would think it is ok since all you really have to do is remove the
control form the panels control collection. You don't really HAVE to get
rid of the control itself; just remove it from the collection of included
controls so it is no longer seen by the user.
Rob,
When I create a windows forms application and add a button to it, the
following is fine:
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Controls.Remove (Button1)
End Sub
End Class
So I think perhaps there is some other issue at play here. It would be
useful to see some code.
Robin
Hi Robin,
I see your example does work, so I just am not understanding how to do it...
Logically I would have thought the following would work, but I know it is
wrong.
Since the control is dynamically created at run time (user control within a
FlowLayoutPanel ), I do not have the option of hardcoding it as you did.
So I tried
' declare an new instance
Dim c as new control
' find out which instance of the control
c=Me.Control
' remove it
controls.remove (c)
Rob
"Robin Tucker" <rt******@remov ehotmail.comwro te in message
news:K9******** *************@g iganews.com...
>
Rob,
When I create a windows forms application and add a button to it, the
following is fine:
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Controls.Remove (Button1)
End Sub
End Class
So I think perhaps there is some other issue at play here. It would be
useful to see some code.
Robin
Also,
I would think this should work, but does not....
Controls.Remove (Me)
"Robin Tucker" <rt******@remov ehotmail.comwro te in message
news:K9******** *************@g iganews.com...
>
Rob,
When I create a windows forms application and add a button to it, the
following is fine:
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Controls.Remove (Button1)
End Sub
End Class
So I think perhaps there is some other issue at play here. It would be
useful to see some code.
Robin
Rob,
When you write Controls.Remove (Me), you are trying to remove the form
instance (more than likely) form the controls collection. "Me" isn't the
object that is the subject of the handler (the button), it is the object
that is handling the event (the form).
Presumably if you are creating the controls manually, you are assigning
handlers manually as well. Here is an example in full. Create a Windows
Forms project and add a button to it at the top called "Button1" (name it
"Add"). With the code below, whenever you click "Add", a new button will be
created and docked at the bottom of the form. A handler will also be added
so that when the new button is clicked, it removes itself from the form
controls collection.
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim newButton As New Button
newButton.Dock = DockStyle.Botto m
newButton.Text = Controls.Count. ToString
Controls.Add(ne wButton)
AddHandler newButton.Click , AddressOf AnyButton_Click
End Sub
Private Sub AnyButton_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s)
Dim theButton As Button = CType(sender, Button)
RemoveHandler theButton.Click , AddressOf AnyButton_Click
Controls.Remove (theButton)
End Sub
End Class
Robin
"Rob" <ro***@yahoo.co mwrote in message
news:bd******** *************** *******@comcast .com...
Also,
I would think this should work, but does not....
Controls.Remove (Me)
Thanks for the reply Robin,
A couple things...
I added some code to your code (see below)...
I noticed that the controls that get added by Button1 are "nameless" ???
I see that your code works very nicely... I am however, still having a
problem adapting it to my needs as my "button" is really a button within a
user control within a FlowLayoutPanel . ( I am having trouble referencing
the click event of the button within the user control.) Should it work in
this scenario as well (if I can figure it out) ?
FYI - As I add each new user control to the FlowLayoutPanel , I do give it
a name, that is why I was hoping somehow to use the name as the "primary
key" to remove the control.
Thanks,
Rob
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim newButton As New Button
newButton.Dock = DockStyle.Botto m
newButton.Text = Controls.Count. ToString
Controls.Add(ne wButton)
AddHandler newButton.Click , AddressOf AnyButton_Click
' ADDED********** **********
Dim i As Integer = 0
Dim str As String
While i < Me.Controls.Cou nt
Dim c As Control = Me.Controls(i)
str = c.Name
MsgBox(str)
i = i + 1
End While
' *************** *************** **
End Sub
"Robin Tucker" <rt******@remov ehotmail.comwro te in message
news:Q9******** *************@g iganews.com...
Rob,
When you write Controls.Remove (Me), you are trying to remove the form
instance (more than likely) form the controls collection. "Me" isn't the
object that is the subject of the handler (the button), it is the object
that is handling the event (the form).
Presumably if you are creating the controls manually, you are assigning
handlers manually as well. Here is an example in full. Create a Windows
Forms project and add a button to it at the top called "Button1" (name it
"Add"). With the code below, whenever you click "Add", a new button will
be created and docked at the bottom of the form. A handler will also be
added so that when the new button is clicked, it removes itself from the
form controls collection.
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim newButton As New Button
newButton.Dock = DockStyle.Botto m
newButton.Text = Controls.Count. ToString
Controls.Add(ne wButton)
AddHandler newButton.Click , AddressOf AnyButton_Click
End Sub
Private Sub AnyButton_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s)
Dim theButton As Button = CType(sender, Button)
RemoveHandler theButton.Click , AddressOf AnyButton_Click
Controls.Remove (theButton)
End Sub
End Class
Robin
"Rob" <ro***@yahoo.co mwrote in message
news:bd******** *************** *******@comcast .com...
>Also,
I would think this should work, but does not....
Controls.Remov e(Me)
Hi Robin,
I think it is finally working.... 40 hours later...
Your reply made me think about what "Me" was...
To refresh...
Button on main form adds a "user control" to a FlowLayoutPanel
The "user control" contains a Button (Button2) that if clicked, the desired
action is to remove the entire user control from the FlowLayoutPanel
The solution that appears to work now...
Controls.Remove (Button2.Parent )
Dispose()
Thanks again for your help !
"Robin Tucker" <rt******@remov ehotmail.comwro te in message
news:Q9******** *************@g iganews.com...
Rob,
When you write Controls.Remove (Me), you are trying to remove the form
instance (more than likely) form the controls collection. "Me" isn't the
object that is the subject of the handler (the button), it is the object
that is handling the event (the form).
Presumably if you are creating the controls manually, you are assigning
handlers manually as well. Here is an example in full. Create a Windows
Forms project and add a button to it at the top called "Button1" (name it
"Add"). With the code below, whenever you click "Add", a new button will
be created and docked at the bottom of the form. A handler will also be
added so that when the new button is clicked, it removes itself from the
form controls collection.
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim newButton As New Button
newButton.Dock = DockStyle.Botto m
newButton.Text = Controls.Count. ToString
Controls.Add(ne wButton)
AddHandler newButton.Click , AddressOf AnyButton_Click
End Sub
Private Sub AnyButton_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s)
Dim theButton As Button = CType(sender, Button)
RemoveHandler theButton.Click , AddressOf AnyButton_Click
Controls.Remove (theButton)
End Sub
End Class
Robin
"Rob" <ro***@yahoo.co mwrote in message
news:bd******** *************** *******@comcast .com...
>Also,
I would think this should work, but does not....
Controls.Remov e(Me) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bruce Rusk |
last post by:
I'm using Stephen Lebans' RTF2 control in a report, and have discovered what
may be a slight bug in it.
I have a lot of non-Western language (Chinese) text in my RTF field, and
such records get sized strangely using the .RTFHeight property of the
control. Specifically, lines of text get cut off the bottom of the control
when I use the code provided in the sample report on the lebans.com site. It
seems that when there is Chinese text,...
|
by: martin |
last post by:
Hi,
I am a web page and a web user control. My web user control is placed in my
web page using the following directive
<%@ Register TagPrefix="uc1" TagName="Header" Src="WebControls/Header.ascx"
%>
The web user control contains the following server controls
|
by: John Lau |
last post by:
Hi,
Is there documentation that talks about the page lifecycle, the lifecycle of
controls on the page, and the rendering of inline code, in a single
document?
Thanks,
John
|
by: Guadala Harry |
last post by:
In an ASCX, I have a Literal control into which I inject a
at runtime.
litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID);
This works great as long as the contains just client-side
HTML, CSS, etc.
What I want to do is somehow insert a *server control* into the , then set the server control's properties at runtime.
|
by: serge calderara |
last post by:
Dear all,
I am new in asp.net and prepare myself for exam
I still have dificulties to understand the difference between server control
and HTML control.
Okey things whcih are clear are the fact that for server control component ,
code is running on the server side.
But if I take as example a Label. I place on a webform an HTM label control
and a WebForm label control, I could see that properties are different for
| |
by: Mike |
last post by:
Hi,
I am strugling with a simple problem which I can't seem to resolve.
I have an asp.net page which contains a server-control (flytreeview,
which is a kind
of a tree to be exact).
The tree is being updated by some other process through remoting.
When the page loads, I init the tree, and in my browser I can see the
initialized tree.
The problem is that every time that I receive update to tree from the
remote process,
|
by: gsb58 |
last post by:
Hi!
On a form I have a calendar. The form is rezised to 1024x768 (Don't
worry - this is a training case) when loaded.
Now I want to center the calendar on the form so that its edges are
equally far from the upper, right, left and bottom borders of the form.
I understand I must use the location property, am I right?
|
by: paul.hester |
last post by:
Hi all,
I have a custom control with an overridden Render method. Inside this
method I'm rendering each control in its collection using their
RenderControl method. However, I'm running into a problem in this
scenario:
<myprefix:mycontrol runat="server">
<%= SomeVariable %>
</myprefix:mycontrol>
|
by: rizwanahmed24 |
last post by:
Hello
i have made a custom control. i have placed a panel on it. I want this
panel to behave just like the normal panel. The problem i was having is
that the panel on my custom control doesnt accept other controls. The
control i drag drop on it becomes the child of my custom control's
parent form and not the child of my custom control. Then i added this
line
""
before my custom control class (i dont know what this line does). Now
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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...
|
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
| |