Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: Image Resources - What is difference between Local Resource and Project Resource File Pin
btaz12518-Apr-11 16:20
btaz12518-Apr-11 16:20 
QuestionGraphicsPath.AddString Pin
xstoneheartx19-Aug-09 11:42
xstoneheartx19-Aug-09 11:42 
Questionc# text to wav volume Pin
mikeyman419-Aug-09 11:32
mikeyman419-Aug-09 11:32 
AnswerRe: c# text to wav volume Pin
Christian Graus19-Aug-09 15:38
protectorChristian Graus19-Aug-09 15:38 
QuestionConvert GlyphIndex to Unicode Pin
xstoneheartx19-Aug-09 11:30
xstoneheartx19-Aug-09 11:30 
QuestionModeless active window/class - Cannot access a disposed object. Pin
Natural_Demon19-Aug-09 9:05
Natural_Demon19-Aug-09 9:05 
AnswerRe: Modeless active window/class - Cannot access a disposed object. Pin
Christian Graus19-Aug-09 11:04
protectorChristian Graus19-Aug-09 11:04 
GeneralRe: Modeless active window/class - Cannot access a disposed object. Pin
Natural_Demon19-Aug-09 12:36
Natural_Demon19-Aug-09 12:36 
wel, my goal was to keep the class going.
as a sort of debugging window and make a reapear when needed.
using the same button that created the original window.

i know there are other possibilites to do this.
by creating a simple class, store data, a array to hold the classes and create a new instance of Form2.

Form2 contains a RichTextBox so i can display things of interest to me.
i added a FormClosing Event + a Callback in Form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Modales_window
{
    public partial class Form2 : Form
    {
        public delegate void ClosingEventHandler();
        public event ClosingEventHandler closingeventhandler;

        public Form2()
        {
            InitializeComponent();
        }

        protected virtual void OnClosingEventHandler()
        {
            if (closingeventhandler != null)
            {
                closingeventhandler();
            } 
        }

        private void ModalesWindow2_FormClosing(object sender, FormClosingEventArgs e)
        {
            OnClosingEventHandler();
        }
    }
}


but this solution doesn't prevent the 'Cannot access a disposed object' error mw2.Dispose();
public Form1()
{
    mw2.closingeventhandler += new Form2.ClosingEventHandler(mw2_closingeventhandler);
    InitializeComponent();
}
void mw2_closingeventhandler()
{
    mw2.Dispose();
    // this is how i tried to free up the recources.
    // but this causes a loop error : (
}


now i tried this, the same button creates/togles the visibillity of the window.
but once you close Form2 with the 'close' button of the form i return to 'Cannot access a disposed object' error
private void button1_Click(object sender, EventArgs e)
{
    // Cannot access a disposed object.
    // Object name: 'Form2'.
    if (!mw2.Created)
    {
        mw2.Show();
    }
    else
    {
        //MessageBox.Show("already open", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
        if (mw2.Visible == true)
        {
            mw2.Visible = false;
        }
        else
        {
            mw2.Visible = true;
        }
    }
}


having come this far, i'm intrested in both.
1 - how to work around 'Cannot access a disposed object'
if you try to open the window again with the same button once you closed it with the RED X button of the form.
You need to hook up to the closing event in form2, so that form1 knows when form2 is closed, and resets it to null. Then use a null check to create a new form
2 - prevent the RED X button to close it and mw2.Visible = true
change the code in form2 so that it never gets closed, it just hides itself.

please show me what you have in mind.

thank you and kind regards

p.s. as a non native english speaker, i hoped to explained myself wel
p.p.s the most simple work around is to set the FormBorderStyle = none, but i like to learn
: )

Bad = knowing 2 much

GeneralRe: Modeless active window/class - Cannot access a disposed object. Pin
Natural_Demon19-Aug-09 13:00
Natural_Demon19-Aug-09 13:00 
GeneralRe: Modeless active window/class - Cannot access a disposed object. Pin
Christian Graus19-Aug-09 16:00
protectorChristian Graus19-Aug-09 16:00 
GeneralRe: Modeless active window/class - Cannot access a disposed object. Pin
Natural_Demon20-Aug-09 2:48
Natural_Demon20-Aug-09 2:48 
QuestionDynamic Menu Creation Problem Pin
jroberson1019-Aug-09 8:59
jroberson1019-Aug-09 8:59 
AnswerRe: Dynamic Menu Creation Problem Pin
Hristo-Bojilov19-Aug-09 9:37
Hristo-Bojilov19-Aug-09 9:37 
GeneralRe: Dynamic Menu Creation Problem Pin
jroberson1019-Aug-09 9:41
jroberson1019-Aug-09 9:41 
GeneralRe: Dynamic Menu Creation Problem Pin
Hristo-Bojilov19-Aug-09 9:46
Hristo-Bojilov19-Aug-09 9:46 
GeneralRe: Dynamic Menu Creation Problem Pin
jroberson1019-Aug-09 9:50
jroberson1019-Aug-09 9:50 
GeneralRe: Dynamic Menu Creation Problem Pin
Hristo-Bojilov19-Aug-09 9:56
Hristo-Bojilov19-Aug-09 9:56 
GeneralRe: Dynamic Menu Creation Problem Pin
jroberson1019-Aug-09 10:07
jroberson1019-Aug-09 10:07 
GeneralRe: Dynamic Menu Creation Problem Pin
jroberson1020-Aug-09 11:36
jroberson1020-Aug-09 11:36 
GeneralRe: Dynamic Menu Creation Problem Pin
0x3c019-Aug-09 9:47
0x3c019-Aug-09 9:47 
GeneralRe: Dynamic Menu Creation Problem Pin
jroberson1019-Aug-09 9:51
jroberson1019-Aug-09 9:51 
GeneralRe: Dynamic Menu Creation Problem Pin
0x3c019-Aug-09 9:58
0x3c019-Aug-09 9:58 
QuestionInsert function into event at runtime Pin
bonzaiholding19-Aug-09 8:45
bonzaiholding19-Aug-09 8:45 
AnswerRe: Insert function into event at runtime Pin
0x3c019-Aug-09 9:57
0x3c019-Aug-09 9:57 
GeneralRe: Insert function into event at runtime Pin
bonzaiholding19-Aug-09 10:18
bonzaiholding19-Aug-09 10:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.