By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,667 Members | 2,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,667 IT Pros & Developers. It's quick & easy.

how to make a form "stick" to another window?

P: n/a
Hi,

How do we make a form "stick" to another window (something like Winamp)?

I'm using C# .NET 2003.

Thank you very much.
Marty
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Marty" <xm******@hotmail.com> skrev i meddelandet
news:opmef.196944$ir4.50531@edtnps90...
How do we make a form "stick" to another window (something like Winamp)?

I'm using C# .NET 2003.


Here's a "stripped down" example on how you can do it.

The key to this solution is to have them have references to each other.

When form1 changes size or location it calls a method in form2 to adjust the
location of that form.
public class Form1 : System.Windows.Forms.Form
{
private Form2 form2 = null;

public Form1()
{
InitializeComponent();
form2 = new Form2(this);
}

// ...

private void InitializeComponent()
{
// ...
this.SizeChanged += new
System.EventHandler(this.Form1_LocationChanged);
this.LocationChanged += new
System.EventHandler(this.Form1_LocationChanged);
// ...
}

private void Form1_LocationChanged(object sender, System.EventArgs e)
{
form2.AdjustToForm1();
}
}

public class Form2 : System.Windows.Forms.Form
{
private Form1 form1 = null;

public Form2(Form1 m)
{
form1 = m;
InitializeComponent();
AdjustToForm1();
}

// ...

internal void AdjustToForm1()
{
this.Left = form1.Left;
this.Top = form1.Bottom;
this.Width = form1.Width;
this.Refresh();
}

private void Form2_Load(object sender, System.EventArgs e)
{
AdjustToForm1();
}
}

// Bjorn A
Nov 17 '05 #2

P: n/a
Hi Bjorn,

Thank you for your fast reply, very useful.
Have a nice day!
Marty

Bjorn Abelli wrote:
"Marty" <xm******@hotmail.com> skrev i meddelandet
news:opmef.196944$ir4.50531@edtnps90...

How do we make a form "stick" to another window (something like Winamp)?

I'm using C# .NET 2003.

Here's a "stripped down" example on how you can do it.

The key to this solution is to have them have references to each other.

When form1 changes size or location it calls a method in form2 to adjust the
location of that form.
public class Form1 : System.Windows.Forms.Form
{
private Form2 form2 = null;

public Form1()
{
InitializeComponent();
form2 = new Form2(this);
}

// ...

private void InitializeComponent()
{
// ...
this.SizeChanged += new
System.EventHandler(this.Form1_LocationChanged);
this.LocationChanged += new
System.EventHandler(this.Form1_LocationChanged);
// ...
}

private void Form1_LocationChanged(object sender, System.EventArgs e)
{
form2.AdjustToForm1();
}
}

public class Form2 : System.Windows.Forms.Form
{
private Form1 form1 = null;

public Form2(Form1 m)
{
form1 = m;
InitializeComponent();
AdjustToForm1();
}

// ...

internal void AdjustToForm1()
{
this.Left = form1.Left;
this.Top = form1.Bottom;
this.Width = form1.Width;
this.Refresh();
}

private void Form2_Load(object sender, System.EventArgs e)
{
AdjustToForm1();
}
}

// Bjorn A

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.