|
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.
DaveBTW, 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.
DaveBTW, 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
|
|
|
|
|
You could do it using events or delegates or custom WM messages
|
|
|
|
|
Can someone please be more specific? Im new to programming.
Y*Live Long And Prosper*Y
|
|
|
|
|
Working Example:
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;
}
}
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);
}
}
public class CheckStateEventArgs : EventArgs
{
public CheckStateEventArgs(bool isChecked)
{
IsChecked = isChecked;
}
public bool IsChecked
{
get;
private set;
}
}
DaveBTW, 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.
|
|
|
|
|
I'm not sure how much code you need to see to handle this problem.
I am trying to add the ability for any logged-on client to send a message to all other logged-on clients.
My server code looks like this:
public OedipusServer
{
bool ensureSecurity = true;
RemotingConfiguration.Configure("oedipus.exe.config", ensureSecurity);
UserList insUserList = UserList.Instance;
ObjRef refUserList = RemotingServices.Marshal(insUserList, "UserList");
...
ServerClass insServerClass = ServerClass.Instance;
ObjRef refAServerClass = RemotingServices.Marshal(insServerClass, "Messaging");
}
public class ServerClass : AbstractServer
{
private static ServerClass mInstance = null;
public static ServerClass Instance
{
get
{
if (mInstance == null)
mInstance = new ServerClass();
return mInstance;
}
}
public override Object InitializeLifetimeService()
{
return null;
}
public override void myStatusHasChanged(int userID, int newStatus)
{
FireNewBroadcastedMessageEvent(userID, newStatus);
}
public event StatusChangedEventHandler myStatusChangedHandler;
public override event StatusChangedEventHandler myStatusChangedEvent
{
add
{
myStatusChangedHandler = value;
}
remove
{
}
}
protected void FireNewBroadcastedMessageEvent(int userID, int newStatus)
{
myStatusChangedHandler(userID, newStatus);
}
}
I have another project, Messaging, which looks like this:
public delegate void StatusChangedEventHandler(int userID, int newStatus);
public abstract class AbstractServer : MarshalByRefObject
{
public abstract void myStatusHasChanged(int userID, int newStatus);
public abstract event StatusChangedEventHandler myStatusChangedEvent;
}
public abstract class AbstractBroadcastedMessageEventSink : MarshalByRefObject
{
public void callbackStatusChanged(int userID, int newStatus)
{
internalCallbackStatusChanged(userID, newStatus);
}
protected abstract void internalCallbackStatusChanged(int userID, int newStatus);
}
On the client side I have:
class EventSink : AbstractBroadcastedMessageEventSink
{
protected override void internalCallbackStatusChanged(int userID, int newStatus)
{
}
}
private AbstractServer rmMessaging;
public Office()
{
rmMessaging = (AbstractServer)Activator.GetObject
(typeof(AbstractServer),
System.Configuration.ConfigurationManager.AppSettings
["AbstractServerUrl"]);
EventSink sinkStatusChanged = new EventSink();
rmMessaging.myStatusChangedEvent +=
new StatusChangedEventHandler(sinkStatusChanged.callbackStatusChanged);
}
private void button1_Click(object sender, EventArgs e)
{
rmMessaging.myStatusHasChanged(23, 14);
}
It's subscribing to the event which raises the runtime error "DelegateSerializationHolder is not permitted to be deserialized at this security level".
|
|
|
|
|
It seems your remoting configuration is not correct.This stuff might help you to solve your the problem.
|
|
|
|
|
Thanks. I found another article which discussed the problem and offered the solution of using a wrapper class. It still didn't work until I realised that I couldn't use tcp.
Adding a separate channel using http/Soap/Singleton (as your article states) solved the problem.
So I have a tcp channel for my data-access and an http channel for braodcasting messages.
|
|
|
|
|
At the risk of sparking of hilarious ridicule, can I get a ListView Control which mirrors the content of another?
I have a listview which is populated and another 'blank' (unitilialised) listview which I need to 'mirror' the first.
Any pointers welcomed.
|
|
|
|
|
Well what ever you do with the first one, just do it to the second one at the same time
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hello. This is my problem:
try
{
Application.Run(new Form1());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
In Debug-Mode (F5), if exception is thrown, then it goes to catch block.
In Release-Mode (Ctlr-F5), if exception is thrown, then it shows "unexpected exception" from windows. Catch block is not called.
How can I catch unexpected exception in Release-Mode ?
Thanks.
|
|
|
|
|
There's a special event that gets triggered whenever there's an unhandled exception. Your application could subscribe to the Application.ThreadException [^]-event.
Something like this (adapted from the MSDN-example, not tested);
{
Application.ThreadException += new ThreadExceptionEventHandler(MyErrorHandler);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.Run(new Form1());
}
private static void MyErrorHandler(object sender, ThreadExceptionEventArgs t)
{
ShowMessage(t.ToString());
}
I are Troll
|
|
|
|
|
|
Hey!
How can i close Firefox?
|
|
|
|
|
Enumerate all the processes using the GetProcesses method, and if you find FF, terminate it. Take a look at the Process [^]-class
I are Troll
|
|
|
|
|
May I politely ask why do you want to close FF from your program? What kind of program are you writing?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
i want to make a Firefox Pw Viewer.
And for that i will close the FF before i open the Firefox Pw Viewer.
|
|
|
|
|
Firefox keeps a lock on the bookmarks database, and needs to be closed for some bookmark readers to work. I'm not certain, but I think that something similar would be in effect for the passwords database
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
I look for a code!
And then i will close the FF prozess
|
|
|
|
|
PC17 wrote: I look for a code!
Sorry for posting an answer instead of real code
I are Troll
|
|
|
|
|
What do you say to this Code?
//using System.Diagnostics;
Process[] pp = Process.GetProcessesByName("ttermpro");
foreach (Process p in pp)
{
p.CloseMainWindow();// Normales ende
//p.Kill(); sofort beenden
}
instead of "ttermpro" "firefox.exe"
|
|
|
|
|
Sieht gut aus!
Well done
|
|
|
|