c#


Buttons work only on the second click on custom popup c#


when i move between forms buttons works as expected, but when im closing my custom pop up only seconds click on any button will trigger it
this is the code im using to load my custom popup
public void loadPopUp(Form from, Form to)
{
to.Tag = from;
to.Show(from);
}
and this is the code my using to close my custom popup
public void closePopUp(string formName)
{
for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
{
string name = Application.OpenForms[i].Name; //for debugging only
if (Application.OpenForms[i].Name == formName)
Application.OpenForms[i].Close();
}
}
note: this is not asp.net application
You should have something else in your code or you make something with the main window that changes the normal behavior of the forms engine. I have tried to build a sample app with LinqPAD using the code above and I have a normal behavior as expected. When I close the popup the focus is restored to the main form.
Nevertheless you could use the main form saved instance in the Tag property to call the Activate method and restore the focus to the main form.
public void closePopUp(string formName)
{
// No need to loop over all application OpenForms if you just want
// to close this popup
// for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
// {
// string name = Application.OpenForms[i].Name; //for debugging only
// if (Application.OpenForms[i].Name == formName)
// Application.OpenForms[i].Close();
//}
var mainForm = this.Tag as Form;
this.Close();
if(mainForm != null)
mainForm.Activate();
}
Note, I use a cast to the base Form class, so your code doesn't depend on the popup created by a particular class instance. This is possible because Activate is a base class method.

Related Links

How to get a correct result of binary string intersection in Entity to Linq query
unable to connect to the remote server from .com domain
Namespace 'Interop' does not exist in namespace “Microsoft.Office”
SQL Server 2008: Dynamic operations can only be performed in homogenous AppDomain
Is there any way to Create “Gradient” Background color for “wizard Control” in “.net 4.5”?
Identity_Insert with Aspnet.Identity
Pass by reference and storing a reference to a variable - c#
C# API Controller Custom Filter with HttpActionContext Redirect to controller?
How to use ODataQueryOptions in case of TypeLess (UnTyped) object in ASP.NET WebApi / OData project
Encoding.Default not working in Unity Player
How do I launch my app from a bash script passing in a parameter?
Why does VS2015RC says “The ViewBag doesn't exist in the current context”, where as VS2013 says no errors?
Putting a List into a datatable column in c#
Changing PivotItem with swipe gesture crashes app (Visual C#, Windows Runtime, Windows Phone)
Unable to run .vbs script from my C# program: “The system cannot find the file specified.”
Single responsibility principle in MVC

Categories

HOME
gcc
marie
ftp
sip
gap-system
c++builder
okhttp3
pandoc
servicenow
obd-ii
ios-universal-links
jpql
google-search-appliance
http-status-codes
chef-recipe
android-wifi
rndis
ng-tags-input
inspec
restangular
semantic-ui-react
folder
intermec
boost-log
textview
kubectl
javafxports
perf
motion
lex
gem-fury
office-interop
android-graphview
aspnetboilerplate
firefox-developer-edition
dna-sequence
seyren
petapoco
spring-cloud-aws
apache-commons-cli
stringbuilder
jigsaw
camellia
matlab-engine
mojolicious
gitk
random-sample
nfa
jad
attiny
caption
javadb
os.walk
powerpoint-2010
satisfiability
lettuce
new-operator
internet-radio
pthreads-win32
windows-phone-store
nomachine
mdp
ojb
extensibility
google-checkout
proj4
windows-scheduler
junction-table
nx
brew
auctex
phone-state-listener
django-tinymce
linear-interpolation
junit-rule
m3u
databus
github-archive
towerjs
scriptmanager
cherokee
httppostedfilebase
overlays
jquery-click-event
method-call
numerical-computing

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App