Mickey Haynes said:
Essentially, we are trying to recreate a modal form on the compact
framework. We want to create an application in which two forms will be open
at one time, a parent and a floating toolbar. The user must be able to see
and use either form without closing the other. The toolbar must be moveable
and must float over the parent form. This is similar to the way the SIP
works.
There are a few issues:
1) how to resize a form?
2) how to keep two forms open and visible at one time?
Easy to do in regular .NET, difficult in CF. Any ideas? Is eVC the only
option?
I believe I've got an answer to your request, and it's completely
managed to boot. There are a few issues involved.
First, as far as I know the only way to make a S.W.F.Form smaller than
full screen is to set FormBorderStyle = FormBorderStyle.None, then set
MinimizeBox, MaximizeBox, and ControlBox to false. This gives you a
floating window that looks kinda like a MessageBox. Unfortunately, it
also has no title bar and can't be moved, at least not as-is. So,
what I did is created a panel that mimics a titlebar and gave it some
simple drag capabilites. For the record, I take little credit for all
this. Most if not all the ideas were out there, I just put them
together.
Notes:
The basic idea for the window movement capability is to detect
MouseDown on the title panel, and if the MouseMove event occurs while
it's down, then change the parent form's location.
Since the form has no border, I manually draw a 1-pixel black line
around the entire form.
I split the form into the TitleBarPanel and a content panel. During
movement, I set the content panel's Visible property to false for best
performance and to minimize graphics funkiness.
I cleaned the code up a bit, but no guarantees. Still, it oughta be
pretty close to what you're looking for. Hope it helps!
Mark Erikson
So, with that said, code follows:
public class FloatingDialog : System.Windows.Forms.Form
{
protected TitleBarPanel titlePanel;
internal System.Windows.Forms.Panel backPanel;
protected Pen penblack;
protected bool moving;
public FloatingDialog(PocketHTMLEditor phe)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.Parent = phe;
this.app = phe;
moving = false;
penblack = new Pen(Color.Black);
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.titleLabel = new System.Windows.Forms.Label();
this.backPanel = new System.Windows.Forms.Panel();
this.titlePanel = new TitleBarPanel("Find");
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.ControlBox = false;
this.MinimizeBox = false;
this.MaximizeBox = false;
titleLabel.Top = 0;
this.titlePanel.Bounds = new Rectangle(0, 0, this.Width, 16);
this.titlePanel.BackColor =
System.Drawing.SystemColors.ActiveCaption;
this.Controls.Add(titlePanel);
this.backPanel.Location = new System.Drawing.Point(1, 16);
this.backPanel.Size = new System.Drawing.Size(this.Width,
this.Height - titleLabel.Height - 1);
this.Controls.Add(this.backPanel);
}
internal bool Moving
{
get
{
return moving;
}
set
{
moving = value;
backPanel.Visible = !moving;
}
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
if(!titlePanel.mouseDown)
{
base.OnPaint (e);
}
Rectangle r = this.ClientRectangle;
r.Height -= 1;
r.Width -=1;
g.DrawRectangle(penblack, r);
}
} // end FloatingDialog
public class TitleBarPanel : System.Windows.Forms.Panel
{
internal bool mouseDown=false;
internal Point oldPoint=Point.Empty;
protected System.Windows.Forms.Label titleLabel;
public TitleBarPanel(string title)
{
this.titleLabel.Font = new System.Drawing.Font("Tahoma", 9F,
System.Drawing.FontStyle.Bold);
this.titleLabel.ForeColor = System.Drawing.Color.White;
this.titleLabel.Location = new System.Drawing.Point(4, 4);
this.titleLabel.Size = new System.Drawing.Size(100, 16);
this.titleLabel.Text = title;
}
override protected void OnMouseDown(MouseEventArgs e)
{
mouseDown=true;
oldPoint=new Point(e.X,e.Y);
((FloatingDialog)this.Parent).Moving = true;
}
override protected void OnMouseMove(MouseEventArgs e)
{
if (mouseDown)
{
int dx,dy;
dx=e.X-oldPoint.X;
dy=e.Y-oldPoint.Y;
this.Parent.Location=new
Point(this.Parent.Left+dx,this.Parent.Top+dy);
this.Parent.Parent.Refresh();
}
}
override protected void OnMouseUp(MouseEventArgs e)
{
mouseDown=false;
((FloatingDialog)this.Parent).Moving = false;
this.Parent.Refresh();
}
} // end TitleBarPanel