Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    338

    [c#] MDI e massimizzazione finestre

    ciao a tutti, ho bisogno di aiuto per questo problema..

    sto preparando una applicazione winform di tipo MDI, la frmMain è in sostanza questo con l'aggiunta dei gestori dei menu

    codice:
    public partial class frmMain : Form
    {
        private int _childFormNumber = 0;
    
        public int childFormNumber
        {
            get
            {
                return _childFormNumber;
            }
            set
            {
                _childFormNumber = value;
            }
        }
    
        public frmMain()
        {
            InitializeComponent();
        }
    
        private void ShowNewForm(object sender, EventArgs e)
        {
            // Crea una nuova istanza del form figlio.
            Form childForm = new frmElenco(childFormNumber);
    
            // Imposta il form come figlio di questo form MDI prima di visualizzarlo.
            childForm.MdiParent = this;
            childForm.Text += " " + ((childFormNumber++) + 1);
            childForm.Show();
        }
    
        private void frmMain_Load(object sender, EventArgs e)
        {
            //  al caricamento apre subito una finestra ricerca
            ShowNewForm(sender, e);
        }
    }
    mentre la frmElenco

    codice:
    public partial class frmElenco : Form
    {
        public frmElenco()
        {
            InitializeComponent();
        }
    
        //  numero della form intesa come figlia della MDIparent
        private int _numeroFiglio = 0;
    
        public int numeroFiglio
    		{
    			get
    			{
                    return _numeroFiglio;
    			}
    		}
    
        public frmElenco(int numero)
        {
            InitializeComponent();
    
            //  assegna il numero interno
            _numeroFiglio = numero;
        }
        
        // eccetera
    }
    ora il problema è che se faccio click sul pulsante di massimizzazione della finestra e poi sulla sua x per chiuderla, ricevo una eccezione:

    System.ObjectDisposedException non è stata gestita
    Message="Impossibile accedere a un oggetto eliminato.\r\nNome oggetto: 'Icon'."
    Source="System.Drawing"
    ObjectName="Icon"


    con il cursore in frmElenco su:
    protected override void Dispose(bool disposing)
    {
    if (disposing && (components != null))
    {
    components.Dispose();
    }
    base.Dispose(disposing);
    }

    Avete qualche idea su questo comportamento?

    Parlo dell'MDI perchè il problema si presenta anche se leggermente diverso in un altro caso. Dalla frmElenco io apro altre finestre con

    codice:
    frmPersonale frmP = new frmPersonale(matricola, nominativo);
    //  la scheda deve rimanere all'interno della frmMain e comparire nell'elenco finestre
    frmP.MdiParent = this.MdiParent;
    frmP.Show();
    e se ripeto l'operazione (massimizza e poi chiudi) ottengo che il prog. va in crash con uno sfarfallio continuo, sembra che tenti di ridisegnare la form sottostante e poi quella che ho appena chiuso, ecc.

    vi prego una mano..

    ps: ovviamente se non clikko mai su 'massimizza' tutto funziona bene, e anche se tolgo la riga

    frmP.MdiParent = this.MdiParent;

    ???
    dulcis in fundo non ho problemi se dopo aver massimizzato, prima di chiudere la form la riporto alla dimensione originale!

  2. #2
    Utente di HTML.it L'avatar di albgen
    Registrato dal
    Jun 2005
    Messaggi
    3,249
    non vedo da nessuna parte una istruzione del genere(probabilmente è dentro initializeComponent)..
    this.IsMdiContainer = true;
    non saprei dirti se c'èntra o meno però prova ad aggiungerlo...

    public frmMain()
    {
    InitializeComponent();
    this.IsMdiContainer = true;
    }

    e poi non cè bisogno di questo
    private int _childFormNumber = 0;
    la form ha una proprietà this.MdiChildren che è un array...
    quindi puoi fare this.MdiChildren.Length e hai il numero delle form
    I got the remedy

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    338
    luendì controllo, ma pensi che questo sia collegato agli errori o è solo un tuo consiglio per migliorare il codice?

  4. #4
    Utente di HTML.it L'avatar di albgen
    Registrato dal
    Jun 2005
    Messaggi
    3,249
    Originariamente inviato da Another
    luendì controllo, ma pensi che questo sia collegato agli errori o è solo un tuo consiglio per migliorare il codice?
    ho letto meglio il tuo post....sembra che il problema non sia nelle form ma in
    una icona...controlla meglio.

    cmq, il campo private int _childFormNumber = 0; è inutile....
    è come dire, ho una variabile int A; che mi conta le mele e ho una variabile int B; che mi conta le stesse mele...che senso ha avere due variabili che contengono la stessa informazione ?
    nessuna, anzi sprechi la ram oltre ad avere un codice più lento, più lungo e non comprensibile....
    I got the remedy

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    338
    allora, la proprietà IsMdiContainer è a posto, l'ho impostata nelle proprietà della form in progettazione, infatti in frmMain.Designer.cs è scritto:

    codice:
    this.IsMdiContainer = true;
    per l'icona..

    - le icone le ho impostate tramite le proprietà delle form, dove vedo la miniatura ma nn trovo nel progetto i files. Non dovrebbero essere nella cartella Resources? A dire il vero questa parte è di qualche mese fa, potrebbero essersi perse nei vari cambi di pc.. devo copiarle da qualche parte o se le vedo come miniature nelle prorietà è a posto?

    - lo stack
    codice:
          StackTrace:
           in System.Drawing.Icon.get_Handle()
           in System.Drawing.Icon.get_Size()
           in System.Drawing.Icon.ToBitmap()
           in System.Windows.Forms.MdiControlStrip.GetTargetWindowIcon()
           in System.Windows.Forms.MdiControlStrip..ctor(IWin32Window target)
           in System.Windows.Forms.Form.UpdateMdiControlStrip(Boolean maximized)
           in System.Windows.Forms.Form.WmSize(Message& m)
           in System.Windows.Forms.Form.WndProc(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           in System.Windows.Forms.UnsafeNativeMethods.DefMDIChildProc(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           in System.Windows.Forms.Form.DefWndProc(Message& m)
           in System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
           in System.Windows.Forms.Control.WndProc(Message& m)
           in System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           in System.Windows.Forms.ContainerControl.WndProc(Message& m)
           in System.Windows.Forms.Form.WndProc(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           in System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           in System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
           in System.Windows.Forms.Control.DefWndProc(Message& m)
           in System.Windows.Forms.Control.WndProc(Message& m)
           in System.Windows.Forms.MdiClient.WndProc(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           in System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           in System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
           in System.Windows.Forms.Control.DefWndProc(Message& m)
           in System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
           in System.Windows.Forms.Control.WndProc(Message& m)
           in System.Windows.Forms.MdiClient.WndProc(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           in System.Windows.Forms.SafeNativeMethods.SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags)
           in System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
           in System.Windows.Forms.MdiClient.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
           in System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.SetBounds(Rectangle bounds, BoundsSpecified specified)
           in System.Windows.Forms.Layout.DefaultLayout.ApplyCachedBounds(IArrangedElement container)
           in System.Windows.Forms.Layout.DefaultLayout.xLayout(IArrangedElement container, Boolean measureOnly, Size& preferredSize)
           in System.Windows.Forms.Layout.DefaultLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
           in System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
           in System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
           in System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
           in System.Windows.Forms.Form.OnLayout(LayoutEventArgs levent)
           in System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
           in System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
           in System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
           in System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
           in System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
           in System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
           in System.Windows.Forms.ToolStrip.DoLayoutIfHandleCreated(ToolStripItemEventArgs e)
           in System.Windows.Forms.ToolStrip.OnItemVisibleChanged(ToolStripItemEventArgs e, Boolean performLayout)
           in System.Windows.Forms.ToolStrip.OnItemRemoved(ToolStripItemEventArgs e)
           in System.Windows.Forms.ToolStripItemCollection.OnAfterRemove(ToolStripItem item)
           in System.Windows.Forms.ToolStripItemCollection.Remove(ToolStripItem value)
           in System.Windows.Forms.ToolStripManager.RevertMergeInternal(ToolStrip targetToolStrip, ToolStrip sourceToolStrip, Boolean revertMDIControls)
           in System.Windows.Forms.Form.UpdateMdiWindowListStrip()
           in System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
           in System.Windows.Forms.Control.WmShowWindow(Message& m)
           in System.Windows.Forms.Control.WndProc(Message& m)
           in System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           in System.Windows.Forms.ContainerControl.WndProc(Message& m)
           in System.Windows.Forms.Form.WmShowWindow(Message& m)
           in System.Windows.Forms.Form.WndProc(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           in System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           in System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
           in System.Windows.Forms.Control.DefWndProc(Message& m)
           in System.Windows.Forms.Control.WndProc(Message& m)
           in System.Windows.Forms.MdiClient.WndProc(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           in System.Windows.Forms.UnsafeNativeMethods.DefMDIChildProc(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           in System.Windows.Forms.Control.DestroyHandle()
           in System.Windows.Forms.Control.Dispose(Boolean disposing)
           in System.Windows.Forms.Form.Dispose(Boolean disposing)
           in SorveglianzaSanitaria.frmElenco.Dispose(Boolean disposing) in D:\Users\..\Documents\Progetti\servizioPP\sorveglianzasanitaria\SorveglianzaSanitaria\frmElenco.Designer.cs:riga 20
           in System.ComponentModel.Component.Dispose()
           in System.Windows.Forms.Form.WmClose(Message& m)
           in System.Windows.Forms.Form.WndProc(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           in System.Windows.Forms.UnsafeNativeMethods.DefMDIChildProc(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           in System.Windows.Forms.Form.DefWndProc(Message& m)
           in System.Windows.Forms.Control.WndProc(Message& m)
           in System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           in System.Windows.Forms.ContainerControl.WndProc(Message& m)
           in System.Windows.Forms.Form.WmSysCommand(Message& m)
           in System.Windows.Forms.Form.WndProc(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           in System.Windows.Forms.Application.Run(Form mainForm)
           in SorveglianzaSanitaria.Program.Main() in D:\Users\..\Documents\Progetti\servizioPP\sorveglianzasanitaria\SorveglianzaSanitaria\Program.cs:riga 27
           in System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           in System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
           in System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
           in System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
           in System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
           in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
           in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           in System.Threading.ThreadHelper.ThreadStart()

  6. #6
    Utente di HTML.it L'avatar di albgen
    Registrato dal
    Jun 2005
    Messaggi
    3,249
    prova reimpostare questa icona...cioè lo cancelli e lo imposti come se fosse una nuova icona...
    I got the remedy

  7. #7
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    338
    ho tolto le icone da tutte le form e non dà più problemi, ora provo a rimetterle, ma c'è una opzione di salvataggio/copia nelle risorse?

  8. #8
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    338
    aggiorno:

    - se non metto nessuna icona per le form tutto bene
    - se inserisco l'icona puntando ad un file in una posizione locale qualsiasi ho i problemi
    - ho i problemi anche se aggiungo l'icona alla cartella Resources e poi la punto

    c'è un metodo sicuro per gestire queste icone?

  9. #9
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    338
    qualcuno mi sa dare una dritta? grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.