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
So I found this blog post
http://lostechies.com/gabrielschenker/2009/01/23/synchronizing-calls-to-the-ui-in-a-multi-threaded-application/
And I've spent the morning trying to learn from it.
It updates a single label with the "stock quote".
MessageBus.Register<QuoteMessage>(m => label1.Text = m.Symbol+":"+m.Quote.ToString("n2"));
I would like to update more than one label with just one message handler. Specifically I might want to change a different label depending on what is in the QuoteMessage object. Given the code below, I can only update the labels with a handler per label.
Doing
MessageBus.Register<QuoteMessage>(m => label1.Text = m.Symbol+":"+m.Quote.ToString("n2"));
MessageBus.Register<QuoteMessage>(m => label2.Text = m.Symbol + ":" + m.Quote.ToString("n2"));
MessageBus.Register<QuoteMessage>(m => label3.Text = m.Symbol + ":" + m.Quote.ToString("n2"));
MessageBus.Register<QuoteMessage>(m => label4.Text = m.Symbol + ":" + m.Quote.ToString("n2"));
just gets me 4 labels displaying the same thing.
I think what you are missing is that the handler can have logic in the delegate action. I would do something like this:
MessageBus.Register<QuoteMessage>(m => {
if (m.Symbol == "MSFT") {
label1.Text = m.Symbol+":"+m.Quote.ToString("n2");
label2.Text = m.Symbol+":"+m.Quote.ToString("n2");
}
else if (something) {
// Do something else
label3.Text = m.Symbol+":"+m.Quote.ToString("n2");
}
});
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 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");
}
}
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 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");
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I've loaded picture names into a data table on aspx, but is this the best way to put them on the page....
private void LoadPics()
{
Image1.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[0]["name"].ToString();
Label1.Text = MyClass.dtprop.Rows[0]["name"].ToString();
Image2.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[1]["name"].ToString();
Label2.Text = MyClass.dtprop.Rows[1]["name"].ToString();
Image3.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[2]["name"].ToString();
Label3.Text = MyClass.dtprop.Rows[2]["name"].ToString();
Image4.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[3]["name"].ToString();
Label4.Text = MyClass.dtprop.Rows[3]["name"].ToString();
Image5.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[4]["name"].ToString();
Label5.Text = MyClass.dtprop.Rows[4]["name"].ToString();
Image6.ImageUrl = #"~\Pictures\" + MyClass.dtprop.Rows[5]["name"].ToString();
Label6.Text = MyClass.dtprop.Rows[5]["name"].ToString();
}
you can try with this code, based on OfType operator linq
var controls = this.Controls.OfType<Image>();
foreach(var item in controls)
{
....
}
if you wish add them to page, you can use PlaceHolder control
Ph.Contols.Add(yourImage);
you set your PlaceHolder in the target page
<asp:PlaceHolder id ="Ph" runat="server"/>
link :http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.placeholder%28v=vs.80%29.aspx
link : http://msdn.microsoft.com/fr-fr/library/vstudio/bb360913.aspx
Another solution : you can also use GridView control, bind this control on your DataTable and define template field
...
<asp:TemplateField>
<ItemTemplate>
<asp:Image id="img" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
...