How can I format multiple button in minimal OnEvent() function? - uibutton

I have a screen with over fifty buttons on it. I want to be able to detect which button was clicked and then proceed to a different screen with data based on what button was clicked. However, I can't seem to detect a click from the mouse without the use of a specific button name. I would like to avoid using 50+ OnEvent() functions if possible. If not, I will just write them all.
Any advice would be greatly appreciated on how I can go about doing this, thanks!

You are using C#? C++? VB.NET? Java?
C# Code:
Here is an Event as Example:
private void button1_Click(object sender, EventArgs e)
{
if (sender is Button)
{
MessageBox.Show((sender as Button).Name);
}
}
You can replace the MessageBox, it is just meant to make it a proof by example.

Related

How to make a default button in UWP app using XAML?

I'm trying to declare a button as default in UWP app but receive an error:
The property 'IsDefault' was not found in type 'Button'
How can I make a default button in UWP app?
I down know what IsDefault is in WPF but to get if a button is pressed in UWP you can use CoreWindow.GetForCurrentThread().KeyDown. Create a Method that will be called from when the button is pressed or VirtualKey.Enter is clicked.
public MainPage()
{
this.InitializeComponent();
CoreWindow.GetForCurrentThread().KeyDown += MainPage_KeyDown; ;
}
private void MainPage_KeyDown(CoreWindow sender, KeyEventArgs args)
{
switch (args.VirtualKey)
{
case Windows.System.VirtualKey.Enter:
// handler for enter key
break;
default:
break;
}
}
You can use key down event which you can place on any textbox for example if you are making a login page then probably there will be 2 textboxes for username and password then just add key down event handler to textbox as it will be the last mandatory field like this:
<PasswordBox KeyDown="PasswordKeyDown"/>
then you can handle this event as:
using System.Windows.Input;
private void PasswordKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
Login();
}
Hope it will help you :)
There is not easy or clean way to solve your problem because IsDefault is not available for uwp apps.
if you are using MVVM or you want to reuse your code I recommend you to use Behaviors and follow the examples that the other guys posted.
I need a Button which user can invoke by pressing the ENTER key.
In an UWP app, by default a Button can be invoked by pressing the Enter key. So I guess what you want is setting the focus on this Button when there are some other UIElements in your page.
You can refer to Keyboard navigation among UI elements,
By default, the tab order of controls is the same as the order in which they are added to a design surface, listed in XAML, or programmatically added to a container.
To focus on the Button which is not the first element, you can just give the TabIndex="1" property to your Button, this property can make your Button get focus whenever the page is loaded, but if you change the focus on other controls in this page, you will need to reselect this button by mouse clicking, touching or TAB key.

Windows Phone Back Button VB

I have been trying to get the back button to work for windows phone using vb, however I cant find anything on the internet, anything I do find is for c#
Can someone please tell me how I can make the back button go to the previous page as every time the back button is pressed it quits out of the app.
thanks
I'm not good at VB so, I'll make it in C# and consider to do it in your way in VB
In the Constructor of a page, write this code :
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
In the Page's class, write this :
void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
if (this.Frame.CanGoBack)
{
this.Frame.GoBack();
}
else
{
Application.Current.Exit();
}
}
Consider to write it in all pages.

mouseClicked() won't execute while mouse is in motion

So basically the title says it all. I tried searching around; you would think something as trivial as this would have instant results, but nope.
This is really annoying me. Can anyone suggest a fix or workaround?
Thanks
That's because, by definition, a mouse click while in motion is no longer a mouse click, it's a drag event.
You still have access to the mousePressed() and mouseReleased() events, so if you want to detect a mouse click during a drag event, use those instead.
Here's a small example to get you started:
void mouseClicked(){
println("clicked");
}
void mousePressed(){
println("pressed");
}
void mouseReleased(){
println("released");
}
void mouseDragged(){
println("dragged");
}
void draw(){
background(0);
}

Changing text values on labels and buttons

I hope this is a simple question, I'm new at Mono, and I'm having trouble getting to grips with GTK#'s bindings.
Essentially, I want to be able to programmatically change attributes against objects like labels, buttons and lists added in by the designer in MonoDevelop.
I know this can be done by instantiating a new instance of say, a button as such:
Button button1 = new Button("Text for button here");
However, say button1 was already created, how would I grab button1 to make changes to it?
Sorry if this all comes across a little thick, I'm still getting the hang of OOP.
Thanks!
This is actually easy enough, now I've sat and worked it out:
protected void OnButton1Clicked (object sender, EventArgs e)
{
Button theButton = (Button)button1;
theButton.Label = "New label text!!";
}

Close popup modal dialog on clicking the submit button in sharepoint custom form

I have a custom form and I would like to add some functionality in my submit button. When I click on Submit button, I would like to close the popup and refresh the parent page.
I used this code in my button but there is a problem. It does not validate the controls and it makes a postback and even does not save any data.
OnClientClick="javascript:window.frameElement.commitPopup();"
Can you help me with some working code?
Thank you.
You need to set OnClientClick property after the code you want to be executed.
protected void btnAdd_Click(object sender, EventArgs e)
{
//Your Code here(some functionality)
Context.Response.Write(#"<script type='text/javascript'>window.frameElement.commitPopup(); return false</script>");
Context.Response.Flush();
Context.Response.End();
}