当前位置:编程学习 > C#/ASP.NET >>

难道是微软的BUG??请问谁能解决啊?

用VS2005生成一个MDI窗体 
我在Main   Form中添加了一个MenuStrip, 
我把它设置它this.IsMdiContainer   =   true;同时指定了一个自制的ICON。 

然后生成子Form,指定this.WindowState   =   System.Windows.Forms.FormWindowState.Maximized;同时也指定了一个自制的ICON。 

在Main   Form构造中添加生成了Form的代码: 
Form   child   =   new   TestForm(); 
child.MdiParent   =   this; 
child.Show(); 

可是子Form的ICON和大小都显示不正常。可是当把Main   Form最小化再最大化,就一切都正常了。。。。

初始化不正常:


把Main Form最小化再最大化,就正常了  
--------------------编程问答-------------------- 我觉得,可能是你语句顺寻的问题,你可以再给子form设置大小和图标的代码设置断点,你跟一下它的执行顺序.在窗口最大化和最小化后会读取一些参数,然后再重新绘制窗口.我猜可能就是执行顺序的问题,你看下吧.呵呵,不一定对,希望能帮到你 --------------------编程问答-------------------- 在子Form中的代码中
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(384, 364);
            this.Controls.Add(this.menuStrip1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "TestForm";
            this.Text = "TestForm";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();
我调整了设置ICON、设置MainMenuStrip和WindowState的顺序,没有什么效果。。。 --------------------编程问答-------------------- 会不会是刷新的问题?

你手动调用刷新看看:
Application.DoEvents();
            this.Refresh(); --------------------编程问答-------------------- 在MainForm的构造函数中添加:
              Form child = new TestForm();
            child.MdiParent = this;
           
            child.Show();

            Application.DoEvents();
            this.Refresh();
或者:
              Form child = new TestForm();
            child.MdiParent = this;

            Application.DoEvents();
            this.Refresh();
            
            child.Show();

仍然没效果。。。。
             --------------------编程问答-------------------- 会不会是 2005下 MenuStrip的问题?
是不是MenuStrip影响了子窗口的 显示呢? --------------------编程问答--------------------    Form   child   =   new   TestForm(); 
  child.WindowState       =       System.Windows.Forms.FormWindowState.Maximized;             child.MdiParent   =   this; 
   child.Show(); 
--------------------编程问答-------------------- 这应该是MS的BUG,我也碰到这种问题,到现在都还没找到解决方法.... --------------------编程问答-------------------- 使用
Form       child       =       new       TestForm();   
child.WindowState               =               System.Windows.Forms.FormWindowState.Maximized;                           child.MdiParent       =       this;  
窗口大小对了,但是子窗口的ICON还是不对 
--------------------编程问答-------------------- 接分

谢谢 --------------------编程问答-------------------- 怎么接分? --------------------编程问答-------------------- 要动态载入ICON. --------------------编程问答--------------------
看Delphi的解决办法
http://www.8888i.net/dispQAInfo.php?id=855

照着改改 --------------------编程问答-------------------- 谢谢大家,我先试试都:) --------------------编程问答-------------------- 对于动态载入ICON的方法,我是这样作的:
              Form child = new TestForm();
            child.WindowState = FormWindowState.Maximized;
            child.MdiParent = this;
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormIcon));
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            child.Show();
结果还是没有效果 --------------------编程问答-------------------- Delphi提供的方法,具体的看不太清楚,但是感觉可能是把Menu重新载入了

我在C#中也试了一下,先把Menu Dispose,然后再生成,不过没有效果。。。
是不是理解错了?

(C#代码如下)
Form child = new TestForm();
            child.WindowState = FormWindowState.Maximized;
            child.MdiParent = this;
            menuStrip1.Dispose();

            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fIleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.menuStrip1.SuspendLayout();
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fIleToolStripMenuItem});
            this.menuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(435, 24);
            this.menuStrip1.TabIndex = 1;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // fIleToolStripMenuItem
            // 
            this.fIleToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.openToolStripMenuItem});
            this.fIleToolStripMenuItem.Name = "fIleToolStripMenuItem";
            this.fIleToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.fIleToolStripMenuItem.Text = "FIle";
            // 
            // openToolStripMenuItem
            // 
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
            this.openToolStripMenuItem.Text = "Open";
            this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
            // 

            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
           
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestForm));
            child.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 
            child.Show();

补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,