how to avoid open page already exist on Navigation stack? [duplicate] - c#

This question already has an answer here:
Pressing buttons multiple times loads multiple pages (Android)
(1 answer)
Closed 6 years ago.
I am using Xamarin.forms, Some times user will click twice on same button, I am search away to avoid open same page twice, maybe disable the button after first click will work fine, but i am searching away to avoid open same page if page already exist on Navigation stack.
btnCustomerPage.Clicked += (object sender, EventArgs e) =>
{
//CustomerPage already Exist on Navigation Stack,So user already open it.
Navigation.PushAsync(new CustomerPage();
};

if (Navigation.NavigationStack.Count == 0 ||
Navigation.NavigationStack.Last().GetType() != typeof(CustomerPage))
{
await Navigation.PushAsync(new CustomerPage(), true);
}

Related

How to transfer User To A Chrome Link? [duplicate]

This question already has answers here:
Process.Start(url) fails
(6 answers)
Closed 2 months ago.
I want user to go on a link when he clicks on a button. I use 6.0 .Net Framework
When I click on button its says system cannot find specified file
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://example.com");
}
Try this:
System.Diagnostics.Process.Start("explorer.exe", "http://google.com");

How would one add code to a control that was added programmatically to a windows form application in c#? [duplicate]

This question already has answers here:
C# - Add button click events using code
(3 answers)
Closed 3 years ago.
I very new to C# and I would like to add a Button to a form programmatically. When this button is pressed I want it to run some code (like a normal button woukd work). But, everywhere I have searched only shows how to add the button and not how to add code to the button.
One way to do it is to give the button a name property, then in your code you "refer" to the button by it's name like so:
void btnButton_Click(object sender, EventArgs e)
{
// your code goes here
}
where btnButton_Click is the name of the button.

How distinguish two different buttons in same event click? [duplicate]

This question already has answers here:
How do I handle click events on multiple similar buttons in WPF?
(3 answers)
Click event for button in loop C# WPF
(3 answers)
How would you know which element of an ItemsControl sends an event in MVVM?
(5 answers)
How to find out which button I pressed?
(1 answer)
Closed 5 years ago.
On WPF, if I have only one button click event shared for two or more (52 being more precise) is there a way to distinguish which button the event come from?
private void Button_Card_Click(object sender, RoutedEventArgs e)
{
// for testing
// it works for each button, but which one has been clicked?
MessageBox.Show("Clicked");
}
First button object with event set up
Second button object with event set up
sender should be the clicked button, but also look at RoutedEventArgs.Source and .OriginalSource
I would also look into using Commands and CommandParameter to indicate which was clicked.

How to add a right click event to an object like button,label,listbox etc [duplicate]

This question already has answers here:
How to create a right click event handler in c#
(4 answers)
Closed 7 years ago.
I'm a beginner, so this may be easy. But i could not find it. I want to add a right click event to a windows form. but when i look properties/events menu of the form, I could not find any right click event. Is there a menu or code example for that? i prefer to use it auto constructed like double clicking for click event, so it is better to me if you can show me how can i find that property if it exists.
Thanks for helping.
its a mousedown event,
private void btn_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
// do your stuff
}
}

how to disable particular check boxes in C# Winform Treeview control with check box option? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
TreeView Remove CheckBox by some Nodes
In my C# Windows Form Application, I have Treeview control with checkboxes.
I want to prevent the user from checking particular nodes' checkboxes. How can stop the user from being able to check particular ones?
TreeView.AfterCheck Event is one option to prevent checking nodes. I find this is an easy way of doing it. But there can be better ways.
private void node_AfterCheck(object sender, TreeViewEventArgs e)
{
// The code only executes if the user caused the checked state to change.
if(e.Action != TreeViewAction.Unknown)
{
if(e.Node.Nodes.Count > 0)
{
//Check whether that is a valid checkbox
// If not you can uncheck it.
}
}
}
Edit
To hide the checkboxes. Look at Cody Gray's answer here.

Categories

Resources