Animation on button click xamarin forms [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to put button click effect in Xamarin forms. How can I do this? Am I need to use any plugin or any best way.
EDITED
I am creating Xamarin.Forms application and I want to make a more user-friendly button click. So, a user can feel like the button was pressed.

You need to create custom button like below:
public class CustomButton : Button
{
public CustomButton() : base()
{
const int _animationTime = 10;
Clicked += async (sender, e) =>
{
try
{
var btn = (CustomButton)sender;
await btn.ScaleTo(1.2, _animationTime);
await btn.ScaleTo(1, _animationTime);
}
catch (Exception ex)
{
ex.Track();
}
};
}
}

Related

Windows Form: Display unique panel based on list selection [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Using a Windows Form I am trying to replicate the functionality of a "Tab Control" but instead of the panel selection being controlled by a tab selection it would be controlled by a list. Is there a built in way to produce this using neatly like the tab control or should I just check if a list value is equal to some value and if yes display panel else don't?
This is probably a dumb question so sorry for wasting anyone's time and thanks in advance!
Besides, you can also use tabpages in tabcontrol as "panel". Just hide the header via the code
private void Form1_Load(object sender, EventArgs e)
{
tabControl1.Appearance = TabAppearance.FlatButtons;
tabControl1.ItemSize = new Size(0, 1);
tabControl1.SizeMode = TabSizeMode.Fixed;
foreach (TabPage tab in tabControl1.TabPages)
{
tab.Text = "";
}
}
Then select the tabpage like,
private void listBox_SelectedIndexChanged(object sender, EventArgs e)
{
if(((ListBox)sender).SelectedItem.ToString() == "tabPage2")
{
tabControl1.SelectedTab = tabPage2;
}
//...
}

Loop for click event in c# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have multiple text boxes on a form and I want to display the name of the textbox when I click on it in a specific textbox. As I have 300 textboxes I dont want to create 300 click Events. Do I need some kind of loop?
Yes, exactly, iterate through all your Controls on your Form and if Control is a TextBox, subscribe to an event like this:
private void subScribeAllTextBoxClickEvents()
{
foreach(var ctrl in this.Controls)
{
var textBox = ctrl as TextBox;
if(textBox != null)
{
textBox.Click += textBox_Click;
}
}
}
private void textBox_Click(object sender, EventArgs e)
{
}
You could call subScribeAllTextBoxClickEvents method for example in your constructor.

Do we have to repeat our code in a WinForms application? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
So I'm trying to switch from C# console to form, but I always read that never repeat our code etc.
My first project would be a calculator, and I found a site just to take a look how it looks like in win form, but in this code there are a lot of repeating. Is this normal in form, in let's say a calculator?
Here is the link that I am talking about.
That is a lot of repetition, to improve it add one click event handler for all of the buttons, eg:
btn1.Click += btnClick;
btn2.Click += btnClick;
Then cast the sender to a Button to get which one was clicked, a rough example:
private void btnClick(object sender, EventArgs e)
{
var btnName = ((Button)sender).Name;
var btnValue = btnName.Replace("btn",string.Empty);
if (textBox1.Text == "0" && textBox1.Text != null)
{
textBox1.Text = btnValue;
}
else
{
textBox1.Text = textBox1.Text + btnValue;
}
}
Don't forget to unhook the event subscriptions in the form unload event:
btn1.Click -= btnClick;
btn2.Click -= btnClick;

How to perform an action while a key is pressed [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How to make that when pressing a key do an action and when you press it again, stop doing it in C#.
What I want to do: I have a program which the user must press F1 to activate any action, well; so that the user does not press another key, but the same one, how would this be done in C #? Since I currently stop the action by doing the following:
if (GetAsyncKeyState(Keys.F1) == -32767)
{
timer1.Start();
}
if (GetAsyncKeyState(Keys.F2) == -32767)
{
timer1.Stop();
}
You can use System.Timers.Timer.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Key.A)
{
if(!timer1.Enabled)
timer1.Start();
else
timer1.Stop();
}
}

Passing data into a separate form [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a button that when pressed is currently outputting messages to a messagebox. Its not very tidy so I created a new form and placed a text box in there. While the 2nd form picks up the data it presents it in another messagebox rather then the textbox like intended. Help is appreciated.
Form2
public Form2(string strTextBox)
{
InitializeComponent();
textBox1.Text = strTextBox;
}
Form 1
private void SaveButton_Click(object sender, EventArgs e)
{
foreach (string error in errorSet)
{
Form2 frm = new Form2(error);
frm.Show();
}
}
There is some more logic in the button_click if it looks a little strange but its pretty redundant for the problem im having.
Thank you
You should loop over your errors collection and store them in a StringBuilder, then, show the Form2 only one time outside the loop (if there is at least an error).
Do not forget to make your textbox MultiLine=true, give it enough height and a vertical scroll bar.
private void SaveButton_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
foreach (string error in errorSet)
sb.AppendLine(error);
if(sb.Lenght> 0)
{
Form2 frm = new Form2(sb.ToString());
frm.Show();
}
}

Categories