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.
Related
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 have a ComboBox control with the DropDownStyle properties set to DropDownList. I want to replace the list of items with some new items at some points in the form but it concatenates the new items with the old items. How can I delete the old items and place new items in the combo box?
I am trying something like that:
this.selectAttribute.Items.AddRange(new object[] {
"Airport_Name", //New items
"City",
"Country"});
You could try clearing the items first:
this.selectAttribute.Items.Clear();
Use the .clear() functionality:
this.selectAttribute.Items.clear()
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 5 years ago.
Improve this question
I have a MySQL Datatable with 3 columns : Name, X, Y
Let's say for now there's these values :
Basically I have a timer which loops through this Datatable and adds a new Button with Name, X, Y as it's location.
If I add a new row in my datatable, a new button will be created in the next timer's Tick event. Now how can I implement something to remove a button on the form which is not in the database anymore ?
Remember the list of buttons placed on the form. Then compare the list from the database and the list of buttons placed with Except.
Something like that:
IEnumerable<string> formButtons = ...;
IEnumerable<string> dbButtons = ...;
IEnumerable<string> buttonsToRemove = formButtons.Except(dbButtons);
buttonsToRemove now contains the buttons which are on the form, but not in the database anymore.
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)
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
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 my current project I want to implement a checkbox that, if checked, replaces all strings in labels, tabs, etc. currently being shown on a form with a different string.
For example, If checked, all instances of the word "car" would change to the word "truck" all through out the program.
I'd rather not go through a do a .replace on every single string in the code. I was wondering if there was some way to "intercept" output strings and replace them on the fly; something like making a string-listener. Any help would be appreciated!
I am no GUI/WinForms program but this would be my personal approach. Add all of these UI elements to a List<T> in the forms constructor. Then in the "replace box checked event handler" you can just iterate over the list applying the same change to all the items. It's by no means a perfect solution but it does mean you only have to statically reference each of the items once. After they're in the list you can operate on all of them very easily.