Disabling a button on one form from another.
-
I have this button that I want disabled from a check box on a separate form. Its an options window and one option is to disable a certain button but the button is on the previous from. How can i disable the button from the form? I cant just start typing because it does not know the button exists. due to it being on another form.
Y*Live Long And Prosper*Y
-
I have this button that I want disabled from a check box on a separate form. Its an options window and one option is to disable a certain button but the button is on the previous from. How can i disable the button from the form? I cant just start typing because it does not know the button exists. due to it being on another form.
Y*Live Long And Prosper*Y
Raise an event in the form with the checkbox that the form with the button subscribes to.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
I have this button that I want disabled from a check box on a separate form. Its an options window and one option is to disable a certain button but the button is on the previous from. How can i disable the button from the form? I cant just start typing because it does not know the button exists. due to it being on another form.
Y*Live Long And Prosper*Y
You might want to delete the repost you made above this one before you get flamed for it! I think the CP servers had a bit of a fit a few minutes ago, so probably when you thought it hadn't submitted - it actually had.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
You might want to delete the repost you made above this one before you get flamed for it! I think the CP servers had a bit of a fit a few minutes ago, so probably when you thought it hadn't submitted - it actually had.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)yeah sorry lol I thought it didn't go through
Y*Live Long And Prosper*Y
-
I have this button that I want disabled from a check box on a separate form. Its an options window and one option is to disable a certain button but the button is on the previous from. How can i disable the button from the form? I cant just start typing because it does not know the button exists. due to it being on another form.
Y*Live Long And Prosper*Y
-
Can someone please be more specific? Im new to programming.
Y*Live Long And Prosper*Y
-
Can someone please be more specific? Im new to programming.
Y*Live Long And Prosper*Y
Working Example:
// FormButton.cs
using System;
using System.Windows.Forms;public partial class FormButton : Form
{
public FormButton()
{
InitializeComponent();
}private void FormButton\_Load(object sender, EventArgs e) { FormCheckBox formCheckBox = new FormCheckBox(); formCheckBox.CheckStateChanged += formCheckBox\_CheckStateChanged; formCheckBox.Show(); } void formCheckBox\_CheckStateChanged(object sender, CheckStateEventArgs e) { button1.Enabled = e.IsChecked; }
}
// FormCheckBox.cs
using System;
using System.Windows.Forms;public partial class FormCheckBox : Form
{
public event EventHandler<CheckStateEventArgs> CheckStateChanged;
public FormCheckBox()
{
InitializeComponent();
}private void checkBox1\_CheckStateChanged(object sender, EventArgs e) { OnCheckStateChanged(new CheckStateEventArgs(checkBox1.Checked)); } protected virtual void OnCheckStateChanged(CheckStateEventArgs e) { EventHandler<CheckStateEventArgs> eh = CheckStateChanged; if (eh != null) eh(this, e); }
}
// CheckStateEventArgs.cs
public class CheckStateEventArgs : EventArgs
{
public CheckStateEventArgs(bool isChecked)
{
IsChecked = isChecked;
}
public bool IsChecked
{
get;
private set;
}
}Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
I've already read that DaveyM69 has explained to you how to use events/delegates for solving your problem.But sometimes you need to notify other instances of your app for something important.In this case events and delegates are not useful,because you can't get valid pointers of the forms belonging to another instance of the app.In this case you have to use custom WM messages.To register custom WM message call RegisterWindowMessage native function. And to send message call SendMessage native function passing HWND_BROADCAST value for hWnd parameter.But this function doesn't seem to work with child windows,but it works with hidden top windows for example. But be careful with that option-it could damage OS performance.