Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to create modal, SIP-like control?

13 views
Skip to first unread message

Mickey Haynes

unread,
Aug 13, 2003, 2:51:30 PM8/13/03
to
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?


Jim Wilson

unread,
Aug 13, 2003, 6:58:12 PM8/13/03
to
All .NET CF Forms are fullsize, not resizable unfortunatly.

Jim Wilson, eMVP
http://www.jwhh.com
http://www.develop.com

"Mickey Haynes" <mickey...@hotmail.com> wrote in message
news:#hLEtvcY...@TK2MSFTNGP10.phx.gbl...

Mark Erikson

unread,
Aug 13, 2003, 9:03:20 PM8/13/03
to
"Mickey Haynes" <mickey...@hotmail.com> wrote in message news:<#hLEtvcY...@TK2MSFTNGP10.phx.gbl>...

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

Chris Tacke, eMVP

unread,
Aug 14, 2003, 9:46:14 AM8/14/03
to
Suffix that with "on the Pocket PC". It's not true for 4.x devices.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

"Jim Wilson" <ji...@jwhh.com> wrote in message
news:O28605e...@TK2MSFTNGP10.phx.gbl...

Mickey Haynes

unread,
Aug 14, 2003, 3:44:13 PM8/14/03
to
You da man! Very cool... Had to make a few tweaks, but all in all, looks
like this will work. I'll try to post the code in a few days when we have
it perfected. Thanks for your help!

"Mark Erikson" <marku...@yahoo.com> wrote in message
news:4d3df955.03081...@posting.google.com...

Jim Wilson [eMVP]

unread,
Aug 13, 2003, 4:12:33 PM8/13/03
to
That is cool solution - excellent!!

"Mark Erikson" <marku...@yahoo.com> wrote in message
news:4d3df955.03081...@posting.google.com...

Mickey Haynes

unread,
Aug 15, 2003, 11:52:03 AM8/15/03
to
Another, slightly easier way to do it is to set the FormBorderStyle to
FixedToolWindow. Try the code below:

Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class ToolbarForm
Inherits System.Windows.Forms.Form
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button

Public Sub New(ByVal parent As Form, ByVal name As String, ByVal
location As Point, ByVal size As Size)
MyBase.New()

InitializeComponent()

Me.Parent = parent

Me.FormBorderStyle = FormBorderStyle.FixedToolWindow
Me.ControlBox = False
Me.MinimizeBox = False
Me.MaximizeBox = False

Me.BringToFront()
Me.BackColor = Color.Green

Me.Size = size
Me.Text = name
Me.Location = location
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(160, 8)
Me.Button1.Text = "Hide Me"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(16, 8)
Me.Button2.Size = New System.Drawing.Size(104, 20)
Me.Button2.Text = "Do Something"
'
'Form5
'
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Hide()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox("something done")
End Sub
End Class

Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Private m_toolBarForm As ToolbarForm

Public Sub New()
MyBase.New()

InitializeComponent()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

Friend WithEvents Button2 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 48)
Me.Button1.Size = New System.Drawing.Size(100, 20)
Me.Button1.Text = "Open toolbar"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(136, 48)
Me.Button2.Text = "Say Hey"
'
'Form1
'
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Menu = Me.MainMenu1
Me.Text = "Form1"

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If m_toolBarForm Is Nothing Then
m_toolBarForm = New ToolbarForm(Me, "Toolbar", New
Point(Me.Left, Me.ClientRectangle.Bottom - 100), New Size(Me.Width, 100))
End If
m_toolBarForm.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox("Hey")
End Sub
End Class

"Mark Erikson" <marku...@yahoo.com> wrote in message
news:4d3df955.03081...@posting.google.com...

0 new messages