473,788 Members | 2,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(o bject 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.Visib le = button1.Visible ;

}

....checkbox1 will be hidden! Is there a way to solve this?
tthx
-Kimmo
Sep 26 '07 #1
4 1671
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******@newsg roup.onlywrote in message
news:#t******** *****@TK2MSFTNG P06.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(o bject 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.Visib le = 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********@nan a.co.ilwrote in message
news:A3******** *************** ***********@mic rosoft.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******@newsg roup.onlywrote in message
news:#t******** *****@TK2MSFTNG P06.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(o bject 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.Visib le = 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_VisibleCh anged(object sender, EventArgs e)
{
if (Visible)
{
myControl.Visib le = true;
}
}

"Kimmo Laine" <re******@newsg roup.onlywrote in message
news:OP******** ******@TK2MSFTN GP02.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********@nan a.co.ilwrote in message
news:A3******** *************** ***********@mic rosoft.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******@newsg roup.onlywrote in message
news:#t******* ******@TK2MSFTN GP06.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(o bject 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.Visib le = button1.Visible ;

}

...checkbox 1 will be hidden! Is there a way to solve this?
tthx
-Kimmo

Sep 26 '07 #4

"Kimmo Laine" <re******@newsg roup.onlywrote in message
news:%2******** *******@TK2MSFT NGP06.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(o bject 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.Visib le = 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
17073
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 load the form without it becoming visible at all until I say me.visible = true? Thanks. Matthew Wells MWells@NumberCruncher.com
1
462
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 to see, i.e. for documents of type A, I use form A, for type B, form B, etc. Each document has a unique number. I need the app to only show one document at a time, i.e. ifthe user tries to open doc. 1 of type A, then open form A and load doc 1....
1
2397
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 I'm having problems figuring out how to get VBto read a more complex XML file (people2.xml) and then useadditional text boxes on the same form to add more familymembers. Each family can have from 1 to 5 members. I've pasted the working code below...
3
14164
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. Thanks in advance, Chris
3
1677
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 example, and let me know what I must do to get this to work on a web form. Imports System.Data Imports System.Data.OleDb Imports CrystalDecisions.CrystalReports.Engine Imports System.Windows.Forms Module ProcessFunctions
13
36696
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 showed me how to create a new form in code and then load it, but I want to load a form when a user clicks a button.. and hide the form that currently has focus..? I can't seem to find this simple task in the help file.. Any help would be greatly...
3
1660
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 button that once the thread completes it beccomes enabled and the datable gets bound to a listbox that shows up on the new form. But there is a delay, which I am guessing is when the listbox is preparing to paint itself with the bound data. Is...
6
2883
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 and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the data table. The lookup
6
4727
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 existing user control and load the newly selected one is pretty bulky. Every time we add a new user control to the project, we have to add some code in the section where we are loading/unloading. Is there a more dynamic, more efficient way to...
13
3254
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 in procedures via a log in table within the database. This works fine. I have now expanded this table to include further data about the authorised user – Power User, Team Leader, & Facilitator. Depending on the user’s status as to which one of...
0
9656
marktang
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...
0
9498
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,...
0
10366
Oralloy
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...
1
10112
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
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();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
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
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.