把一个WEBBROWSER放在一个PANNEL里,如何实现webbrowser 拖动呢

解决方案 »

  1.   

    还有根据PANEL大小进行缩放,各位高手指点一下吧
      

  2.   

    根据panle大小进行拖放,比较好处理:
    1、将webbrowser放在panle中,设置webbrowser.Dock为Fill
    2、或者设置webbrowser的Anchor属性为上下左右铆定。
      

  3.   

    有一个矛盾:如果WEBBROWSER。DOCK=FILL的话,点击PANEL进行拖放和拉伸就做不到了,所以必须留出一点定的空间给鼠标mousedown,mousemove通过事件控制PANEL,但这样的话,发现webbrowser在父容器里,反应过于激烈,如果拉PANEL向左,webbrowser则以更快的速度的向左,向上也是如此,不知是不是PANEL。LOCOTION变化所制。
      // 
                // panel6
                // 
                this.panel6.Controls.Add(this.webBrowser1);
                this.panel6.Location = new System.Drawing.Point(294, 8);
                this.panel6.Name = "panel6";
                this.panel6.Size = new System.Drawing.Size(435, 254);
                this.panel6.TabIndex = 2;
                this.panel6.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MyMouseDown);
                this.panel6.MouseLeave += new System.EventHandler(this.MyMouseLeave);
                this.panel6.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MyMouseMove);
                this.panel6.Resize+= new System.EventHandler(this.panel6_Resize);
                this.panel6.LocationChanged += new EventHandler(this.panel6_Resize);
                // 
                // webBrowser1
                // 
                this.webBrowser1.Location = new System.Drawing.Point(31, 19);
                this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
                this.webBrowser1.Name = "webBrowser1";
                this.webBrowser1.Size = new System.Drawing.Size(315, 209);
                this.webBrowser1.TabIndex = 0;
                this.webBrowser1.Url = new System.Uri("http://www.sina.com.cn", System.UriKind.Absolute);
                 void panel6_Resize(object sender, System.EventArgs e)
            {
                setWebbrowserSize();
            }  void setWebbrowserSize()
       {
           Panel p = this.panel6;
           int x = p.Location.X;
           int y = p.Location.Y;
           if (p.HasChildren && p.Controls.Count == 1)
           {
               WebBrowser awebbrowser = (WebBrowser)p.Controls[0];
               awebbrowser.Location = new Point(x + 2, y + 2);
               awebbrowser.Size = new Size(p.Size.Width - 6, p.Size.Height - 6);       }
       }
      

  4.   

    我希望能达到,WEBBROWSER四个边距离PANEL有2和4像素的距离
      

  5.   

    在加载窗体的时候,根据panel动态设定一下WEBBROWSER的大小Size和位置Location属性就可以实现了
      

  6.   

    在鼠标事件里处理panel的location
      

  7.   

    void setWebbrowserSize()
      {
      Panel p = this.panel6;
      int x = p.Location.X;
      int y = p.Location.Y;
      if (p.HasChildren && p.Controls.Count == 1)
      {
      WebBrowser awebbrowser = (WebBrowser)p.Controls[0];
      awebbrowser.Location = new Point(x + 2, y + 2);
      awebbrowser.Size = new Size(p.Size.Width - 6, p.Size.Height - 6);  }
      为什么我在FORM_LOAD中调用此函数,Webbrowser中位置却不对呢,差不多在PANEL的右半边,离左边框远远不止2
      

  8.   

    //Location 是控件相对其容器左上角的坐标,所以
    awebbrowser.Location = new Point(2, 2);//(x + 2, y + 2);