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
Here is an example of my code:
Button1_Click(object sender, EventArgs e)
{
PictureBox PB = new PictureBox;
PB.Name = TextBox1.Text;
}
In this code when a user clicks the button, a new object of type PictureBox will be created. Then Name will be assigned the object. How's this possible?
I mean if user clicks again, another object with same reference will be created. How's this possible?
How's this possible?
The Name property on a Control is just a string property - you can assign it anything you want, so having multiple controls with the same name is just the same as having multiple text boxes displaying the same text, or any other class with a string property.
Note that, in your case, you're not actually using or storing the PictureBox you create in any way, so it's going to be eligible for GC as soon as your method ends.
Related
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 4 years ago.
Improve this question
I have this error and I have no ideo about what should I do
The aim is when I click to button, it should read the word in textbox and save it into the string variable by its new factor.I have the error oin the topic
private void panel_button_kelimeekle_kaydet_Click(object sender, EventArgs e)
{
if(panel_checkbox_ing.Checked)
{
string (panel_textbox_kelimeekle_yab.Text) = Ingkelimeler[(Ingkelimeler.Length+1)];
}
}
If panel_textbox_kelimeekle_yab is already a textbox on your form, then you don't need to declare its type when you assign a value to it. C# thinks you're trying to declare a new string variable.
Change that line of code to
panel_textbox_kelimeekle_yab.Text = Ingkelimeler[(Ingkelimeler.Length+1)];
This probably won't solve all your problems, but at least it will get you on to the next error message. (You probably mean Length-1 in your array index, but there's really no way for us to know.)
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 5 years ago.
Improve this question
I have three text boxes for input values, I wish to retain the values even after closing the form. Is it possible?
You might want to use User Settings. They're different from Application Settings because they can be read and write between different sessions of the same applications.
You can create a new setting at design time:
Solution Explorer > Properties
Double-click on the .settings file (this creates a new set in the default settings).
Set name and type of your settings, plus an initial value in the value form. The scope is "user";
At this point, assuming you created a mySetting1 setting of int type, you load this value in the textbox
int myValue = myNamespace.Properties.Settings.Default.mySetting1;
myTextBox1.Text = myValue.ToString();
When closing the form, be sure to save the new value (I assume you checked for integrity):
int myvalue = int.Parse(myTextBox1.Text);
myNamespace.Properties.Settings.Default.mySetting1 = myValue;
myNamespace.Properties.Settings.Default.Save();
More of this on MSDN.
Bye!
Davide.
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 8 years ago.
Improve this question
if (Operators.CompareString(this.ParentForm.ActiveControl.Name, this.Name, false) == 0)
{
base.Focus();
}
From What I have experience in VB6,the above code doesn't work because they are never equal if the users didn't change to the same name.
From Example, the UserControl Name is ucCalendar, When I drag to my From, the name will automatically change to ucCalendar1,even though I can change to ucCalendar but usually we won't do that.
I think the coder want to compare whether the UserControl is the only control or ActiveControl on the Form so that he can force to focus it.
I don't know this C# works or not. Please tell me.
There is nothing in the WinForms code saying that two controls can not have the same name. The reason you think that is that you're looking at it from the designer perspective, when you use the designer it won't let you have two controls with the same name just because it uses there as field names for them in the code, and as you probably know there can not be two fields / properties / variables with the same name in the same scope. As a matter of fact there is no need for the Control's Name property to be anything.
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
in C# with DotNet 4 i have a form with a combobox which is filled with values when starting the program.
Now user can dropdown and select one of the values.
But: It is also possible to write something new into the combobox-field.
Question: What can i do that it is NOT possible to write something which is not part of the list?
Thanks
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList".
It can be done by simply assigning a property to combobox .DropDownStyle = ComboBoxStyle.DropDownList. but, this property do not allow to edit text. means you have to select item either by mouse or by up/down arrow key. You cannot filter result by selecting this property. if you wish to filter result but don't allow to accept invalid value then you can do this by writing some code in cmb_Validating event
private void cmb_Validating(object sender, CancelEventArgs e)
{
if (cmb.SelectedValue == null && cmb.Text != string.Empty)
e.Cancel=true;
}
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 8 years ago.
Improve this question
I've just got a stupid question. I have done research but I quite don't understand the explanations given as I'm a beginner in C#.
I have a class called things. The user now ca create a new object in this class by clicking a button. He can give some propertes for the object before, e.g. a description or a name.
This new object has to be created automatically then.
I want a list where all the object names are listed and when the user clicks on one of these, a label should show other properties of the object apart from the name, e.g. the description.
How shall I name these objects the user creates? And how can I make the label show the properties when the user just clicks on the list.
The program has no use really but I want to create it in order to learn how object orientation works.
I hope you understand my question.
Thanks in advance to everybody
Here is my assumption,
You have a Class named "SomeClass", When you click "New" Button, the new object should be created and it should be added to the list.
You can have a List<SomeClass> list = new List<SomeClass>() Which will act as a main list, and you can just use the single object as follows,
ON NEW OBJECT CLICK
SomeClass cls = new SomeClass();
cls.Description ="desc";
list.Add(cls)
Hope this is what you are expecting.