所有代码我都是照书上源代码复制出来的,原来的程序能运行,按原样新建程序,把代码复制过来就不行,窗体名字都是一样的。
错误提示为
警告 1 “Popup.Controls.Frm_Popup.Show()”隐藏了继承的成员“System.Windows.Forms.Control.Show()”。如果是有意隐藏,请使用关键字 new。 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Frm_Popup\Frm_Popup\Frm_Popup.cs 92 21 Frm_Popup
//以下是Frm_Popup 窗体代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace Popup.Controls
{
    partial class Frm_Popup : System.Windows.Forms.Form
    {        #region 变量
        private InformStyle InfoStyle = InformStyle.Vanish;//定义变量为隐藏
        private System.Drawing.Rectangle Rect;//定义一个存储矩形框的数组
        private bool isMouseMove = false;//是否在窗体中移动
        static private Frm_Popup F_Popup = new Frm_Popup();//实例化当前窗体
        #endregion        #region 内置属性
        /// <summary>
        /// 定义一个任务通知器的枚举值
        /// </summary>//InformStyle
        protected enum InformStyle
        {
            /// <summary>
            /// 隐藏
            /// </summary>
            Vanish = 0,
            /// <summary>
            /// 显视
            /// </summary>
            Display = 1,
            /// <summary>
            /// 显视中
            /// </summary>
            Displaying = 2,
            /// <summary>
            /// 隐藏中
            /// </summary>
            Vanishing = 3
        }        /// <summary>
        /// 获取或设置当前的操作状态
        /// </summary>
        protected InformStyle InfoState
        {
            get { return this.InfoStyle; }
            set { this.InfoStyle = value; }
        }
        #endregion        public Frm_Popup()
        {
            this.InitializeComponent();
            this.timer1.Stop();//停止计时器
            //初始化工作区大小
            System.Drawing.Rectangle rect = System.Windows.Forms.Screen.GetWorkingArea(this);
            this.Rect = new System.Drawing.Rectangle(rect.Right - this.Width - 1, rect.Bottom - this.Height - 1, this.Width, this.Height);
        }        #region 返回当前窗体的实例化
        /// <summary>
        /// 返回此对象的实例
        /// </summary>
        /// <returns></returns>
        static public Frm_Popup Instance()
        {
            return F_Popup;
        }
        #endregion        #region 声明WinAPI
        /// <summary>
        /// 显示窗体
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="nCmdShow"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
        #endregion        #region 方法
        /// <summary>
        /// 显示窗体
        /// </summary>
        public void Show()
        {
            switch (this.InfoState)
            {
                case InformStyle.Vanish://窗体隐藏
                    this.InfoState = InformStyle.Displaying;//设置窗体的操作状态为显示中
                    this.SetBounds(Rect.X, Rect.Y + Rect.Height, Rect.Width, 0);//显示Popup窗体,并放置到屏幕的底部
                    ShowWindow(this.Handle, 4);//显示窗体
                    this.timer1.Interval = 100;//设置时间间隔为100
                    this.timer1.Start();//启动计时器
                    break;
                case InformStyle.Display://窗体显示
                    this.timer1.Stop();//停止计时器
                    this.timer1.Interval = 5000;//设置时间间隔为5000
                    this.timer1.Start();//启动记时器
                    break;
            }
        }
        #endregion        #region 事件
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            switch (this.InfoState)
            {
                case InformStyle.Display://显示当前窗体
                    this.timer1.Stop();//停止计时器
                    this.timer1.Interval = 100;//设置时间间隔为100
                    if (!(this.isMouseMove))//如果鼠标不在窗体中移动
                        this.InfoState = InformStyle.Vanishing;//设置当前窗体的操作状态为隐藏中
                    this.timer1.Start();//启动计时器
                    break;
                case InformStyle.Displaying://当前窗体显示中
                    if (this.Height <= this.Rect.Height - 12)//当窗体没有完全显示时
                        this.SetBounds(Rect.X, this.Top - 12, Rect.Width, this.Height + 12);//使窗体不断上移
                    else
                    {
                        this.timer1.Stop();//停止计时器
                        this.SetBounds(Rect.X, Rect.Y, Rect.Width, Rect.Height);//设置当前窗体的边界
                        this.InfoState = InformStyle.Display;//设置当前窗体的操作状态为显示
                        this.timer1.Interval = 5000;//设置时间间隔为5000
                        this.timer1.Start();//启动计时器
                    }
                    break;
                case InformStyle.Vanishing://隐藏当前窗体
                    if (this.isMouseMove)//如果鼠标在窗体中移动
                        this.InfoState = InformStyle.Displaying;//设置窗体的操作状态为显示
                    else
                    {
                        if (this.Top <= this.Rect.Bottom - 12)//如果窗体没有完全隐藏
                            this.SetBounds(Rect.X, this.Top + 12, Rect.Width, this.Height - 12);//使窗体不断下移
                        else
                        {
                            this.Hide();//隐藏当前窗体
                            this.InfoState = InformStyle.Vanish;//设置窗体的操作状态为隐藏
                        }
                    }
                    break;
            }
        }        private void Frm_Popup_MouseMove(object sender, MouseEventArgs e)
        {
            this.isMouseMove = true;//当鼠标移入时,设为true
        }        private void Frm_Popup_MouseLeave(object sender, EventArgs e)
        {
            this.isMouseMove = false;//当鼠标移出时,设为false
        }        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (this.InfoState != InformStyle.Vanish)//如果窗体的状态不是隐藏
            {
                this.timer1.Stop();//停止计时器
                this.InfoState = InformStyle.Vanish;//设置窗体的操作状态为隐藏
                base.Hide();//隐藏当前窗体
            }
        }        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.Image = null;
            pictureBox1.Image = Image.FromFile("Close1.bmp");
        }        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.Image = null;
            pictureBox1.Image = Image.FromFile("Close2.bmp");
        }
        #endregion
    }
}
//以下是Form1的代码 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace Frm_Popup
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            Popup.Controls.Frm_Popup.Instance().Show();
        }
    }
}

解决方案 »

  1.   

    下次贴代码用UBB排版一下。
    例如你的代码
    按提示,你尝试吧
    public void Show()
    改为:
    public new void Show()
      

  2.   

    提示不是写的很清楚了吗?你得把partial class Frm_Popup : System.Windows.Forms.Form
    这个类中的
    public void Show()这个方法改一下,因为对于它的基类Form也有一个Show方法,你有几种选择:
    1. 把这个方法改成 public new void Show()
    2. 修改方法名为ShowForm这种不会和Form中方法重名的
    3. 看看你的工程属性里是不是把Build选项卡中的Treat warning as errors设置成了All,如果是的话,把它设置成None就可以看到这个问题作为warning出现,而不会编译错误了
      

  3.   

    sorry看错了,你这个本来就是warning,那可以忽略我写的第三种解决方法
      

  4.   

    Rect计算看不懂,用这个System.Drawing.Rectangle rect = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
    下面两句位置调换一下
    this.SetBounds(Rect.X,Rect.Y,Rect.Width,Rect.Height);
    //显示Popup窗体,并放置到屏幕的底部
    ShowWindow(this.Handle,4);private   enum   WindowShowStyle

    ///<summary> Hides   the   window   and   activates   another   window.</summary> 
    ///<res> See   SW_HIDE </res> 
    Hide   =   0, 
    ///   <summary> Activates   and   displays   a   window.   If   the   window   is   minimized   
    ///   or   maximized,   the   system   restores   it   to   its   original   size   and   
    ///   position.   An   application   should   specify   this   flag   when   displaying   
    ///   the   window   for   the   first   time. </summary> 
    ///   <res> See   SW_SHOWNORMAL </res> 
    ShowNormal   =   1, 
    ///   <summary> Activates   the   window   and   displays   it   as   a   minimized   window. </summary> 
    ///   <res> See   SW_SHOWMINIMIZED </res> 
    ShowMinimized   =   2, 
    ///   <summary> Activates   the   window   and   displays   it   as   a   maximized   window. </summary> 
    ///   <res> See   SW_SHOWMAXIMIZED </res> 
    ShowMaximized   =   3, 
    ///   <summary> Maximizes   the   specified   window. </summary> 
    ///   <res> See   SW_MAXIMIZE </res> 
    Maximize   =   3, 
    ///   <summary> Displays   a   window   in   its   most   recent   size   and   position.   
    ///   This   value   is   similar   to   "ShowNormal ",   except   the   window   is   not   
    ///   actived. </summary> 
    ///   <res> See   SW_SHOWNOACTIVATE </res> 
    ShowNormalNoActivate   =   4, 
    ///   <summary> Activates   the   window   and   displays   it   in   its   current   size   
    ///   and   position. </summary> 
    ///   <res> See   SW_SHOW </res> 
    Show   =   5, 
    ///   <summary> Minimizes   the   specified   window   and   activates   the   next   
    ///   top-level   window   in   the   Z   order. </summary> 
    ///   <res> See   SW_MINIMIZE </res> 
    Minimize   =   6, 
    ///   <summary> Displays   the   window   as   a   minimized   window.   This   value   is   
    ///   similar   to   "ShowMinimized ",   except   the   window   is   not   activated. </summary> 
    ///   <res> See   SW_SHOWMINNOACTIVE </res> 
    ShowMinNoActivate   =   7, 
    ///   <summary> Displays   the   window   in   its   current   size   and   position.   This   
    ///   value   is   similar   to   "Show ",   except   the   window   is   not   activated. </summary> 
    ///   <res> See   SW_SHOWNA </res> 
    ShowNoActivate   =   8, 
    ///   <summary> Activates   and   displays   the   window.   If   the   window   is   
    ///   minimized   or   maximized,   the   system   restores   it   to   its   original   size   
    ///   and   position.   An   application   should   specify   this   flag   when   restoring   
    ///   a   minimized   window. </summary> 
    ///   <res> See   SW_RESTORE </res> 
    Restore   =   9, 
    ///   <summary> Sets   the   show   state   based   on   the   SW_   value   specified   in   the   
    ///   STARTUPINFO   structure   passed   to   the   CreateProcess   function   by   the   
    ///   program   that   started   the   application. </summary> 
    ///   <res> See   SW_SHOWDEFAULT </res> 
    ShowDefault   =   10, 
    ///   <summary> Windows   2000/XP:   Minimizes   a   window,   even   if   the   thread   
    ///   that   owns   the   window   is   hung.   This   flag   should   only   be   used   when   
    ///   minimizing   windows   from   a   different   thread. </summary> 
    ///   <res> See   SW_FORCEMINIMIZE </res> 
    ForceMinimized   =   11 

      

  5.   

    显示出一个标题栏,没在右下方,窗体像是没到右下方,也没显示出来,代码都是从书的源代码拷过来的,不知要设置什么控件的属性,看了timer时间设置是一样的100没错。哪位知道怎么解呀?
      

  6.   

    貌似你在public void Show()
      {
      switch (this.InfoState)
      {
      case InformStyle.Vanish://窗体隐藏
      this.InfoState = InformStyle.Displaying;//设置窗体的操作状态为显示中
      this.SetBounds(Rect.X, Rect.Y + Rect.Height, Rect.Width, 0);//显示Popup窗体,并放置到屏幕的底部
      ShowWindow(this.Handle, 4);//显示窗体
      this.timer1.Interval = 100;//设置时间间隔为100
      this.timer1.Start();//启动计时器
      break;这部分里面没有设置InfoStyle。尝试加入this.InfoState = InformStyle.Displaying;
      

  7.   

    Sorry,看错了,你上面有这句话
      

  8.   

    你加个断点进到timer的tick响应事件中,打个断点看看是不是Form的位置不对了。
      

  9.   

    知道了,timer的单击事件,没关联上。