473,405 Members | 2,282 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,405 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 5780
"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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.