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
17 7392
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.
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
Are the two programs ones you have written?
If so, you can code in some methods for the two to communicate with each other.
no they are two different applications....just like a notepad and one screen keyboard. different solution itself.
he meant if you wrote the code of both of the applications?
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
here is code of application where i have to write - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Runtime.InteropServices;
-
-
namespace simple_wind_fow
-
{
-
public partial class simpleform3 : Form
-
{
-
public simpleform3()
-
{
-
InitializeComponent();
-
}
-
private void textBox1_Enter_1(object sender, EventArgs e)
-
{
-
-
-
}
-
private void textBox2_Enter(object sender, EventArgs e)
-
{
-
-
}
-
-
private void simpleform3_Click(object sender, EventArgs e)//when clicked on that window
-
{
-
textBox1.Focus();
-
}
-
-
-
}
-
}
this is the second application where is need to find active application and send value to it , when ever button is pressed - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Runtime.InteropServices;
-
-
namespace button
-
{
-
public partial class keyboard : Form
-
{
-
public keyboard()
-
{
-
InitializeComponent();
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
//find the active application
-
//send value "1" to that application
-
}
-
private void button2_Click(object sender, EventArgs e)
-
{
-
//find the active application
-
//send value "2" to that application
-
}
-
-
}
-
}
they are two different application which are two different exe file
please do help. Its kind of urgent requirement
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.
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.
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.
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
hey guys,
i found out the solution in app1 - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Runtime.InteropServices;
-
-
namespace buttons
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
//**********Using event in user32 for sending button value****************//
-
-
[DllImport("user32")]
-
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int
-
dwExtraInfo);
-
private const byte VK_MENU = 0x12;
-
private const byte VK_TAB = 0x09;
-
private const int KEYEVENTF_EXTENDEDKEY = 0x01;
-
private const int KEYEVENTF_KEYUP = 0x02;
-
-
//************************************************************************//
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
prevwin();//function to go to previously active window
-
keybd_event(0x60, 0, 0, 0);// key press event
-
keybd_event(0x60, 0, KEYEVENTF_KEYUP, 0);// key release event
-
}
-
private void button2_Click(object sender, EventArgs e)
-
{
-
prevwin();
-
keybd_event(0x61, 0, 0, 0);
-
keybd_event(0x61, 0, KEYEVENTF_KEYUP, 0);
-
}
-
-
private void prevwin()
-
{
-
// using ALT TAB to go to previously active window
-
-
keybd_event(VK_MENU, 0xb8, 0, 0); //Alt Press
-
keybd_event(VK_TAB, 0x8f, 0, 0); // Tab Press
-
keybd_event(VK_TAB, 0x8f, KEYEVENTF_KEYUP, 0); // Tab Release
-
keybd_event(VK_MENU, 0xb8, KEYEVENTF_KEYUP, 0); // Alt Release
-
}
-
}
-
}
-
In app2 - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace textboxs
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void Form1_Shown(object sender, EventArgs e)
-
{
-
textBox1.Focus();
-
}
-
-
-
}
-
}
I got it Properly. try it out :-). Thank you very much for the help and concern.
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 - SendKeys.Send(Keys.Enter.ToString());
you could have used this, sends "enter" key to the active window.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |