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 4 years ago.
Improve this question
I have a c# FlowLayoutPanel container to which I am adding a number of labels with Label.Text set to different values ie Label.Text = "ABCDEF".
What is the best way to search all the labels in the container to find the
a particular label with the Text = "ABCDEF"?
Thank You
You can find the label with text as follow:
foreach (var item in flowLayoutPanel1.Controls)
{
if (item is Label)
{
if ("ASDF" == ((Label)item).Text)
{
MessageBox.Show("found it");
}
}
}
Also if you know your component's name, you can search it as below:
foreach (var item in flowLayoutPanel1.Controls.Find("label1", true))
{
if ("ASDF" == ((Label) item).Text)
{
MessageBox.Show("found it");
}
}
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 3 years ago.
Improve this question
I was following this article, but Office.DocumentProperties throw error that Office does not have DocumentProperties defined.
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
Microsoft.Office.Core.DocumentProperties properties;
var activeDocument = Globals.ThisDocument.Application.ActiveDocument;
properties = (Microsoft.Office.Core.DocumentProperties)activeDocument.CustomDocumentProperties;
MessageBox.Show(JsonConvert.SerializeObject(properties));
}
The How to: Read from and write to document properties article explains how to read from and write to Document Properties. The following code works like a charm on my PC:
Word.Document doc = WordApp.ActiveDocument as Word.Document;
Office.DocumentProperties properties = doc.CustomDocumentProperties as Office.DocumentProperties;
for (int i = 0; i < properties.Count; i++)
{
Office.DocumentProperty property = properties[i];
if(property!=null)
{
System.Windows.Forms.MessageBox.Show(property.Name);
Marshal.ReleaseComObject(property);
}
}
if (properties != null) Marshal.ReleaseComObject(properties);
if (doc != null) Marshal.ReleaseComObject(doc);
Sometimes, you need to use a late-binding technology to avoid exceptions:
dynamic properties = doc.CustomDocumentProperties;
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 couldn't find any info , about creating a spell checker which reads a word from .txt file.
I will be glad if you can help with anything.
To solve your problem you can use the NHunspell library.
Your check method in this case is very simple and looks like this:
bool CheckSpell(string word)
{
using (Hunspell hunspell = new Hunspell("en_GB.aff", "en_GB.dic"))
{
return hunspell.Spell(word);
}
}
You can find dictionaries on this site.
Also you can use SpellCheck class:
bool CheckSpell(string word)
{
TextBox tb = new TextBox();
tb.Text = word;
tb.SpellCheck.IsEnabled = true;
int index = tb.GetNextSpellingErrorCharacterIndex(0, LogicalDirection.Forward);
if (index == -1)
return true;
else
return false;
}
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 6 years ago.
Improve this question
I need help for item add in the stackpanel.
My item name is "kanal" its wp8 imagebutton item.
Its my codes
public mainpage()
{
InitializeComponent();
foreach (var kanal in MainPage.kanalllarstatik)
{
mystackpanel.Children.Add(kanal);
}
}
I need add 130x130 pixel 3 button items per line like this:
Stackpanel only put one element per line so you need to put a horizontal stackpanel (in each line) and then add to it the three elements.
If you want a 130x130 control, you should use:
kanel.Height=130;
kanal.Width =130;
Code example
Test Data
List<Button> buttons = new List<Button>();
for (int i = 0; i < 16; i++)
{
buttons.Add(new Button
{
Height = 130,
Width = 130,
Content = new TextBlock
{
Text = i.ToString()
}
});
}
Algorithm
StackPanel horizontalStackPanel = new StackPanel
{
Orientation = Orientation.Horizontal
};
foreach (Button button in buttons)
{
horizontalStackPanel.Children.Add(button);
if (horizontalStackPanel.Children.Count == 3) //new line
{
myStackPanel.Children.Add(horizontalStackPanel);
horizontalStackPanel = new StackPanel
{
Orientation = Orientation.Horizontal
};
}
}
myStackPanel.Children.Add(horizontalStackPanel);
XAML
<StackPanel x:Name="myStackPanel"></StackPanel>
Result
I hope that this can help you.
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
This is for my button named Edit, when you have an entry into the shopping basket and click on the entry and click Edit it opens up a new window which allows you to edit the entries, product name, quantity or price. This is what I have and it compiles and runs fine but is there an easier way to write it?
private void btn_Edit_Click(object sender, EventArgs e)
{
if (lst_Results.SelectedIndex >= 0)
{
// Want to edit the value of the Item
Edit editbutton = new Edit();
editbutton.NameOfItem =
basket.Items[lst_Results.SelectedIndex].ItemName;
editbutton.Quantity = basket.Items[lst_Results.SelectedIndex].Quantity;
editbutton.ReplacementValue =
basket.Items[lst_Results.SelectedIndex].Price;
if (editbutton.ShowDialog() == DialogResult.OK)
{
basket.UpdateReplacementValue(basket.Items[lst_Results.SelectedIndex].ItemName, editbutton.Quantity, editbutton.ReplacementValue);
RenderLibrary();
}
}
}
At least, you can write out the repeating array access.
// Want to edit the value of the Item
Edit editbutton = new Edit();
var item = basket.Items[lst_Results.SelectedIndex];
editbutton.NameOfItem = item.ItemName;
editbutton.Quantity = item.Quantity;
editbutton.ReplacementValue = item.Price;
if (editbutton.ShowDialog() == DialogResult.OK)
{
basket.UpdateReplacementValue(item.ItemName, editbutton.Quantity, editbutton.ReplacementValue);
RenderLibrary();
}
Also, you might want to just pass the object as parameter to the control, and edit it there using data binding.
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
How can I make set a Panel objects visibility to false if the text in a TextBox is "CLOSED"?
My current code is:
if (Session["txtALTN1"] != "Closed")
{
pnlALTN1.Visible = false;
}
else
{
pnlALTN1.Visible = true;
}
Controls are not placed in the session, if txtALTN1 is your TextBox use this instead:
if (txtALTN1.Text != "Closed")
{
pnlALTN1.Visible = false;
}
else
{
pnlALTN1.Visible = true;
}
or simply:
pnlALTN1.Visible = (txtALTN1.Text == "Closed");