如何在Windows Mobile应用程序中显示弹出框?

问题描述:

我正在开发一个Windows移动应用程序,我想在其中显示弹出框,其中包含DataGrid控件,用于在用户单击窗体中的某个按钮时显示特定的细节。如何在Windows Mobile应用程序中显示弹出框?

我正在使用ShowDialog()方法,但它工作。

任何人都可以告诉我如何实现这个?

在此先感谢。

+0

我使用ShowDialog()方法,但它工作。 ? – 2011-04-28 08:43:12

+0

这是一个紧凑的框架应用程序吗?如果是这样,你应该编辑你的标签,因为它与asp.net无关。另外你的问题还不清楚 - 它工作,还是不是?你应该展示一些代码让人们能够更好地帮助你。 – 2011-04-28 10:48:58

如果我正确理解你的问题,我的解决方案是创建一个自定义弹出类。

public class Popup : Control 
{ 
    private class Const 
    { 
     public const int Height = 100; 
     public static Color BarFrameColor = SystemColors.ControlDark; 
     public static Color BarShadowColor = Color.Black; 
     public static Color BackColor = SystemColors.Info; 
     public static Color ForeColor = SystemColors.InfoText; 
    } 

    // [ gdi objects ] 
    private Bitmap m_bmp; 
    private Pen m_penShadow, m_penFrame; 

    private Panel panel; 
    private VScrollBar vScrollBar; 
    private Label lblText; 
    private bool scrolling; 

    public string Text 
    { 
     get 
     { 
      return lblText.Text; 
     } 
     set 
     { 
      lblText.Text = value; 
     } 
    } 

    public bool Scrolling 
    { 
     get 
     { 
      return this.scrolling; 
     } 
     set 
     { 
      this.scrolling = value; 
     } 
    } 

    public Popup() 
    { 
     this.Hide(); 
     this.ForeColor = Const.ForeColor; 
     this.BackColor = Const.BackColor; 
     this.Height = Const.Height; 

     this.panel = new Panel(); 
     this.panel.BackColor = Const.BackColor; 
     this.panel.Location = new Point(2, 2); 

     this.vScrollBar = new VScrollBar(); 
     this.vScrollBar.ValueChanged += new EventHandler(vScrollBar_ValueChanged); 

     this.lblText = new Label(); 
     this.lblText.Location = new Point(0, 0); 
     this.lblText.Text = ""; 

     this.panel.Controls.Add(lblText); 
     this.Controls.Add(vScrollBar); 
     this.Controls.Add(panel); 

     CreateGdiObjects(); 

     this.Scrolling = false; 
    } 

    private void CreateGdiObjects() 
    { 
     // [ gdi objects ] 
     this.m_penShadow = new Pen(Const.BarShadowColor); 
     this.m_penFrame = new Pen(Const.BarFrameColor); 
    } 

    protected override void OnParentChanged(EventArgs e) 
    { 
     base.OnParentChanged(e); 

     // [ calculate layout ] 
     this.Left = 0; 
     if (this.Parent != null) 
     { 
      this.Width = this.Parent.Width; 
      this.Top = this.Parent.Height - this.Height; 
     } 

     if (this.Scrolling) 
     { 
      this.vScrollBar.Size = new Size(12, this.Height - 4); 
      this.vScrollBar.Location = new Point(this.Width - 2 - this.vScrollBar.Width, 2); 

      this.panel.Size = new Size(this.Width - 4 - this.vScrollBar.Width, this.Height - 4); 
      this.vScrollBar.Minimum = this.panel.Top; 
      this.vScrollBar.Maximum = this.panel.Height; 
      this.vScrollBar.Visible = true; 

      this.lblText.Size = new Size(this.panel.Width, this.Height * 3); 
     } 
     else 
     { 
      this.panel.Size = new Size(this.Width - 4, this.Height - 4); 
      this.vScrollBar.Visible = false; 
      this.lblText.Size = this.panel.Size; 
     } 


     this.BringToFront(); 
    } 

    protected override void OnPaint(PaintEventArgs e) 
    { 
     // [ draw progress on memory bitmap ] 
     CreateMemoryBitmap(); 
     Graphics g = Graphics.FromImage(this.m_bmp); 
     DrawControl(g); 

     // [ blit to screen ] 
     e.Graphics.DrawImage(this.m_bmp, 0, 0); 
    } 

    protected override void OnPaintBackground(PaintEventArgs e) 
    { 
     // [ don't pass to base since we paint everything, avoid flashing ] 
    } 

    private void CreateMemoryBitmap() 
    { 
     // [ see if need to create bitmap ] 
     if (this.m_bmp == null || this.m_bmp.Width != this.Width || this.m_bmp.Height != this.Height) 
      this.m_bmp = new Bitmap(this.Width, this.Height); 
    } 

    private void DrawControl(Graphics g) 
    { 
     g.Clear(this.BackColor); 
     Rectangle rc = new Rectangle(0, 0, this.Width - 1, this.Height - 1); 
     g.DrawRectangle(this.m_penShadow, rc); 
     rc.Inflate(-1, -1); 
     g.DrawRectangle(this.m_penFrame, rc); 
    } 

    private void vScrollBar_ValueChanged(object sender, System.EventArgs e) 
    { 
     this.lblText.Top = -this.vScrollBar.Value; 
    } 
}