473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Form and its Load-event

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
Sep 26 '07 #1
4 1659
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

"Kimmo Laine" <re******@newsgroup.onlywrote in message
news:#t*************@TK2MSFTNGP06.phx.gbl...
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
Sep 26 '07 #2
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

"Ido Samuelson" <is********@nana.co.ilwrote in message
news:A3**********************************@microsof t.com...
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

"Kimmo Laine" <re******@newsgroup.onlywrote in message
news:#t*************@TK2MSFTNGP06.phx.gbl...
>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

Sep 26 '07 #3
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;
}
}

"Kimmo Laine" <re******@newsgroup.onlywrote in message
news:OP**************@TK2MSFTNGP02.phx.gbl...
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

"Ido Samuelson" <is********@nana.co.ilwrote in message
news:A3**********************************@microsof t.com...
>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

"Kimmo Laine" <re******@newsgroup.onlywrote in message
news:#t*************@TK2MSFTNGP06.phx.gbl...
>>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

Sep 26 '07 #4

"Kimmo Laine" <re******@newsgroup.onlywrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
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?
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.
Sep 26 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Matthew Wells | last post by:
I am trying to load a form (load Me) without the form becoming visible. If I try me.hide or me.visible = false, they load the form and the form blinks before becoming invisible. Is there a way to...
1
by: Konstantin | last post by:
Can someone help me figure out a way to open a form only once in an MDI app. I have an MDI app that contains several forms. I use each form depending on the type of document that the user needs...
1
by: kyma via .NET 247 | last post by:
Hi, I haveto use VB to create a form that reads an exisiting XML fileand then allows updates via the VB form. My problem is that I was able to get VB to read a simple XML file(people.XML), but...
3
by: Chris | last post by:
Hi, I'm trying to append text from another class to a generic richTextBox that I've added to a Windows form. I can't seem to figure out how to expose the richTextBox to append text to it. ...
3
by: Eric | last post by:
I had a windows form project that had a functions module that could control objects on the referenced main form. How would I do the same with a web project using a web form? See my windows form...
13
by: Tim Smallwood | last post by:
Hi, This is probably a stupid question, but I can't seem to get a form to show / load? In the older versions of VB I'd use frmMyform.show / load myForm, etc? I looked at the help file and it...
3
by: PAPutzback | last post by:
I have a form that when it loads it fires off a second thread to load a datatable. This datatable contains a list of names and ids that the user may want to add to their criteria. So I have a...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
6
by: Ronald S. Cook | last post by:
We have a Windows app that has one main form (a shell, sort of). We then load user controls into a panel on the form depending on what the user has selected. Our current code to unload the...
13
JodiPhillips
by: JodiPhillips | last post by:
G'day, I have a silly and simple problem that I need some guidance with. Due to the way our network is set up, I am unable to use the group permissions for Access and have had to implement log...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.