473,320 Members | 1,859 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,320 software developers and data experts.

about Show Method in Control Class under System.Windows.Forms (C#)

Hi,

my function: myAdjustForm.Show();

I am using the Show method to show the pop-up window to the users
in my C# program.

I found that I have invoke this function TWICE at the beginning before I can
see the pop-up window poping up.

Do you know how I can fix it? Is it related to missing initialization
routines?

Thanks.

Best regards,

Albert

Feb 9 '07 #1
10 2413
Hi Albert,

When you call myAdjustForm.Show(), does your process own the foreground
window? If you do, then the issue is quite strange indeed, would you please
give me some code so that I can try to reproduce the issue on my side?

If the foreground window doesn't belong to your process, then calling
myAdjustForm.Show() will NOT bring it to foreground on win2000/xp, this is
because by default windows will prevent applications from stealing focus,
it will flash the taskbar button instead. In this case, calling Show()
twice will also not solve the issue; therfore it might not be the case
either. (For this issue, you will have to use SetForegroundWindow along
with AttachThreadInput as a workaround, search for these two APIs and you
will much information about it)

If you do post the code, please let me know which .NET version you're
using. Thanks.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 9 '07 #2
Albert,

This is a strange problem that have never happened to me. Can you post
simple compilable sample that demonstrates the problem.
--
Stoitcho Goutsev (100)

"Albert Fu" <ko**@community.nospamwrote in message
news:93**********************************@microsof t.com...
Hi,

my function: myAdjustForm.Show();

I am using the Show method to show the pop-up window to the users
in my C# program.

I found that I have invoke this function TWICE at the beginning before I
can
see the pop-up window poping up.

Do you know how I can fix it? Is it related to missing initialization
routines?

Thanks.

Best regards,

Albert

Feb 9 '07 #3
Hi,

Thank you for all the replies.

I am using MS VS 2005 (MS Visual C# 2005 77626-009-0000007-41501).

I included the function that I have in my program at the end of my email. I
set a breakpoint inside this function in the debugger. The debugger stops
inside the function when I select to display the pop-up windows.
(myAdjustForm.Visible is false in this case).

Here is my obeservation:
1) 1st time
The program stops at another function in another form after I stepped over
myAdjustForm.Show(). There is no pop-up window showing up.
2) 2nd time
The program stops at myAdjustForm.BringToFront() after I stepped over
myAdjustForm.Show(). The pop-up window shows up as I expected.
3) The pop-up window shows up every time after the second time.

I think this could be a C# compiler bug since I don't understand why the
execution sequence of my program will change after the first time. I tried to
uncheck the optimize code box in the build page but this problem is still
there. So I am not sure that the same problem will show up in a simplified
version of my program if this is compiler related problems.

Do you have any ideas how to change the behavior of the compiler so that it
will generate the code that reflects the program flow?

Best regards,

Albert

************************************************** ****
private void menuItemAdjust_Click(object sender, EventArgs e)
{
if (myAdjustForm.Visible == true)
myAdjustForm.Hide();
else
{
myAdjustForm.Show();
myAdjustForm.BringToFront();
}
}
************************************************** ***
Feb 9 '07 #4
Hi Albert,

Thank you for your detailed explanation. However, I'm still not very clear
about the issue here. It's my understanding that stepping through the code
will certainly have impact on the Form's show/hide behavior since you're
showing the form non-modal, which means the IDE will get focus when you
stepped through the code. Let me know if I've misunderstood anything.

Using your test code, I've created a local project to test the behavior:

private Form2 f2 = new Form2();

private void showHideForm2ToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (f2.Visible == true)
f2.Hide();
else
{
f2.Show();
f2.BringToFront();
}
}

This should works correctly if you're running the project instead of
stepping through the .Show or .BringToFront() code.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 12 '07 #5
Hi,

I expect the program will stop at myAdjustForm.BringToFront() after I step
over
myAdjustForm.Show(). It happens everytime after the first time.

My test can only show the program does reach myAdjustForm.show() function
every time that I select to show this pop-up window from the menu. It is up
to Windows to show the pop-up window or CSC to generate the right code.

In addition, I have similar functions throughout my program to display other
windows. This is the only one that doesn't work right the first time. Can you
explain why?

The above can be observed with/without code optimization enable.

If I cannot make sense out of my program when I step it through, how can I
debug
my program?

Thanks.

Best regards,

Albert

"Walter Wang [MSFT]" wrote:
Hi Albert,

Thank you for your detailed explanation. However, I'm still not very clear
about the issue here. It's my understanding that stepping through the code
will certainly have impact on the Form's show/hide behavior since you're
showing the form non-modal, which means the IDE will get focus when you
stepped through the code. Let me know if I've misunderstood anything.

Using your test code, I've created a local project to test the behavior:

private Form2 f2 = new Form2();

private void showHideForm2ToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (f2.Visible == true)
f2.Hide();
else
{
f2.Show();
f2.BringToFront();
}
}

This should works correctly if you're running the project instead of
stepping through the .Show or .BringToFront() code.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 12 '07 #6
Hi Albert,

When the first time .Show gets called, is the form already loaded? i.e.
Does its Load event get called before the first call to its Show()? Also,
what's the Load event doing there?

It would be great if you could send me a reproducible project which could
easily show the issue. Thank you for your effort.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 13 '07 #7
Hi Albert,

Would you please let us know the status of this post? Thanks.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 15 '07 #8
Hi Walter,

I can't send you my program and I think a simplified version may not show
this problem.

Can you elaborate more about the load event since I am not familiar with it?
How can I tell whether the form is loaded?

Do you think this is an initialization problem of my program?
Can you suggest how to generate some debug messages that can help
us to see find the root cause of this problem.

Thanks.

Best regards,

Albert
Feb 16 '07 #9
Hi Albert,

Here's some important events of a Form that might be useful for you:
===========
Load: This event is fired when the form is first loaded in the program. It
is called when the Form.Show() or Form.ShowDialog() method is called for
the first time.

Activated: This event is triggered whenever the form gets the application
focus. It is fired when the form is first loaded (along with Load event),
when the form is brought in front, or when the form is restored from the
minimized state.

VisibleChanged: It is called whenever the Visible property of the form is
changed or the form is hidden or shown.

Deactivated: This event is triggered whenever the form loses the
application focus. It is fired when the form is closed, when the form is
brought into background, or when the form is minimized.

Closing: It is fired when the application wishes to be closed, or the
application is in the process of close but has not yet closed.

Closed: It is raised when the application is finally closed.
===========
Also, you might find following article useful:

#ShawnVN's Blog : WinForms Tip-of-the-Day: Avoid subscribing to your own
events
http://weblogs.asp.net/savanness/arc...3/10/3646.aspx
Let me know if there's anything else I can help.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 20 '07 #10
Hi Albert,

I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.

Have a great day!

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 23 '07 #11

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

Similar topics

6
by: Jax | last post by:
Custom control problem. I'm modding a textbox so that it will always have a "%" sign at the end of it. I have overrided the Text property to account for the "%" value within the textbox and have...
0
by: Wesman | last post by:
Why does the following code not work (displays the correct values in the second textbox). if i chane the OnFocusChange method to the following it will work: private void OnFocusChange(object...
2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
0
by: Henry | last post by:
Using ideas provided by some of you I was able to figure out how to get the names of the parameters fields of a crystal report specified at run time. The code below just basically puts the...
9
by: Martin Ho | last post by:
My application should check for new updates when user chooses this option in the menu. It should go online and check the flag and compare with current flag in the programs directory. If version is...
1
by: TBK | last post by:
I'm trying to finish up an assignment I had for a class and basically I'm stuck. The program is supposed to take information you've entered, put it into an array, display it in a listbox and then...
2
by: Michael | last post by:
Dear All : I have a problem about define property GridTableStylesCollection in usercontrol. The code show as follow : Public Property StylesCollector() As GridTableStylesCollection Set(ByVal...
0
by: Michael | last post by:
Thanks for your advice. However, I have copy your script into test my project The code is that : Imports System.Windows.Forms Public Class MilesBox Inherits System.Windows.Forms.UserControl...
5
by: Len Weltman | last post by:
I am trying to pass a NumericUpDown object into a class method using Visual Studio 2005, but the control type is not found in Intellisense and the type declaration is flagged as an error. Here...
10
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.