Floating Form - Always on Top

G

Guest

Hello

I have a windows form that I would like to float on top of another form so I
set the TopMost property as follows:

m_F_WorkHistory.TopMost = True

But when I try to inertact with the calling form, the m_F_WorkHistory form
disappears. The form is to be used to help fill out the parent form.

Is there anything else I need to do? Am I missing something?

Thanks in advance.
Tom

(e-mail address removed)
 
M

Mark Broadbent

Pass. You would need to supply more code, however see the following I
knocked up quickly which doesnt display that unexpected behaviour. Create
two class files to a empty windows forms project.
//**********************************
//Under.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace KeepOneFormTopMost
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Under : System.Windows.Forms.Form
{
private System.Windows.Forms.Button buttonOpenForm;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Under()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonOpenForm = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonOpenForm
//
this.buttonOpenForm.Location = new System.Drawing.Point(192, 224);
this.buttonOpenForm.Name = "buttonOpenForm";
this.buttonOpenForm.TabIndex = 0;
this.buttonOpenForm.Text = "Open Form";
this.buttonOpenForm.Click += new
System.EventHandler(this.buttonOpenForm_Click);
//
// Under
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.buttonOpenForm);
this.Name = "Under";
this.Text = "Under Form";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Under());
}

private void buttonOpenForm_Click(object sender, System.EventArgs e)
{
Upper f = new Upper();
f.TopMost = true;
f.Show();
}
}
}

//*************************************
//Upper.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace KeepOneFormTopMost
{
/// <summary>
/// Summary description for Upper.
/// </summary>
public class Upper : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Upper()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Upper
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Upper";
this.Text = "Upper Form";

}
#endregion
}
}

--
Best Regards,

Mark

Mark Broadbent

mcad,mcdba,mcse+i
emailto: newsgroupsATmettayyaDOTgotadslDOTcoDOTuk
remove AT with '@' and DOT with '.' -please do not send spam or address will
be changed!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top