Name object automatically and show their properties when chosen [closed] - c#

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.

Related

User Controlls to Main Form 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 2 years ago.
Improve this question
I am using Windows Forms .NET C# for this project
I am making a school project for a cafe ordering system. And the coffee aspect is a simple custom controller that allows users to pick out a size of the coffee, how many sugars and creams they want. My issue is that I then have to take that user control inputs and store them in the main form list and inside a ListBox as a display of an order.
Does anyone know how to store user control inputs into a main form List<>?
The best way is to create a class to store info about order, let's call it class "Order". Each order will be represented by instance of this class (you pass your control's values as parameters to the constructor). You can store orders in the List<Order>.
To add it to the ListBox, you must override ToString() method:
public override string ToString(){ return "onfo to show" }
This method will show info about order from your class in the way you like.
P.s. for more specific help provide sample code of what you have tried since now.

C# ParentForm.ActiveControl.Name [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 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.

how do you create a custom table looks like this [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 8 years ago.
Improve this question
http://i.stack.imgur.com/Hi9Iz.jpg
i am trying to create a table in c# which should look like at example above and it should be usable in a loop. example: i have two variables called "text" and "author" big box belongs to text and right bottom box belongs to author. those variables available in a loop. what i want to is fill those boxes and make it compatible with loop. i managed to solve this with textboxes but i couldn't figure out how to make them stay under another one.
The easier way (that i am aware of) to do what you want is with an usercontrols and a flowLayoutPanel so we do it as follow
Create an UserControl
create it with panels or textBox in the way you want your table to be, i did like so
Create a flowLayoutPanel
put it where you like it to be and set those properties
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flowLayoutPanel1.WrapContents = false;
add as much table like UserControl you want in it the result should be as follow

C# Windows Form - access code [closed]

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 8 years ago.
Improve this question
I need to know where I can access the basic code, for example a "NumericUpDown" Element.
What I want to do:
Add Code to my NumericUpDown Element, for example:
Set the "Maximum"-Value to a variable embedded inside my Formclass code.
The Reason why I cant to it right now:
I just can access the NumericUpDown Element just in the Design View right now. There I can Input a value, but can't set it to the amount stored in a variable.
I just know, that If I double click the field, I get a "ValueChanged" Method into my code. But what I need to know: How can I access the "basic" Code of the NumericUpDown Element, where I could set the "Maximum"-Property?
I'm relatively new to programming. And I'm quite overwhelmed with a lot of things... So I COULD google for the problem but it would just take me way to much time.
Since I guess it's an easy answer for you guys, I post it here.
Thanks a lot!
You can access the Control's objects attributes by it's name.
For example:
NumericUpDown1 <- It's the name of your Control
In your C# code you can access all of it's attribtes and methods by puttin a period after it's name:
NumericUpDown1.Maximun = 100;
NumericUpDown1.Width = 250;
NumericUpDown1.Height = 10;
etc. You can serach it by "Control Properties" in google. Luck and effort! :P Remember to try and search a bit before asking. Don't wait for others to make your job. Luck! ^.^
You can access source code of components, but it won't help you. every component has interface and you can use it's interface to interact with it. Also you can override some methods of component to change their behavior.

Why does C# allow creating an object with the same reference? [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
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.

Categories