I currently have made a program in AutoIT that has PixelSearch methods inside of it. Anyway, I have a pretty intense GUI that can be annoying to fill out everytime you run it, so I decided I would make a save/load settings button. It turns out that AutoIT handles file reading/writing pretty inefficiently, so writing to the file to "save" settings and reading from the file to "load" settings was out of the question. I decided to make something in C# since the FileStream class is amazing. But, to replace the AutoIT program, I need the function pixelsearch, which basically searches for a certain pixel in a rectangle/point defined. Anyone have an idea how this is created, or if there is one already how it is used?
P.S: Is there also a way that I can save the cursor's location after the user presses a certain button in C#? I was thinking of a mouseEvent of some sort.
you certainly can save the mouse click locations, try to use the mouse events mouseUp(object sender, MouseEventArgs e) mouseDown(object sender, MouseEventArgs e) ... inside the function you can open a stream and write the location everytime then close it , the location is e.Location
Related
I am creating a WPF application using Kinect SDK 1.8
I want to press a button with hand.
private void playTeeth1Sound(object sender,RoutedEventArgs e)
{
System.Media.SoundPlayer teeth1_Sound = new System.Media.SoundPlayer(#"../../soundForKinect/1.wav");
teeth1_Sound.Play();
}
I don't see any Kinect specific code in your question, and I'm not sure what the questions is, but one thing to consider in the code snippet in your question is:
Every time this method is called (presumably when the button is pressed), it has to:
instantiate a new System.Media.SoundPlayer
load the sound file into teeth1_Sound
play the sound file with the Play() method
You might find there is a delay each time as the code re-instantiates teeth1_Sound and reloads the sound file? It might be easier to load all the sound files when the app is starting up, have them ready to Play() as soon as you need them?
I am currently working on updating a C# project that makes use of WinForms. One of the minor changes I want to make is as follows.
The project has a Form that currently allows the user to click a Button, which then opens a Folder Browser window where they can select a folder for the project to retrieve information from. The selected directory is entered into a TextBox after being selected. However, clicking on the TextBox also opens up a Folder Browser window. You are also currently unable to manually enter text into the TextBox.
What I want to do is (hopefully) pretty simple: I want the user to be able to enter a directory manually into the TextBox and for the project to accept that text input, and for the TextBox to not open a Folder Browser form upon being clicked.
Some other things to keep in mind:
I am not familiar with all the ins and outs of WinForms, so I could very well be missing something simple that I could do.
I am also in the process of completely restructuring the project, so if this is not possible in WinForms, but is possible in, say, WPF, that would not be a major obstacle for me in this case.
Here is the code for the Button, or at least the pertinent part, as a reference. txtProjectDir is the TextBox in question. Not much else is done with the TextBox in the code except for this part.
private void btnBrowse_Click(object sender, EventArgs e)
{
if (chooseProjectFolderDialog.ShowDialog() == DialogResult.OK)
{
clbConvertProjects.Items.Clear();
clbProjects.Items.Clear();
txtProjectDir.Text = chooseProjectFolderDialog.SelectedPath;
cur_projDir = txtProjectDir.Text;
Update: I have made some changes based on the input of several users (thanks to all of you, by the way). This is what the pertinent part of the code looks like now:
private void btnBrowse_Click(object sender, EventArgs e)
{
if (chooseProjectFolderDialog.ShowDialog() == DialogResult.OK)
{
clbConvertProjects.Items.Clear();
clbProjects.Items.Clear();
cur_projDir = txtProjectDir.Text;
I also had to change the TextBox to not be read-only, as well as remove a reference to the above method from its Event properties. Now it is able to accept user input, and doesn't open a Folder Browser when clicked into.
The only problem is this: if I only enter text directly into the TextBox, instead of selecting a folder via the browser popup, the program doesn't seem to properly accept the input (i.e., no information is being collected from the directory). Obviously, I still need to make the program accept user input, as it currently doesn't.
Update 2: After more suggestions (again, thanks guys) and good old trial-and-error, I have re-inserted the line txtProjectDir.Text = chooseProjectFolderDialog.SelectedPath; as removing it from the method had undesired effects on the program's functionality. I am still having an issue with the program accepting the user's manual input into the TextBox, though.
Update 3: As per #blaze_125's recommendation, I am going to have to create a new event for the TextBox when the user Leaves it. Thank you all for the help, I appreciate it!
However, clicking on the TextBox also opens up a Folder Browser window.
The only event for the TextBox is Action -> Click, which is set to btnBrowse_Click
What I want to do is (hopefully) pretty simple: I want the user to be able to enter a directory manually into the TextBox and for the project to accept that text input, and for the TextBox to not open a Folder Browser form upon being clicked.
If you don't want that event(aka action->click) to happen, then you must remove the text btnBrowse_Click from that textbox and leave it blank. That will remove the event you currently have linked to your textbox click.
There will be an even linked to the text box txtProjectDir to check this select the text box and in the properties select the lightning bolt.
I would assume that the even is a click into the textbox however.
If this is the case you probably want to remove this.
Now in terms of how to accept what is in the text box as the value you just want to reference the text and that is in the textbox whitch would be txtProjectDir.Text
private void btnBrowse_Click(object sender, EventArgs e)
{
if (chooseProjectFolderDialog.ShowDialog() == DialogResult.OK)
{
clbConvertProjects.Items.Clear();
clbProjects.Items.Clear();
cur_projDir = txtProjectDir.Text;
First off I would like to say that I am kinda new to visual studio C# (2 months in) & I've studied other languages but I know the fundimentals & the project is somewhat done, its just this one feature I cant seem to get the hang of.
So I am trying to connect a trackBar to my WinForm application which is a SoundBoard.
It is not driven by Windows Media Player it is simply just some resources (Audio Files)
It is a really boring project its really nothing special but I really cant seem to get the code to work.
(Will provide the .cs files if necessary)
What I am trying to accomplish is that I want to make a trackBar that connects to the winForm app & lets the user control the volume of the WinForm itself.
I know I need to set the min and max values according to my needs at the beginning, like in the Form_Load event.
E.g. the volume control uses percentage 0 - 100%
Then I need to set min=0, max=100.
the thing is, I have no idea how to do it, I have never seen any code that makes any sence in this scenario.
Here is the code for the trackBar, or this is what I've gotten so far. I know its not much but I am really bad with trackBars.
(Sorry for my bad english, not my native tounge.)
private void trackBar1_Scroll(object sender, EventArgs e)
{
trackBar1.Minimum = 0;
trackBar1.Maximum = 100;
}
This is the code for the sounds being played with each button that is named differently.
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.Stream = Properties.Resources.cow;
player.Play();
There is no sense in modifying the Minimum and Maximum values within an Scroll event. Just set these values to 0 and 100 in designer (Properties window).
Then, you will be able to use this event and control the volume through it:
private void trackBar1_Scroll(object sender, EventArgs e)
{
yourSoundPlayer.Volume = trackBar1.Value;
}
As you haven't told what you use for playing a sound, I have assumed the Volume property. However, it may be another in your case.
How to get keyboard and mouse input (what buttons are currently pressed) && also how to send output (make the mouse click at a specific position in another program). If you could also add comments on what different things do and why you use them would be terrific :D
Cheers! //Daniel
http://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library
This article is quite helpful. It even includes code for a cool macro recorder.
This may not be a very good solution but bad as i am (didnt understand how to use the other ones that were suggested) i chose the siple way out... i used using Microsoft.Xna.Framework.Input; after getting the xna framework reference, then i simply went ahead and did keyboardstate currentkeyboard = keyboard.getstate :) same with mouse
.NET only has .NET controls (forms, buttons,etc) based mouse/keyboard hooking built in, so to programmatically respond to those events outside your .NET controls you need a global event hook that can intercept mouse and keyboard activity from anywhere in windows.
HowTo use one keyboard/mouse hook dll to perform the functionality you are requesting (the ability to respond programmatically to mouse/keyboard events globally):
Download "Gma.UserActivityMonitor.dll" from: global mouse/keyboard kooks in c#
Place this dll in C:\Windows\System32
In your project, include a reference (from VS, add...reference and browse to the dll)
In your project code, add "using Gma.UserActivityMonitor;"
In your code, declare these event consumers:
HookManager.MouseMove += HookManager_MouseMove;
HookManager.KeyPress += new KeyPressEventHandler(HookManager_KeyPress);
Here are some method stubs that can be raised when the mouse/keyboard events occur:
private void HookManager_MouseMove(object sender, EventArgs e)
{
}
private void HookManager_KeyPress(object sender, EventArgs e)
{
}
Hope this helps, this is how I did it when I needed to consume global mouse and keyboard events in my code.
I'm attempting to use the ScintillaNET control in an application I am working on. I drag and drop the control into my form and run form. The control appears on the form. This is good. In addition, if I set any of the properties in the control's properties editor (ConfigurationManager.Language, for example), I am able to type in that language and see syntax highlighting occur.
Where I run into problems is when I attempt to change properties programmatically. For example, I attempt to load text from a file into the form (I'm doing this in the form's Load). The text doesn't display. I also can't seem to show the line numbers or do any other number of tasks (including programmatically change the Language).
Any idea what I may be doing wrong? Even something as simple as the code below doesn't seem to work:
private void scintilla1_Load(object sender, EventArgs e)
{
scintilla1.ConfigurationManager.Language = "xml";
}
Simply add scintilla1.ConfigurationManager.Configure();
private void scintilla1_Load(object sender, EventArgs e)
{
scintilla1.ConfigurationManager.Language = "xml";
scintilla1.ConfigurationManager.Configure();
}
After spending some time playing around with the different events, it appears that I cannot affect the Scintilla control until after it is already visible. Hence, the "Load" event does not let me make any programmatic changes to the control until I've set it visible.
It's a little strange, and seems sort of pointless to me to have the Load event at all, but I just wanted to let everybody know what is happening in case someone else ran into the same problem.