Find a label in WinForms which contains certain text? [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 8 years ago.
Improve this question
In C# Windows form application, how to find the label on the form which contains the text I'm looking for?
For example: I am trying to search a label whose Text property contains "25".

You can find it using linq this way:
var control = this.Controls.OfType<Control>().Where(x => x is Label && x.Text.Contains("25"));
or as #Sayse suggested just filter on Label type:
var Labelcontrol = this.Controls.OfType<Label>().Where(x => x.Text.Contains("25"));
Explanation:
If we want to fetch all controls of the form we have to do :
var AllControls = this.Controls.OfType<Control>();
and if we want to fetch only Controls of Type Label then:
var LabelControls = this.Controls.OfType<Label>();
Here this refers to current form of application.
UPDATE:
If you have label in nested controls, means inside some user control or some other control, then you need to check recrursively as in this SO post (How to get ALL child controls of a Windows Forms form of a specific type)

Related

That TextBox should retain the same value even after closing the 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 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.

how to add Buttons in datagrid view using C# .net [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 6 years ago.
Improve this question
How to add buttons in DataGridView using WinForms application in c# .NET?
In this picture, you can see that buttons are add in rows for delete, edit and active columns names. Like that way, I want to add buttons in DataGrid view in WinForms.
Right click in your datagridview.
In pop-up select Add Column.
In add column pop-up you can choose DataGridViewButtonColumn.
Just make a function which and call it on form load function
Public void AddButton()
{
//Add button
DataGridViewButtonColumn EditButton = new DataGridViewButtonColumn();
EditButton.UseColumnTextForButtonValue = true;
EditButton.DataPropertyName = "btnColumn";
EditButton.Text = "Button Text";
DataGridView_name.Columns.Add(EditButton);
}
If you want to add it manually from code

How to create images in a Foreach Loop [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 6 years ago.
Improve this question
I have a List of objects and i want to create a Foreach loop which create images on my MainWindow separated by 50 pixels for example. I don't know if I have to create them in the desgner itself or if there's a way to create then place the images the one below the other in a command.
For example i have:
List<string> URIS = new List<string>();
foreach (var i in URIS)
{
//New image in MainWindow with source i
}
Remember that I want a "list" of images in my Window so that every image is below the last one.
Look into the ItemsControl. It has an ItemsSource property that takes a list and lays out its items into a visual list. You can use the ItemTemplate property to control exactly what type of visual is created from each list item, including things like spacing.

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

Form will add a labels based on how many data are in the database in C# [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
Good day guys.
I am doing a some kind of a advertisement app that will scroll texts.
I am currently doing it using label.top and timer function in C#.
It is doing quite good as I just use it for testing purposes. But the question I want to raise here is that, is it possible that C# will add labels for me automatically based on how many data I have in my database?
Thanks in advanced!
Yes, it is possible to do so. If you have N items from your DB that you want to display, you can dynamically create the labels as per below pseudocode:
//your code to retrieve data from database
for(int i=0;i<N;i++)
{
Label l = new Label();
l.ID = "lbl" + i.ToString();
l.Visible = true;
l.Text = "Your text here";
this.Page.Controls.Add(l);
}
Note: The 'marquee' tag has been deprecated, and you should avoid using it where possible.

Categories