what I want to do is to change the parameters of the buttons On click event(for example if the script(GETFromYTS.DisplayMovies) wants a string change that string). have not seen any good answers.
the "GetfromYTS.displaymovies" code:
public void DisplayMovies(string[] movieUrls)
{
//create text objects with the movie URLs
}
IDE is Jetbrains Rider
EDIT 1: new problem, how do I change the text of the button?
EDIT 2: the first problem solved. answer selected
According to the documentation, you can use button.onClick.AddListener(function);.
The other functions (like removing one or more functions already associated with the button) are listed here.
Aside from daniel's answer, i'd like to add that in your onclick method you could thrown an unity event: https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html
This has some editor support, so in your editor you can call functions of other gameobjects.
Related
I am using Unity 2020.3 and making basically a question-answer game.
Assume that I have this two functions:
public void TrueAnswer()
{
Debug.Log("True !");
}
public void FalseAnswer()
{
Debug.Log("False !");
}
In every question, true answer's button is changing(For example, in xth question the answer is in first button but in x+1th question the answer is in third button). So, I should change answer buttons onClick event in every question. Depend on my research, there is some ways like:
using UnityEngine.UI;
m_YourFirstButton.onClick.AddListener(TaskOnClick);
m_YourSecondButton.onClick.AddListener(delegate {TaskWithParameters("Hello"); });
m_YourThirdButton.onClick.AddListener(() => ButtonClicked(42));
m_YourThirdButton.onClick.AddListener(TaskOnClick);
(This is from Unity Documentation, version 2019.1)
using UnityEngine.UIElements;
button.GetComponent<Button>().clicked += ButtonClicked;
(This is what I understand from Unity Documentation version 2020.3 and what VS 2019 IntelliSense recommend me to use "clicked" event. 2020.3 also has onClicked event but it is obsolote)
First, I used the first way to set buttons onClick events and it did not work.
Then, I read the documentations and tried the second solution, which is also did not work but I get an error:
ArgumentException: GetComponent requires that the requested component 'Button' derives from MonoBehaviour or Component or is an interface.
I understand what the error is, but I am very confused. After Unity 2019.1, I can't find the UnityEngine.UI library in Unity Documentations but if I use in script I can use it without any error. So depend on the documentation I must use UnityEngine.UIElements library but if I use, how can I make buttons derive from MonoBehaviour or others?
I don't think you need to change the buttons click event at all.
Rather those can be a "static" click event that return what button index was clicked.
[0] Button 1 -> ButtonClicked(0)
[1] Button 2 -> ButtonClicked(1)
[2] Button 3 -> ButtonClicked(2)
You can then have the answers in an array
[0] Answer 1
[1] Answer 2
[2] Answer 3
and use the clicked buttons index to determine which answer was picked.
When you go to ask a new question, all you have to do is create (or replace values of) the answers array with the relevant answers (in any order you wish).
I'd like to select a created DrawingObject to highlight it and show the handles without the user needing to click it. I am using Halcon 13 and tried using SendMouseDoubleClickEvent() (Docu) but this only seems to be available for the new Halcon Smart Window, which is currently not an option for me as it interacts differently with the Halcon-Procedures. I also tried to use SelectObj() (Docu) but this seems to do something entirely different.
I have:
a reference to the HWindowControlWPF
the ID of the HWindowControlWPF
the ID of the DrawingObject
Any help or hint is appreciated!
I could not find a proper solution to this problem but I found a hack that achieves the same result:
First, detach all drawing objects apart from the one you want to show as selected via DetachDrawingObjectFromWindow. Then, reattach them via AtachDrawingObjectFromWindow.
This works because the Halcon Window automatically selects the last attached drawing object.
Once code has been written, the only way I know of to view the overloads for a method is to actually edit the method by deleting the Parenthesis () and reopening them.
Is there a shortcut key that I could press to activate this instead of having to edit my files?
For an example, please reference the ShowDialog Overload screen shot below:
With your cursor inside the parentheses, use the keyboard shortcut Ctrl-Shift-Space. If you changed the default, this corresponds to Edit.ParameterInfo.
Example:
Ctrl+Shift+Space shows the Edit.ParameterInfo for the selected method, and by selected method I mean the caret must be within the method parentheses.
Here is the Visual Studio 2010 Keybinding Poster.
And for those still using 2008.
Tested only on Visual Studio 2010.
Place your cursor within the (), press Ctrl+K, then P.
Now navigate by pressing the ↑ / ↓ arrow keys.
The default key binding for this is Ctrl+Shift+Space.
The underlying Visual Studio command is Edit.ParameterInfo.
If the standard keybinding doesn't work for you (possible in some profiles) then you can change it via the keyboard options page
Tools -> Options
Keyboard
Type in Edit.ParameterInfo
Change the shortcut key
Hit Assign
It happens that none of the above methods work. Key binding is proper, but tool tip simply doesn't show in any case, neither as completion help or on demand.
To fix it just go to Tools\Text Editor\C# (or all languages) and check the 'Parameter Information'. Now it should work
Great question; I had the same issue. Turns out that there is indeed a keyboard shortcut to bring up this list: Ctrl+Shift+Space (a variation of the basic IntelliSense shortcut of Ctrl+Space).
The command Edit.ParameterInfo (mapped to Ctrl+Shift+Space by default) will show the overload tooltip if it's invoked when the cursor is inside the parameter brackets of a method call.
The command Edit.QuickInfo (mapped to Ctrl+KCtrl+I by default) will show the tooltip that you'd see if you moused over the cursor location.
I know this is an old post, but for the newbies like myself who still hit this page this might be useful.
when you hover on a method you get a non clickable info-box whereas if you just write a comma in the method parenthesis the IntelliSense will offer you the beloved info-box with the clickable arrows.
Every once and a while the suggestions above stop working, if I restart Visual Studio they start working again though.
you mean's change overload.
just Press Shift + ↑ / ↓
Mine showed up in VS2010 after writing the first parenthesis..
so, prams.Add(
After doings something like that, the box with the up and down arrows appeared.
I am developing the Internet Explorer Toolbar in c#.net using the band objects.
Now in my toolbar, I am using the textbox field to make the search enable, but in this textbox field, I am not able to use the backspace, delete, arrow keys and many other such button.
I am not sure about y I am not able to use this. Please help me about this. I found many question posted over like this, but none of them was having the specific answer.
Thanks
The problem is that the browser is eating the events for those keystrokes, so the solution is to force focus to the toolbar when the text box receives focus.
To fix it add this line to your toolbar's constructor:
yourTextBox.GotFocus += (sender, args) => OnGotFocus(args);
Also make sure you have implemented TranslateAcceleratorIO() per this example.
Compare your code to this one and see what's missing.
Simplifying
I have a text box and a button
The button just create an messagebox with the text from the textbox.
But i change the value of the textbox, the new value apears (Ex: Type 123) but the message box does not show the value.
If i try to use the value in the programming (get the value by textbox1.text) the variable has nothing ( textbox1.text = "") but i can still see what i typed in the form.
Anyone has any clue?
Your button's click event handler should look something like this
private void button_Click(object sender, EventArgs e)
{
MessageBox.Show(textBox.Text);
}
I suspect you already have code similar to this and that at some point the textbox is cleared or otherwise set to String.Emppty but without seeing actual code it is difficult to help you
When/where did you check the value of textBox1.Text? If you're checking it in the constructor, Form1_Load, or anything else that occurs before you'll have typed text, you will get an empty value.
To properly check the value of textBox1.Text, you should set what's called a breakpoint on the line that calls MessageBox.Show(textBox1.Text). To do this, click in the grey area of the source editor (it's on the far left) on the line containing MessageBox.Show(..). A red circle will appear and your code should be highlighted. When you run your application and click on your button, your application should pause and Visual Studio will highlight that line and from here you can hover over "textBox1.Text" in the MessageBox.Show() line and it should show you the current value.
If your application is as simple as a form, a textbox, and your button1_Clicked event handling code, this should work no problem. If it is not this simple, then you need to look for anything that sets the value of the textBox in your code and make sure it isn't passing any blank values by using breakpoints.
To solve this properly, though, we really need more information.
Thanks Eric and Crippledsmurf. As both of you said, its hard to help without the code.
The problem I found is that when calling the form, I send some objects by reference, so I can track them down and I found that when (don't ask me why it happens that way, I'm still working on it) the construtor is called he make an new component, so the component in the interface no longer represents the one pointed by the variable "textbox1" (Yes Crash893, I haven't mispelled the name).
I found that I was making some mess with the references, and probably that was causing the problem. I fixed the problem by changing the actions performed by references for delegates and events, but I couldn't track down the exactly source of the problem.
Thanks, again, everyone for the insights.