|
Hi George,
electriac wrote: the new form will not receive input unless I click on it
I don't think this is correct. What probably happened is the Control with the lowest TabIndex isn't the one you want it to be. Try playing around with TabIndex (and check TabStop is still at its default value of true).
If all that does not help, experiment with Focus, Activate, BringToFront inside the Shown handler, the constructor is too soon for these.
Regards,
|
|
|
|
|
Tried delaying commands with a timer. NG. Unless I click on the form the IR commands are written to my source code. So the compiler is the active form.
|
|
|
|
|
electriac wrote: the compiler is the active form
Each WinForm application has an active window; what you are saying is somehow your IDE (Visual Studio?) is active instead of your app itself. That is abnormal; what do you do to make your app run? what language is it in? it is a WinForm app isn't it? what happens when you run your app by double-clicking its exe (in bin/debug/ or in bin/release/ subfolders)?
BTW: within the app, i.e. assuming your app has focus, it is the Shown event you want, not a timer!
|
|
|
|
|
I am compiling and executing with CTRL F5 it is a standard windows form in C#. I will have to look into executing outside the compiler.
TNX Luc
|
|
|
|
|
I don't know how useful this may be, as I'm a total newbie to C#, but I'm working tonight on the exact same situation - a form creating a form - and mine's working perfectly. The only difference I see is that, rather than passing a value in the new statement, I'm initializing that value in a separate statement immediately after, ie:
Form2 dlg = new Form2();
dlg.temp = fname;
if(dlg.ShowDialog()==DialogResult.OK)
{ ...
This assumes that Form2 defines a public member temp, of course. I have no idea why it would make a difference, but it just might.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
electriac wrote: Unfortunatly the new form will not receive input
What do you mean by this ? Do you have a textbox in your form that doesn't receive what you type on the keyboard as soon as the form is opened? You may have to set its TabIndex property to 0 and TabStop to true .
|
|
|
|
|
There is no TabIndex or TabStop as the form is receiving input from an IR controller as a keydown event.
|
|
|
|
|
I don't know if I fully understand your question. But in windows applications, only the active control with the keyboard focus can receive keyboard events. You need to set focus to the textbox (or whatever your control is) before you can send keystrokes to the control.
|
|
|
|
|
Update:
I have done some more experimenting and find the following. When the program is executed outside the compiler the child Form2 is created but the focus remains on Form1. When compiled with CTRL F5 the focus goes to the compiler.
Here is where Form2 is created: Form2=playMKV
Application.RemoveMessageFilter(this);
if (temp.EndsWith(".mkv")) // its a Matroska file
{
playMKV dlg = new playMKV(fname);
//if (dlg.ShowDialog() == DialogResult.OK) // not necessary as there will always be a result 1 or 0;
dlg.ShowDialog();
if (dlg.Number == 1)
{
string temp2 = "\x22" + fname + "\x22";
System.Diagnostics.Process proc =
System.Diagnostics.Process.Start("mplayerc.exe", temp2 + " /fullscreen /play /close ");
proc.WaitForExit();
}
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
Application.AddMessageFilter(this);
return;
}
I have tried delaying the this.Focus in Form2 as Luc suggested and it seems to make no difference.
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
this.Focus();
this.Activate();
this.BringToFront();
}
This Form2 closes on any keydown event there being two options:
1.the "Enter" key is hit or "Enter" is pressed on the IRcontroller in which case the key event is == 13 returning 1 to Form1
or
2.on any other key the Form2 is closed returning 0;
Form2 keydownevent
if (keyEvent.KeyValue == 13)
{
num = 1;
}
else
{
num = 0;
}
this.Close();
The program works without problem as long as I click on Form2 with the mouse.
|
|
|
|
|
Shameel
TNX for your input as it allowed me to solve the problem. I added an event handler to the listBox on Form2 and the focus was gained by the form.
TNX again.
|
|
|
|
|
Is there a reason you use Application.RemoveMessageFilter(this) ?
|
|
|
|
|
Yes. The message filter seems to stop the Form2 from receiving the IR commands. Although I have not test without it since implementing the newest changes.
|
|
|
|
|
I checked and the keydown event goes to the parent form and not the child unless the Message Filter is removed.
|
|
|
|
|
Hi
Do you know, if there exist a code (application), that capture all the text from the keyboard? Application should not be seen, so it should run in tray, like a hiden application, but it still capture all the text.
If you don't konw if that kind of application exists, maybe you have some suggestions how to made it.
Thnx
|
|
|
|
|
Write a global keyboard hook - here's[^] one example.
/ravi
|
|
|
|
|
such apps are evil.
|
|
|
|
|
Yeah, it's called a keylogger and NO we're not going to tell you how to write one.
|
|
|
|
|
Hi
I have a gridview that get it's data from a dataset;
I add a checkbox to this gridview as culumn;
now my user can choose each row;
How can i recognize that checkboxes that have checked by user and other value of that checked rows?
|
|
|
|
|
|
I almost lost some money today on a bet with a colleague arguing that the following Java code was just plain invalid.
if( this_thing == DING & that_thing == DONG ) {
thenGoDoTheOtherThing();
} Fortunately, he did not take me up on the bet! Turns out, for both Java and C#, when the & operator is used in this context the compiler stops treating it as the bitwise AND operator. Instead it treats it like the logical AND operator (&& ) except that it applies a slightly modified evaluation rule - where && stops evaluation as soon as it encounters the first expression that evaluates to false , & goes ahead and evaluates all the expressions regardless of what each component expression evaluates to. The logical AND still works as one might expect, just that all the component expressions are always evaluated. Here's an example:
class Program
{
static void Main(string[] args)
{
if (Eval1() & Eval2())
Console.WriteLine("Eval1() and Eval2() returned true.");
else
Console.WriteLine("Eval1() and/or Eval2() returned false.");
}
static bool Eval1()
{
Console.WriteLine("Eval1");
return false;
}
static bool Eval2()
{
Console.WriteLine("Eval2");
return true;
}
} And here's the output you get.
Eval1
Eval2
Eval1() and/or Eval2() returned false. Guess you learn something new everyday! I am not sure that using this feature is such a great idea though. Thoughts?
modified on Friday, December 4, 2009 3:31 PM
|
|
|
|
|
IMO, that it doesn't do the short circuit evaluation means that it actually is a bitwise AND, between two bools, but that doesn't make it any less "bitwise" or "AND", a bool is just 0 or 1 with nicer names after all..
|
|
|
|
|
Yep, it does indeed still do a bitwise AND of the boolean operands. See my reply[^] to OriginalGriff[^]'s post below.
|
|
|
|
|
Fortunately it should only work if (as in your example) both the parameters are bool - as it then performs a bitwise AND of the two results. Hence why it evaluates both rather than stopping when one fails.
It's still quite nasty though - I wonder if you can turn it off...
if ((dataTable.Rows != null) & (dataTable.Rows.Count > 0))
{
...
} would throw exactly the exception you are testing to avoid!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
"Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
|
|
|
|
|
Yes. It does still perform a bitwise AND of the 2 boolean operands. Here's the IL for the sample code:
L_0000: call bool ConsoleApplication1.Program::Eval1()
L_0005: call bool ConsoleApplication1.Program::Eval2()
L_000a: and
L_000b: brfalse.s L_0018
L_000d: ldstr "Eval1() and Eval2() returned true."
L_0012: call void [mscorlib]System.Console::WriteLine(string)
L_0017: ret
L_0018: ldstr "Eval1() and/or Eval2() returned false."
L_001d: call void [mscorlib]System.Console::WriteLine(string)
L_0022: ret And I agree, it does seem to be a fairly dangerous operator. I'd be surprised if somebody deliberately used it with this explicit intent - chances are, in a majority of the cases its occurrence is a typo - and something the compiler won't even alert you about.
|
|
|
|
|
That is what the documentation says:
"Binary & operators are predefined for the integral types and bool. For integral types, & computes the logical bitwise AND of its operands. For bool operands, & computes the logical AND of its operands; that is, the result is true if and only if both its operands are true.
The & operator evaluates both operators regardless of the first one's value."
And now you can go and test/read up on the | operator...
|
|
|
|