Reputation: 61
I want to animate buttons in c#. So i create a method called HoverMouseBut() as follows.
public void HoverMouseBut(Button name,Image img, int w, int h)
{
name.Image = Resources.img;
name.ForeColor = Color.FromArgb(232, 126, 4);
name.Size = new Size(w, h);
name.Font = new Font("Segoe UI", 12, FontStyle.Regular);
name.TextAlign = ContentAlignment.BottomCenter;
name.ImageAlign = ContentAlignment.MiddleCenter;
}
I called this method as follows;
private void addo_MouseHover(object sender, EventArgs e)
{
HoverMouseBut(addo,Add2,250,160);
}
This gave me a syntax error. I changed the method without image parameter and see.Then it worked.But I want to change the image of the button as well.How could I do this? Whats wrong with my code?
*Add2 is an image in resources .
Upvotes: 2
Views: 55
Reputation: 11491
You are using C# and forms are like other properties in C#. Therefore you have different options to do that. One of the easiest ones is to have a public property of your needed type in your second form and use that to pass data
class Form2
{
public string myStringField{get;set;}
}
class Form1
{
myMethod()
{
....
var newForm= new Form2();
newForm.myStringField="Something";
}
}
However, if your Form2 can not exist without your field, it make sense to put your filed in the constructor
class Form2
{
public Form2 (string myStringField)
{...}
}
class Form1
{
myMethod()
{
....
var newForm= new Form2("Something");
}
}
Upvotes: 1
Reputation: 76
If you are trying to pass an Image to the method for use, why did you set name.Image = Resources.img
?
Changing it to name.Image = img
might work
Upvotes: 1