|
|
||||||
|
#1
|
|
|
|
|
Hi all,
I got a problem: I have a Panel control which has many mixed child controls (buttons, checkboxes, comoboxes). All controls are visible (the parent container Panel is also visible). My problem is that when I set the Visible property of the Panel to false and try to read the Visible property of any of its child control, the result is always false??? How can I get the original value of the Visible property of any child control?? I'd appreciate your prompt reply, Thanks a lot .. Veszko /****************************/ Panel pnl = new Panel(); .. .. .. pnl.Visible = true; Button btn = new Button(); .. .. .. btn.Visible = true; pnl.Controls.Add(btn); .. .. .. MessageBox.Show(pnl.Visible.ToString()); // The result is "True" MessageBox.Show(btn.Visible.ToString()); // The result is "True" pnl.Visible = false; MessageBox.Show(pnl.Visible.ToString()); // The result is "False" MessageBox.Show(btn.Visible.ToString()); // The result is "False" ... which is not OK!!! // I need to know the original value of "btn.Visible" /****************************/ |
|
|
|
#2
|
|
|
|
|
since the panel is the parent, anything that happens with it's
visiblity will be pushed down to the children. You really don't want to mess with that behavior at all. However, there is something you can do to keep the last state of the visibility of the control. Override the Visible property in each of your child controls with private bool _LastVisibility; public new bool Visible { get { return base.Visible; } set { _LastVisibility = value; base.Visible = value; } } public bool LastVisibility { get { return _LastVisibility; } } that will allow you to save the last visible state that any given control was set to. You can get that last state by checking your new 'LastVisibility' property. Allen Anderson http://www.glacialcomponents.com mailto: allen@put my website url here.com On Fri, 18 Jun 2004 15:54:18 +0200, "Wesam" <public_2000> wrote: [..] |
|
#3
|
|
|
|
|
Thanks Allen for your reply, unfortunately, this is not a practical solution
because this is a general problem in all our software programs and somehow I have to fix ... Overriding each control's Visible property takes a long time and makes very difficult to modify the program in the future, could you help? May thanks, Veszko "Allen Anderson" <allen> wrote in message news:sq7j [..] |
|
#4
|
|
|
|
|
Use reflection and call the internal method GetState
passing the parameter STATE_VISIBLE (0x2) /claes "Wesam" <public_2000> wrote in message news:3988 [..] |
|
#5
|
|
|
|
|
Dear Claes!
Thank you for your reply, but could you provide me with some simple source code? unfortunately I was unable to both "GetState" & "STATE_VISIBLE" in MSDN ... Your solution seems to be interesting! I'd appreciate your help, Veszko "Claes Bergefall" <claes.bergefall> wrote in message news:2928 [..] |
|
#6
|
|
|
|
|
Public Function CallMethod(ByVal name As String, ByVal o As Object, ByVal
ParamArray params() As Object) As Object Dim objectType As Type = o.GetType Dim flags As BindingFlags = BindingFlags.Instance Or _ BindingFlags.Static Or _ BindingFlags.NonPublic Or _ BindingFlags.Public Dim methodInfo As methodInfo Dim param As Object Dim types(params.Length - 1) As Type Dim index As Integer For index = 0 To params.Length - 1 types(index) = params(index).GetType Next While Not objectType Is Nothing methodInfo = objectType.GetMethod(name, flags, Nothing, types, Nothing) If methodInfo Is Nothing Then objectType = objectType.BaseType Else Exit While End If End While If methodInfo Is Nothing Then Throw New MissingMemberException(o.GetType.FullName, name) Else Return methodInfo.Invoke(o, params) End If End Function Call like this: Dim visible As Boolean = CBool(CallMethod("GetState", myLabel, 2)) /claes "Wesam" <public_2000> wrote in message news:3336 [..] |
|
#7
|
|
|
|
|
Dear Claes,
Thanks for your help, but unfortunately I wan unable to use the code you put here for two reasons: I can understand C# code, and because for some reason the code is not complete or so ... my VB.NET reported many errors (syntax) and I could not use it?? Could you help me please! Thank you for all your help, Wesam "Claes Bergefall" <claes.bergefall> wrote in message news:2928 [..] |
|
#8
|
|
|
|
|
I think you are going to have a hard time doing that without
intercepting the call that hides or dispalys the child controls. See, the problem is that the controls really ARE being set to hidden. When the parent is not displayed, it calls the hide on the children as well. So where as you think you are trying to get to some value under the hood where things have their old value, I don't believe there is such a thing. When a parent is no longer displayed, it iterates the children and hides them too. At least that is my understanding of how the framework works. Allen Anderson http://www.glacialcomponents.com mailto: allen@put my website url here.com On Mon, 21 Jun 2004 09:28:23 +0200, "Wesam" <public_2000> wrote: [..] |
|
#9
|
|
|
|
|
Dear Allen,
Thanks for your reply, however, I disagree with you! 100% the parent's "Visible" or "Hide()" does not call similar methods on the children because it somehow maintains the original state of each control! For instance, in my previous example the child controls are hidden when the parent is hidden (although some of them could originally be visible or hidden) but when you set the parent's "Visible" to true, fortunately (and this what makes me believe is it possible) all child control are set back to their original "Visible" value which -in turn- makes clear that the each control -somehow- ALWAYS RETURNS FALSE if the parent's "Visible" is false!! And thus when the parent's "Visible" is true, then the real value of the child control is RETURNED I think something like that happens, and I feel that there's a way to solve this ... but I don't know how? do you have any ideas? Thanks, Veszko "Allen Anderson" <allen> wrote in message news:c5u0 > I think you are going to have a hard time doing that without > intercepting the call that hides or dispalys the child controls. See, > the problem is that the controls really ARE being set to hidden. When > the parent is not displayed, it calls the hide on the children as > well. So where as you think you are trying to get to some value under > the hood where things have their old value, I don't believe there is > such a thing. When a parent is no longer displayed, it iterates the > children and hides them too. At least that is my understanding of how > the framework works. > > Allen Anderson > [..] > mailto: allen@put my website url here.com > > On Mon, 21 Jun 2004 09:28:23 +0200, "Wesam" <public_2000> > wrote: > solution > >because this is a general problem in all our software programs and somehow I [..] |
|
#10
|
|
|
|
|
??? The code I posted is in VB.NET!
You're probably missing an Imports System.Reflection statement /claes "Wesam" <public_2000> wrote in message news:2176 [..] |
|
#11
|
|
|
|
|
I am not missing the "System.Reflection" .. I did include it into the
program, however, the complier did not report Imports missing or something like this, it said there syntax errors and invalid casting and stuff like that. I did a Copy/Paste the code you provided AS-IS into a new VB.NET project (because I did not learn VB that much I did not change anything, I just added the missing Reflection namespace) and that's why I could not figure out the reason. Could you help me? Many thanks, Veszko "Claes Bergefall" <claes.bergefall> wrote in message news:3512 [..] |
|
#12
|
|
|
|
|
Copying/pasting the code AS-IS works just fine
You do know that the news-client adds line-breaks on long lines, right? What errors are you getting? /claes "Wesam" <public_2000> wrote in message news:4064 [..] |
|
#13
|
|
|
|
|
Dear Claes!
I so sorry for the inconvenience, my Visual Basic is corrupted and that's why nothing worked :-(( Your example works very very well, I tried it on my colleague's machine and it good. However, I would ask you some final question (if you allow me): Can you convert this code somehow to C#??? Now I have a working VS.NET (VB & C#) but I am mainly a C# programmer and I have to use your code in my program and I am not sure I can do that, could you help me? If not possible could just give general guides of how all this is working fine? I really appreciate your valuable help, Thanks, Veszko "Claes Bergefall" <claes.bergefall> wrote in message news:1048 [..] |
|
#14
|
|
|
|
|
Dear Claes,
I managed to convert the code to C#, thanks to you, however, I have a question: how did you know that there's a "GetState()" method and there's a parameters for it which "2"?? I could not find information about this issue nowhere? would you provide me with info please! Many thanks in advance, Veszko "Wesam" <public_2000> wrote in message news:3972 [..] |
|
#15
|
|
|
|
|
I looked at the source code for the framework :-)
Download .NET Reflector and do the same: http://www.aisto.com/roeder/dotnet/ (it's at the top) /claes "Wesam" <public_2000> wrote in message news:a808 [..] |
|
|
| Similar Threads | |
| How to ensure "child" ascx control loads before parent Load Hi, I have a .ascx control which holds company information which can be edited. One of the controls inside this is an Address control. The address control has country and... |
|
| Implement "visible" property for composite control (for Igor) Igor, I saw your post from a few years back where you responded to someone asking how to implment the concept of visible with this statement: > You are not supposed to... |
|
| Implement "visible" property for composite control. Hi, I am designing a composite control and I want to provide the property "visible" on the control. The intention is to make the control visible / invisible at run time... |
|
| The "Visible" property of a parent control ruins that one of its child controls Hi all, I got a problem: I have a Panel control which has many mixed child controls (buttons, checkboxes, comoboxes). All controls are visible (the parent container Panel is... |
|
| Is there a way to make an ASP.Net control invisible other than the "visible" property? I have some controls that I want to be invisible, but if the user does something, they will become visible using javascript. So I can't set its "visible" property to false,... |
|
|
All times are GMT. The time now is 07:56 AM. | Privacy Policy
|