Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kate18

How do windows talk to each other?

This topic is 5420 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have made a small app and I am trying to make this slider bar work. What I want to happen is from my main apps main menu there is a button called opacity. When clicked I would like it to open another form with a track bar on it that controls the main apps opacity. Is this possible? So far when I click on the opacity button, a new window opens with the trackbar on it but i cant work out how to connect the opacity control bit. The code to open the trackbar window is private void menuItem7_Click(object sender, System.EventArgs e) { opacity d = new opacity(); d.ShowDialog(); } Can 2 forms access each others properties? Thanks heaps for any info, Kate Oh, I''m using vc#

Share this post


Link to post
Share on other sites
Advertisement
Probably the easiest way to do this is to have the track bar control on the second form have an event handler for it''s Scroll event that updates a public variable in the second form. Then if ShowDialog() returns ok, just read the variable in your menu item event handler.

Share this post


Link to post
Share on other sites
What I''d do is to pass the "this" pointer to the second form
and register it to the ValueChanged event handler of the
trackbar.

So the code would look something like this:


// In main form

private void menuItem7_Click(object sender, System.EventArgs e)
{
opacity d = new opacity(this);
d.ShowDialog();
}

public void trackbar_ValueChanged(object sender, System.EventArgs e)
{
// Change main form opacity here

}

// In the opacity form

opacity(Form parent)
{
InitializeComponents();

m_TrackBar.ValueChanged += System.Eventhandler(parent.trackbar_ValueChanged);
}


This method allows "live" update of the opacity as the track
bar is being dragged.

I hope this helps.




Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites
Cool, Thanks guys
That code you wrote you wrote tangentz worked great.
Cheers


A friend of mine helped me get this working at her place but now i'm home trying to do it but it doesn't work.
Whats happening is that when i try to use parent in the opacity forms constuctor it doesnt give me access to the event code that controls the main forms opacity.
eg

public opacity(Form parent)
{
InitializeComponent();
// if i use parent. here, i only have access to the "form" classes members and not the members of my main app even though we pass "this" to the constructor.
}

Does that make sense?


[edited by - Kate18 on January 15, 2004 6:13:20 AM]

Share this post


Link to post
Share on other sites
Right, you can downcast to the main form to use its methods.


public opacity(Form parent)
{
InitializeComponent();
MainForm f = (MainForm) parent; // Downcast to MainForm
f.DoSomething(); // USe MainForm''s methods
}


Or, just pass in the parent as a MainForm.


public opacity(MainForm parent)
{
InitializeComponent();
parent.DoSomething(); // USe MainForm''s methods
}





Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!