473,326 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

virtual key board as a form

11
Hello i am new to c#
please help me for the following problem

Que:

i have one form application with few buttons say app1 on it
and two another form application with textbox in it say app2 and app3
now i need to type in app2's or app3 's textbox using those buttons on app1
how can i know which is active among app2 and app3.
and how can i tell app1 abt which text box is in focus in the active application

thanks in advance
Feb 19 '10 #1
17 7392
tlhintoq
3,525 Expert 2GB
How do I get my Form2 to react to something on my Form1?
How do I make my Form1 control something on my Form2?
Although you can have Form1 directly access items on Form2 it isn't the recommended way to go. It ties the two forms tightly to each other. If a change is made in Form2 such as removing one of the controls, then code in Form1 breaks.
It is better to Form1 raise an event, and have Form2 contain its own code for how to react to this. This places responsibility for Form2 within Form2, and Form1 within Form1.
It keeps Form1 blissfully ignorant of Form2 - and a logging component - and a progress component, and a dozen other little black boxes that can be subscribed to events in Form1, all without Form1 being made responsible for directly affecting controls other than itself.
Events tutorial (including Form to Form which is the same as class to class)

Your question title indicates you are trying to make a virtual keyboard. This tutorial for a cash register does exactly that: It makes a virtual numeric keyboard. The only difference is that you will need another 100 keys.
Feb 19 '10 #2
nayanar
11
my problem is like this

i have two different application like on-screen keyboard and excel sheet

in my problem i have:
1st application: form with number buttons.
2nd application: few forms with many texboxes in each.

now i need to fill those text boxes with number using 1st application

i want to how will 1st application know which text box of which form is having cursor and how will it send the data to it. i think it require knowledge of win32 api calls and all. which i very little idea. can u help me out in this .

thanks in advance
Feb 24 '10 #3
tlhintoq
3,525 Expert 2GB
Are the two programs ones you have written?
If so, you can code in some methods for the two to communicate with each other.
Feb 24 '10 #4
nayanar
11
no they are two different applications....just like a notepad and one screen keyboard. different solution itself.
Feb 25 '10 #5
he meant if you wrote the code of both of the applications?
Feb 25 '10 #6
nayanar
11
yes i have written the code. But i need to know how to find which application is active and how to send value to the it
Feb 25 '10 #7
nayanar
11
here is code of application where i have to write

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10.  
  11. namespace simple_wind_fow
  12. {
  13.     public partial class simpleform3 : Form
  14.     {
  15.         public simpleform3()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         private void textBox1_Enter_1(object sender, EventArgs e)
  20.         {
  21.  
  22.  
  23.         }
  24.         private void textBox2_Enter(object sender, EventArgs e)
  25.         {
  26.  
  27.         }
  28.  
  29.         private void simpleform3_Click(object sender, EventArgs e)//when clicked on that window
  30.         {
  31.             textBox1.Focus();
  32.         }
  33.  
  34.  
  35.     }
  36. }
Feb 25 '10 #8
nayanar
11
this is the second application where is need to find active application and send value to it , when ever button is pressed

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10.  
  11. namespace button
  12. {
  13.     public partial class keyboard : Form
  14.     {
  15.         public keyboard()
  16.         {
  17.             InitializeComponent();
  18.         }       
  19.  
  20.         private void button1_Click(object sender, EventArgs e)
  21.         {
  22.            //find the active application
  23.             //send value "1" to that application
  24.         }
  25.         private void button2_Click(object sender, EventArgs e)
  26.         {
  27.             //find the active application
  28.             //send value "2" to that application
  29.         }
  30.  
  31.     }
  32.  }
Feb 25 '10 #9
nayanar
11
they are two different application which are two different exe file
Feb 25 '10 #10
nayanar
11
please do help. Its kind of urgent requirement
Feb 25 '10 #11
SendKeys.Send(Keys.Enter.ToString()); will send the "Enter" key for example to the currently Active form., though i dont understand how will you manage to keep focus on your main form instead of your keyboard form when someone *clicks* a button for a keypress on the keyboard form since both are in different exe.
Feb 25 '10 #12
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Feb 25 '10 #13
tlhintoq
3,525 Expert 2GB
With what you have coded thus far you can forget about this working for you.
And I use the term 'coded' very loosely. You have about 10 seconds of work here.

Vishal is right that program one looses focus as soon as you click a button on program 2. You are going to have to do some work to keep track of which field was last clicked in. Then when that application receives a message, put the the message (key click/button click) into the proper field.
Feb 25 '10 #14
nayanar
11
ok.
for example if i have calculator ,notepad and a inbuilt on-screen keyboard opened on my desktop sequentially in the same order. and if i type using onscreen keyboard , how will this on screen keyboard is getting to know that it has to type in notepad. how does that work. can i use the same logic which the onscreen keyboard is using. Do u ppl know how does that on screen keyboard do it. Please help
Feb 26 '10 #15
nayanar
11
hey guys,

i found out the solution

in app1

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10.  
  11. namespace buttons
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         //**********Using event in user32 for sending button value****************//
  21.  
  22.         [DllImport("user32")]
  23.         public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int
  24.         dwExtraInfo);
  25.         private const byte VK_MENU = 0x12;
  26.         private const byte VK_TAB = 0x09;
  27.         private const int KEYEVENTF_EXTENDEDKEY = 0x01;
  28.         private const int KEYEVENTF_KEYUP = 0x02;
  29.  
  30.         //************************************************************************//
  31.  
  32.         private void button1_Click(object sender, EventArgs e)
  33.         {
  34.             prevwin();//function to go to previously active window
  35.             keybd_event(0x60, 0, 0, 0);// key press event 
  36.             keybd_event(0x60, 0, KEYEVENTF_KEYUP, 0);// key release event 
  37.         }
  38.         private void button2_Click(object sender, EventArgs e)
  39.         {
  40.             prevwin();
  41.             keybd_event(0x61, 0, 0, 0);
  42.             keybd_event(0x61, 0, KEYEVENTF_KEYUP, 0);
  43.         }
  44.  
  45.         private void prevwin()
  46.         {
  47.             // using ALT TAB to go to previously active window
  48.  
  49.             keybd_event(VK_MENU, 0xb8, 0, 0); //Alt Press 
  50.             keybd_event(VK_TAB, 0x8f, 0, 0); // Tab Press 
  51.             keybd_event(VK_TAB, 0x8f, KEYEVENTF_KEYUP, 0); // Tab Release 
  52.             keybd_event(VK_MENU, 0xb8, KEYEVENTF_KEYUP, 0); // Alt Release
  53.         }       
  54.     }
  55. }
  56.  
In app2

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace textboxs
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void Form1_Shown(object sender, EventArgs e)
  20.         {
  21.             textBox1.Focus();
  22.         }
  23.  
  24.  
  25.     }
  26. }

I got it Properly. try it out :-). Thank you very much for the help and concern.
Feb 26 '10 #16
good job but this worries me, user may see the Alt+Tab menu while typing and it loses and gains focus again and again, and instead of using the Imported API's
Expand|Select|Wrap|Line Numbers
  1. SendKeys.Send(Keys.Enter.ToString());
you could have used this, sends "enter" key to the active window.
Feb 26 '10 #17
nayanar
11
Hi,

as i opened both of the application using exe file and tried if the code works, then i did not get ALT+TAB menu. I surely try what u have mentioned above. thank you.
Feb 28 '10 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: MLH | last post by:
On the subject of switching between virtual consoles to get out of a 'hung' situation in the primary console... What I have been doing is pressing LEFTALT-F4 to bring up a 2nd virtual console,...
9
by: Neil | last post by:
I've been discussing here a SQL 7 view which scrolls slowly when linked to an Access 2000 MDB. After trying various things, I've distilled it down to the following: when the linked view has a...
2
by: gj_williams2000 | last post by:
Not sure if this is the right board but it is in c... I've got a console program written in c which receives key presses and gets a Windows Virtual key code. I am trying to convert it to the...
2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
6
by: Supra | last post by:
i got board working using graphic window in vb.net but no controls adding to form. i am doing checker board game. when i clicked and moved the peg to another location(grid). but how do i get bitmap...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
8
by: Herby | last post by:
Given class B and C which inherit from class A They all override a method of the form: Add( A^ lhs, A^ rhs ); So A is abstract. So if i was defining Add for class B : B::Add( A^ lhs, A^ rhs...
4
by: Hypnotik | last post by:
So I'm writing this program. I have the board constructed, and I'm having a problem making a move. At this point I just want to make a move, I'll work on whether it is a legal move after that. The...
5
by: Ian11 | last post by:
I have been searching for weeks to find asp message board code in its rawest form so that I can modify it to my needs. What I am looking for is code that will process a simple html for such as: ...
1
by: poopsy | last post by:
hi all, i'm trying out some examples on java..and i found this code where there is board and i cant find out what package to import to make this work, im getting error where there is "board".. i...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.