How to Send a Object name as argument to function? [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I want write a program that :
In textbox type a picturebox name and in other textbox type location number,then press button to move that picturebox that name is equal textbox1 to that location.
my question is how I can send a object(picturebox) to a Function?

If I understand you correctly you want to move a picture box by entering its name into a textbox? Then this is a possibility:
private void button_click(object sender, EventArgs e)
{
string pBoxName = textbox1.Text;
// I don't quite understand what you mean by 'location number'
int newPos = int.Parse(textbox2.Text);
// boxList is a List<PictureBox>
PictureBox pBox = boxList.Where(x => x.Name.Equals(pBoxName)).FirstOrDefault();
if(pBox != null)
{
MoveTheBox(pBox, newPos);
}
}
private void MoveTheBox(PictureBox box, int newPos)
{
// move the box
}

Related

Fill combobox according to month of days value [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am doing a c# project of making "Age Calculator" and I have the following problem:
When i select February from month's combo box then in date's combo box it shows 1-31 numbers. But i want to show 1-29.How can i solve this without database?
private void ListBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (ListBox1.SelectedValue == "February")
{
for (int i=1; i<=29; i++)
Listbox2.Items.Add(i.ToString());
}
}

How to write from textbox to file? C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I want to get data from textbox and write it to file. I have this code, but it's not working.
private void Button_Click_2(object sender, RoutedEventArgs e)
{
string info = textbox2.Text;
List<string> data= new List<string>();
data.Add(info);
String line = File.WriteAllLines(filename, data);
}
What am I doing wrong?
1. you are trying to store the return value of the function File.WriteAllLines() into String variable line but File.WriteAllLines() does not return anything it's return type is void
2. you can use File.WriteAllText() function to write your string entered in TextBox.
Try This :
private void Button_Click_2(object sender, RoutedEventArgs e)
{
File.WriteAllText(filename, textbox2.Text);
}

how controling A Clickable pictureBox ? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a pictureBox and I want to perform a some statement when the image is clicked, So how can i check when the pictureBox is selected inside an if statement ?
Add an event handler to the MouseClick event, and then add in the code you want to run within the handler method:
MyPictureBox.MouseClick += new MouseEventHandler(MyEventHandler);
private void MyEventHandler(object sender, MouseEventArgs e)
{
//your code here
}

Get several buttons' ID with single method [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm building a program with C# in Windows Forms, and the following question came to me. I have several buttons in my form and when any of them is clicked, I want to be able to store its ID in a single variable that will handle only one ID at a time. I already have a method that does this, but the fact is I don't want to call this method from the event handler of each button:
button1_Click(object senders /* ... yada yada ... */)
Is there a way how I can simplify this with a single method? Is it even possible?
You don't need many Click event handlers for your buttons, just 1 is enough:
private void buttons_Click(object sender, EventArgs e){
Button button = sender as Button;
//do something with the clicked button
//...
}

using malayalam font in C# textbox [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have an app in c# having 2 textbox.When i select the first one and type i should get the malayalam font and when i select the other textbox, i should get the text in english. For this i set the font of first textbox to malayalam and font of second textbox to english-arial.
and when i run the program both the text box displays english letters when i type. By pressing alt+shft keys and swapping the input language, then both textboxe's inputs become malayalam. I want to type malayalam in one textbox and english in other textbox without swapping the input language using alt+shft
Thank you
You have to select malaya language on text box enter event and back to english language selection on leave event as below:
private void textBox1_Enter(object sender, EventArgs e)
{
System.Globalization.CultureInfo TypeOfLanguage = new System.Globalization.CultureInfo("ms-MY");
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage);
}
private void textBox1_Leave(object sender, EventArgs e)
{
System.Globalization.CultureInfo TypeOfLanguage = new System.Globalization.CultureInfo("en-us");
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage);
}
Hope that was helpful.

Categories