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 / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Cannot call Close() while doing CreateHandle()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gav - 24 Aug 2005 19:36 GMT
Is there a way around this error message?

Example (not what I'm actually doing but similar, this is a simple version):

Lets say you are creating some sort of calendar application you create a
form which is a MDI container, another form which is the 'events' form and a
dialog form which simply allows you to select a date with a ok and cancel
button.

Your app loads, the MDI container loads the events form. In the load of the
events form it realises that it does not have a date, so therefore it loads
the date dialog box, if you select a date and click on OK the events form
loads all the events for that particular date. However if I click the cancel
button I want the events form to close.

Regards
Gav
RYoung - 24 Aug 2005 22:58 GMT
Seems to me the following would be used:

App loads
Event form loads
Method in Event form checks for date,
If no date then:
   DateDialog dlg = new DateDialog();
   if ( dlg.ShowDialog() == DialogResult.Cancel )
       Unload EventForm
   End if

Would that work?

Ron

> Is there a way around this error message?
>
[quoted text clipped - 14 lines]
> Regards
> Gav
Gav - 25 Aug 2005 01:00 GMT
Thanks for the reply Ron, what you mentioned is exactly what I'm after,
however where exactly do I call the method which checks for the date? If I
do it in the Load, activated, paint or anywhere like that, if the user
clicks the cancel button and I try to close the form I get the above error
message.

"Cannot call Close() while doing CreateHandle()"

I need an event that is fired after the CreateHandle has finished so that I
could potentially close the form in code if I have to.

It would be great if somebody can guide me in the right direction of solving
this little problem...

Thanks
Gav

> Seems to me the following would be used:
>
[quoted text clipped - 29 lines]
>> Regards
>> Gav
RYoung - 25 Aug 2005 20:25 GMT
Gav,

After duplicating the error, here's what I came up with:

I created a WinApp with MainForm as MdiParent = True, an EventsForm and
CalendarDialog

On MainForm I placed a button with this code:

EventsForm frm = new EventsForm();
if ( frm.CheckDate() == DialogResult.Ok )
{
   frm.MdiParent = this;
   frm.Show();
}

On EventsForm I added the CheckDate() method:

public DialogResult CheckDate()
{
    return new CalendarDialog().ShowDialog();
}

CalendarDialog has 2 buttons, 1 with DialogResult = Cancel, the other
DialogResult = Ok

Things work as expected.

I thought about the "elegance" of the solution, and decided EventsForm is a
class, with exposed methods and properties like any other class, so
justified it that way :)
Or, you can say that a pre-condition for EventsForm to load is that it has a
valid date to load data with.

Ron

> Thanks for the reply Ron, what you mentioned is exactly what I'm after,
> however where exactly do I call the method which checks for the date? If I
[quoted text clipped - 46 lines]
>>> Regards
>>> Gav
Gav - 26 Aug 2005 13:47 GMT
Thanks again for the reply Ron... your theory sounds very reasonable I will
give it a try ASAP.

Cheers
Gav

> Gav,
>
[quoted text clipped - 82 lines]
>>>> Regards
>>>> Gav
Gav - 26 Aug 2005 14:10 GMT
That is working perfectly thanks for the help

> Thanks again for the reply Ron... your theory sounds very reasonable I
> will give it a try ASAP.
[quoted text clipped - 88 lines]
>>>>> Regards
>>>>> Gav

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.