|
I thought i knew how to use Thread.Sleep until i made my own "SendKeys" class using the Win32 APIs. Below is my test code. What happens when it executes is that the Thread.Sleep delay occurs at the beginning followed by the 2 SendKeys statement. Clearly this is wrong. The intent is to execute the first SendKeys statement... pause... then execute the second SendKeys statement.
// focus textbox
this.txtTest.Focus();
// send key presses
KeysAuto keysAuto = new KeysAuto();
keysAuto.SendKeys("This is a test.{ENTER}Second Line.{ENTER}");
Thread.Sleep(1000);
keysAuto.SendKeys("This is a test #2.{ENTER}Second Line.{ENTER}");
I have been unsuccessful finding information about this oddness on the internet. Anyone had this problem and can shed some light on it for me?
|
|
|
|
|
This "oddness", as you call it, is because you don't understanding how Windows works.
You're using SendKeys to post keyboard messages (hint, hint) to your own form. OK, great! You've posted these messages, but since your very next statement puts your forms' execution thread to sleep, the message processing loop of your form (otherwise known as WndProc) can't process those messages, send the keystrokes to the TextBox, and let the TextBox repaint itself, until Thread.Sleep returns. As a quick'n'dirty "fix", you might want to let that stuff happen before you put your thread to sleep:
KeysAuto keysAuto = new KeysAuto();
keysAuto.SendKeys("This is a test.{ENTER}Second Line.{ENTER}");
Application.DoEvents();
Thread.Sleep(1000);
keysAuto.SendKeys("This is a test #2.{ENTER}Second Line.{ENTER}");
Application.DoEvents() will let your form process all pending messages before the next line executes.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
"I do not know until i know." --famous philosopher
You suggestion works! Your explanation makes it clear that the SendKeys class is sending new events to the MainForm, thus explaining the delay. I was just blind to it. I see the following things happening:
--Mainform function starts execution;
--SendKeys sends keypresses; new events are stored in execution cue;
--Thread.Sleep is executed;
--SendKeys sends keypresses; new events are stored in execution cue;
--Rest of Mainform function is executed;
--Form receives and handles newly made SendKeys events;
From what i read about DoEvents, it seems to make a form multi-threaded somewhat- frees up the UI during execution. Just like the good ole days of VB6!
|
|
|
|
|
redfish34 wrote: From what i read about DoEvents, it seems to make a form multi-threaded somewhat-
It's not multi-threaded at all. Application.DocEvents() just redirects the UI thread to executing the WndProc loop to process the messages, then when the message queue is empty, returns the thread to executing your code from the next line.
VB6 worked the exact same way...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I load a text document in listbox, no problem. the text file is loaded like a list, I mean, read string by string. the next step is print preview and print the listbox contents because the listbox contents and the text file are diffrent and the listbox has a temporal contens and this is my doubt, how can I show in the printpreviewdialog and printdialog the contents of my listbox??.
ץײגضزدجىعםىلـصزתﺼﺷבֿאּסּﺫﻅﻂ
|
|
|
|
|
In a usercontrol i create a ListView control with a handler for the click event. In this usercontrol i create a new form and i send the reference of my ListView to it and also attach it to the Controls of the form(Obs: my ListView control isn't in the Controls of my usercontrol, it's only created there).
At runtime when i select an item from the ListView the handler method is executed, then the form closes and when i reopen the form(with the same attached ListView) when i try to select an item the same handler method isn't executed(Obs: Before I close the form I erase the reference of the ListView from the Controls of the form so the dispose method won't affect it)
Code:
public class myusercontrol: System.Windows.Forms.UserControl
{
....
private void InitLv()
{
this.lv = new System.Windows.Forms.ListView();
lv.Click+=new EventHandler(lv_Click);
.......
}
private void lv_Click(object sender, System.EventArgs e)
{
.......//this method is executed only once
}
private void btn_drop_Click(object sender, System.EventArgs e)
{
MyForm popup = new MyForm ();
popup.AddLv(this.lv);
....
}
}
In MyForm:
...
public void AddLv(System.Windows.Forms.ListView lv)
{
this.SuspendLayout();
this.Controls.Add(lv);
this.ResumeLayout(false);
}
public void CloseForm()
{
RemoveLVTV();// this remove de lv from Controls
this.Close();
}
nycadr
|
|
|
|
|
When you thought your thread had not posted properly, did it not occur to CHECK before posting it 3 times?
|
|
|
|
|
In a usercontrol i create a ListView control with a handler for the click event. In this usercontrol i create a new form and i send the reference of my ListView to it and also attach it to the Controls of the form(Obs: my ListView control isn't in the Controls of my usercontrol, it's only created there).
At runtime when i select an item from the ListView the handler method is executed, then the form closes and when i reopen the form(with the same attached ListView) when i try to select an item the same handler method isn't executed(Obs: Before I close the form I erase the reference of the ListView from the Controls of the form so the dispose method won't affect it)
Code:
public class myusercontrol: System.Windows.Forms.UserControl
{
....
private void InitLv()
{
this.lv = new System.Windows.Forms.ListView();
lv.Click+=new EventHandler(lv_Click);
.......
}
private void lv_Click(object sender, System.EventArgs e)
{
.......//this method is executed only once
}
private void btn_drop_Click(object sender, System.EventArgs e)
{
MyForm popup = new MyForm ();
popup.AddLv(this.lv);
....
}
}
In MyForm:
...
public void AddLv(System.Windows.Forms.ListView lv)
{
this.SuspendLayout();
this.Controls.Add(lv);
this.ResumeLayout(false);
}
public void CloseForm()
{
RemoveLVTV();// this remove de lv from Controls
this.Close();
}
|
|
|
|
|
In a usercontrol i create a ListView control with a handler for the click event. In this usercontrol i create a new form and i send the reference of my ListView to it and also attach it to the Controls of the form(Obs: my ListView control isn't in the Controls of my usercontrol, it's only created there).
At runtime when i select an item from the ListView the handler method is executed, then the form closes and when i reopen the form(with the same attached ListView) when i try to select an item the same handler method isn't executed(Obs: Before I close the form I erase the reference of the ListView from the Controls of the form so the dispose method won't affect it)
Code:
public class myusercontrol: System.Windows.Forms.UserControl
{
....
private void InitLv()
{
this.lv = new System.Windows.Forms.ListView();
lv.Click+=new EventHandler(lv_Click);
.......
}
private void lv_Click(object sender, System.EventArgs e)
{
.......//this method is executed only once
}
private void btn_drop_Click(object sender, System.EventArgs e)
{
MyForm popup = new MyForm ();
popup.AddLv(this.lv);
....
}
}
In MyForm:
...
public void AddLv(System.Windows.Forms.ListView lv)
{
this.SuspendLayout();
this.Controls.Add(lv);
this.ResumeLayout(false);
}
public void CloseForm()
{
RemoveLVTV();// this remove de lv from Controls
this.Close();
}
nycadr
|
|
|
|
|
Hello to all,
I have to make RTP sreaming. By doing googling i foung oRTP library. This is build in C. I also found ortp.dll. But now i don't know how to use this dll in C#.net.
This dll is not a COM object. So, we can't add reference of this.
Plz help me.
Regards,
Divyang Mithaiwala
|
|
|
|
|
You can call into a C dll using P/Invoke (http://pinvoke.net). If the dll heavily uses STL, MFC, ATL or some other C++ library, your best bet might be to use C++/CLI to call the method.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
Hi!
I have a user control with a PictureBox control. This picturebox's image is data binded to a binary field in the database. When I set the image, it works fine: image is saved in the DB and everythings fine.
Now, when I want to CLEAR the image, I do the following:
this.picImage.Image.Dispose();
this.picImage.Image = null;
and...nothing happens. The next time I open the form, the image is still there. The binding is correct because if I change the bitmap, it is saved properly. It seems to be ignoring the null value Im trying to persist in the database.
I'm using Visual Studio 2005 and SQL Server 2005.
Help! Thanks in advance
|
|
|
|
|
How can i disable ALT+CTRL+DEL key of windows ?. Any links. Help me please
Jijo
-- modified at 9:02 Friday 17th February, 2006
|
|
|
|
|
|
Ok, you need a screwdriver, or a knife, or some other thin flat implement
put the thin end under the Alt key on your keyboard, and gently apply leaverage. The key should easily pop out. Repeat with the other alt key
Now do the same with both Ctrl keys
Finally repeat the process with the Del key (and also the other Del key on the numeric keypad, if the keyboard in question has one).
Include these instructions in the manual for your software, so that the end users can perform the same action.
--
Help me! I'm turning into a grapefruit!
Buzzwords!
|
|
|
|
|
Yeah, of all the ways to do it, sure, ASP.NET would offer the easiest approach!
Regards,
Nish
|
|
|
|
|
I would write a ASP.NET keyboard driver. That way, you will be able to handle any keystroke sequence.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
I am with benjymous, I think a screwdriver would definetly be involved in an elegant solution,of course a quick and nasty solution would involve a hammer and/or explosives.
Regards
Ray
"Je Suis Mort De Rire"
Blogging @ Keratoconus Watch
|
|
|
|
|
jijobaby wrote: How can i disable ALT+CTRL+DEL key of windows ?.
There are several hardware solutions for this:
1. Remove the keys from the keyboard.
2. If your keyboard is switch-based, remove those small switches. This way you can keep the keys on the keyboard.
3. Buy a custom-made keyboard without those keys.
4. Put a dongle on the keyboard connector. This has the advantage of keeping those keys working normally, but block that specific combination.
AFAIK, there's no software solution for this...
From the Churchdown Parish Magazine: "Would the Congregation please note that the bowl at the back of the Church, labelled 'For The Sick,' is for monetary donations only."
|
|
|
|
|
Daniel Turini wrote: AFAIK, there's no software solution for this...
He could use a Mac
--
Help me! I'm turning into a grapefruit!
Buzzwords!
|
|
|
|
|
C# isn't powerful enough. You need a proper language like Befunge 93[^].
The following listing should give you a start
<br />
0>:48*- #v_$>0145*p0>:045*p:48*1--#v_$7>44*>?< _$++++\1-:#^_v >>^ ><br />
^+1p*73\0:< ^+1 _v#`2g*73:<>:2/ :v >0\2/:^ v< ^"TWANG.."<<br />
145*g1+:145*p8 8*` #v_ $> > 44*>?< _$++++:37*g2`!#v_ > <br />
>7*p:37*g37*+p^vg*540+1g$#*73g<^$< <>0\2/:^v _v#!`g*540: < # >"rra ehT."^ <br />
^3\+1g*73::p*73< >+2*+p# 045*^ ^ < <>:045*g64*1-g-#v_^ >:#,_$$ ^<br />
C."*520<p*5400< ^56g*73:g*540:_^#-g*46g*540:_^# -g*2+56g*540:<# v"re A,B,<br />
A("25*""v>5*p ^v1$< >025*".niaga gniyrT .sevac gnikam pu dewercS"^>"iF :)CB<br />
A,B,C."<^ 41 < _^#:p*7303p*37\5p*37\5p*37\5p*37\4p*37\4p*37\4$<v2"(abc): Move<br />
*73g+2* 73:\g*73g+1*73:,*52.+1:g*540$_,#! #:<"Cave "0<$_,#! #:<*5<v30g*73g*46\g<br />
540_v#- g-1*46<v"bats."*25_v#g*5440p*54:p*54:p*54:p*5450p*5440p*54< v 4g*<br />
vv< > :045*g^>" raeh uoY">545*g!#v_25*".tfard "v>v #"Tunnels lead to:">#<6*g-<br />
20_v$_^#!-g+1*73g*540:g*541$_,#! #:<"You feel a" <,:>$":A",,045*g:65+2*g1v^,:*5<br />
1>>025*"!supmuw a l" v> `#v_v v_\$37*1++v^_^#v-1*46:,,"B:",*52.+< <br />
2v^ $_,#! #:<"You smel"<2v` 2:-"A"$< <!vg\g*540< >g1+.":C"25*,,,64*g1+.">"<br />
v>5*,,> ~:25*-!#v_:"a"-:^>#v_:01 vv0:<>`^>:045*p37*g: 4- #v_$025*"!tab tnaig a"<br />
<>_#"#^^# $<"0$ _v#!`-<> 1-^v$_,#! #:<"Yo" "u've been snatched by "<br />
"ni llef uoY...eeeeeeEEEEEE" "Y">:#,_$@0 >:2/: v> ^ <>5-#v_025*"!tip a ot"<br />
\37*g5-#v_ $> $$> $$>$ > >44*>?< _$++++: : 045*g\:145*g\:37*g<br />
" net"v">4-!#^_-!#^_-!#^_\0+# 45 *p#^ #1 #<v>0\2/:^#v541g *5\0< >"!supmuw a yb"<br />
:#,_$@>"ae neeb ev'uoY...PLUG" ^ >:#,_$^> > ^>*g-#^_025*>?>v>"llik uoY"><br />
>37*1++v^"You bumped the wumpus." ^#<^"ed the w"<<br />
v40<^"The crafty wumpus dodged your arrow" < "<br />
5>0\25*\#v_ #^ #<"!">?<u<br />
*^-g*5<="">".gnihtyna tih t'ndid wo"vv_$^v"s"< "<br />
>g\g14^>_v#" >:2/ :v "0< v<,: >"upm"^<br />
Ryan
O fools, awake! The rites you sacred hold
Are but a cheat contrived by men of old,
Who lusted after wealth and gained their lust
And died in baseness—and their law is dust.
al-Ma'arri (973-1057)
|
|
|
|
|
You could also put this in your licence agreement:
Pressing ctrl+alt+del while using this software you are agreeing that a ninja comes to your home and chops off your head.
Or you could send information to the server when the user preses ctrl+alt+del and then instruct the ninja to do his work. That way you don't have to ship a ninja with every copy of the software.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Anybody tried glue? No i don't mean to sniff it.... all you overdosers have a dirty mind!
|
|
|
|
|
What all these jokers are trying to say is what you want to do is just not possible in Windows...
We now return you to your regularly scheduled sarcasm.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It's probably not obvious that this thread was originally posted in the lounge, and got moved here (somewhat unnervingly!) - that's why it got the sarcastic replies
--
Help me! I'm turning into a grapefruit!
Buzzwords!
|
|
|
|
|