473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
2 5772
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
3
by: Ken | last post by:
I have a win 2000 database of autographs and scanned photos. They are in the SAME directory. In the table, my "ImagePath" text field shows JUST the image name (i.e. "blank.jpg"). I have an image...
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
5
by: Sue | last post by:
Help! I have an asp table with an embedded table. The asp tablerow that contains this table has a static ID assigned of "FilterRow2" (see snippets of code below). When I click on the button to set...
43
by: markryde | last post by:
Hello, I saw in some open source projects a use of "!!" in "C" code; for example: in some header file #define event_pending(v) \ (!!(v)->vcpu_info->evtchn_upcall_pending & \...
3
lwwhite
by: lwwhite | last post by:
Access 2003. I have a form (form view) with a subform (datasheet view). The form has a map_id field and each record on the subform also has a map_id field. I want the fields on the form and subform...
6
by: Uh Clem | last post by:
Is there a way to update form/control properties via VBA and have them still be there after the form is re-opened? When a textbox value is updated by the user, I need that value to be there next...
4
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.