0

I'm making a program in C# using WinForms. When user presses a combination of keys, e. g. SHIFT+A, my program determines that - I already setup that with a keyboard hook.

What I need is that program knows what is selected or marked such as text, image, app etc. When a user presses SHIFT+A, what is selected program save into a created file in directory which is already done. How do I get the selected control into the created file? How do I get what is selected into a text file and save it or write the marked control into the created file.

I tried to find the answer on the internet, but there are only answers for the TextBox control.

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
R.Faladore
  • 33
  • 1
  • 6
  • When you say "a program knows" are you talking about YOUR program having knowledge of OTHER programs running on windows OR with-in YOUR program? I really think you should spend some time to give us a use-case because at the moment it is hard to visualize what you are asking for. – lucidgold Apr 20 '16 at 20:09
  • I want that my program will knew that. – R.Faladore Apr 20 '16 at 20:11
  • Will know what? You did not answer my question – lucidgold Apr 20 '16 at 20:12
  • I'am asking that I need to do that when user will press SHIFT + A the program will determind the selected text and save it into the text file which I already created? – R.Faladore Apr 20 '16 at 20:14
  • Okay, I understand that but are you asking for this functionality with-in YOUR program OR you want this to work when you minimize your program and press SHIFT+A globally and get selected text? – lucidgold Apr 20 '16 at 20:17
  • I wanted in both way and i done that with keyboard global hook what i'am asking you guys is how i get selected text into a txt file which program crates when it starts. – R.Faladore Apr 20 '16 at 20:25

1 Answers1

0

If you are looking for the control that is focused you can use: this.ActiveControl or this.ActiveControl.Name.

Then you need a method for each control type, that defines how it is saved to a file. Dependent if it's picturebox a textbox, ...

RomCoo
  • 1,868
  • 2
  • 23
  • 36
  • This thing will do what...? – R.Faladore Apr 20 '16 at 20:05
  • I think there is no way to get the selected item of a winform. but instead with this method you could check which control/item has the focus. – RomCoo Apr 20 '16 at 20:08
  • So I copy this code to the section where program or hook is checking if 2 keys are pressed and if it's true it return this code? – R.Faladore Apr 20 '16 at 20:10
  • when you decide what you want to save to a file you can use `this.ActiveControl` to get the control or `this.ActiveControl.Name` to get the name of that control. (I edited the answer to make it more simple) – RomCoo Apr 20 '16 at 20:16
  • Thanks for that one more question can i used this for when some text is selected... – R.Faladore Apr 20 '16 at 20:26