Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Form and its Load-event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kimmo Laine - 26 Sep 2007 13:44 GMT
Hi!

Is there a way to generate Load-event for form without showing it?

My problem is that if i try to set control states before Load is raised,
control states may or may not work. Here is some code:

Lets say that i have 2 form - form1 and form2. In form1 i have a button.
When this button is pressed i will display the other form:

   void button1_Click(object sender, EventArgs e) {

     Form2 f = new Form2();
     f.DoSomething();
     f.Show();

   }

In form2 i have 2 controls, button and a checkbox. If i do like this in
DoSomething-method...

   public void DoSomething() {

     button1.Visible = true;
     checkBox1.Visible = button1.Visible;

   }

...checkbox1 will be hidden! Is there a way to solve this?

tthx
-Kimmo
Ido Samuelson - 26 Sep 2007 13:53 GMT
You can do

form.Show();
form.Hide();

before the call to the DoSomething method. However it is better if you
explain more what you are doing, it looks like you have a design issue.

Best,

Ido Samuelson

> Hi!
>
[quoted text clipped - 28 lines]
> tthx
> -Kimmo
Kimmo Laine - 26 Sep 2007 14:32 GMT
Hi Ido!

Well i have several (20+) views with a custom base class. The base class
contains all kind of localiztion, security database and navigation related
virtual methods. The code which is displaying views looks something like
this

UIViewBase v = GetView(...);
// . . .
v.OnBeforeShow(...);
v.Show();
v.OnAfterShow(...);
// . . .

My problem is that if i place code in the virtual OnBeforeShow-method which
is setting control states (like the Visibility e.g.) and then im relying it,
the code doesn´t work when the view is displayed for the first time. Of
course i can code something that doesn´t use control states, lets say in
if-statements e.g., but i would rather not.

-kimmo

> You can do
>
[quoted text clipped - 40 lines]
>> tthx
>> -Kimmo
Ido Samuelson - 26 Sep 2007 14:41 GMT
The best approach (and the right way) will be to separate between your logic
and the views. You should then use binding to change how the view looks and
display data.
the second approach you can take (to make it work asap) is move the code
that is not working (aka the code that changes the user controls visibility
or something else) and move it to the following :

void Form1_VisibleChanged(object sender, EventArgs e)
       {
           if (Visible)
           {
               myControl.Visible = true;
           }
       }

> Hi Ido!
>
[quoted text clipped - 62 lines]
>>> tthx
>>> -Kimmo
Ben Voigt [C++ MVP] - 26 Sep 2007 23:32 GMT
> Hi!
>
[quoted text clipped - 25 lines]
>
> ...checkbox1 will be hidden! Is there a way to solve this?

This has nothing to do with "control states" and nothing to do with the Load
event.

The simple truth is that setting Visible sets an internal flag, but reading
Visible doesn't use the flag.  It also checks whether the parent is visible.
MSDN says Visible is "true if the control and all its parent controls are
displayed".  I can't find any public or protected member that lets you read
the internal flag.  Most likely you'll have to maintain your own list of
which controls are visible, trigger from the VisibleChanged event so that
checkBox1's Visible stays in sync with button1, or base your decision on a
property other than Visible.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.