How do I get a label in a form to display the values of a property
In my C# windows form I have 2 forms. I would like to display a collection of strings in a label on a form. When I debug I show the 2 elements in my array but they are not showing in the label I am passing it to. When I hover of toString the data is there but how to I pass it to sender so it will display in the label control I have on my form?
In the snippet of code below to data is in toString but how do I get it from there down to sender.ToString????
public AccountReport_cs(Func<string> toString)
this.toString = toString;
private void AccountReport_cs_Load(object sender, EventArgs e)
label1.Text = sender.ToString();
This is another piece of the code that will open form2 where the information should be displayed.
private void reportButton2_Start(object sender, EventArgs e)
AccountReport_cs accountReport = new AccountReport_cs(allTransactions.ToString);
accountReport.ShowDialog();
Here is the last piece of code and this will show how the data gets to EndOfMonth.
public class Transaction
public string EndOfMonth get; set;
public override List<Transaction> closeMonth()
var transactions = new List<Transaction>();
var endString = new Transaction();
endString.EndOfMonth = reportString;
transactions.Add(endString);
return transactions;
c#
add a comment |
In my C# windows form I have 2 forms. I would like to display a collection of strings in a label on a form. When I debug I show the 2 elements in my array but they are not showing in the label I am passing it to. When I hover of toString the data is there but how to I pass it to sender so it will display in the label control I have on my form?
In the snippet of code below to data is in toString but how do I get it from there down to sender.ToString????
public AccountReport_cs(Func<string> toString)
this.toString = toString;
private void AccountReport_cs_Load(object sender, EventArgs e)
label1.Text = sender.ToString();
This is another piece of the code that will open form2 where the information should be displayed.
private void reportButton2_Start(object sender, EventArgs e)
AccountReport_cs accountReport = new AccountReport_cs(allTransactions.ToString);
accountReport.ShowDialog();
Here is the last piece of code and this will show how the data gets to EndOfMonth.
public class Transaction
public string EndOfMonth get; set;
public override List<Transaction> closeMonth()
var transactions = new List<Transaction>();
var endString = new Transaction();
endString.EndOfMonth = reportString;
transactions.Add(endString);
return transactions;
c#
add a comment |
In my C# windows form I have 2 forms. I would like to display a collection of strings in a label on a form. When I debug I show the 2 elements in my array but they are not showing in the label I am passing it to. When I hover of toString the data is there but how to I pass it to sender so it will display in the label control I have on my form?
In the snippet of code below to data is in toString but how do I get it from there down to sender.ToString????
public AccountReport_cs(Func<string> toString)
this.toString = toString;
private void AccountReport_cs_Load(object sender, EventArgs e)
label1.Text = sender.ToString();
This is another piece of the code that will open form2 where the information should be displayed.
private void reportButton2_Start(object sender, EventArgs e)
AccountReport_cs accountReport = new AccountReport_cs(allTransactions.ToString);
accountReport.ShowDialog();
Here is the last piece of code and this will show how the data gets to EndOfMonth.
public class Transaction
public string EndOfMonth get; set;
public override List<Transaction> closeMonth()
var transactions = new List<Transaction>();
var endString = new Transaction();
endString.EndOfMonth = reportString;
transactions.Add(endString);
return transactions;
c#
In my C# windows form I have 2 forms. I would like to display a collection of strings in a label on a form. When I debug I show the 2 elements in my array but they are not showing in the label I am passing it to. When I hover of toString the data is there but how to I pass it to sender so it will display in the label control I have on my form?
In the snippet of code below to data is in toString but how do I get it from there down to sender.ToString????
public AccountReport_cs(Func<string> toString)
this.toString = toString;
private void AccountReport_cs_Load(object sender, EventArgs e)
label1.Text = sender.ToString();
This is another piece of the code that will open form2 where the information should be displayed.
private void reportButton2_Start(object sender, EventArgs e)
AccountReport_cs accountReport = new AccountReport_cs(allTransactions.ToString);
accountReport.ShowDialog();
Here is the last piece of code and this will show how the data gets to EndOfMonth.
public class Transaction
public string EndOfMonth get; set;
public override List<Transaction> closeMonth()
var transactions = new List<Transaction>();
var endString = new Transaction();
endString.EndOfMonth = reportString;
transactions.Add(endString);
return transactions;
c#
c#
edited Nov 11 at 17:50
asked Nov 11 at 17:38
Demond
545
545
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you need to send information between forms, the best thing you can do is create a property in the target form and assign the value you want to send before displaying the form; thus you will not need to change the default constructor of the form.
// Destiny form
public partial class FormDestiny : Form
// Property for receive data from other forms, you decide the datatype
public string ExternalData get; set;
public FormDestiny()
InitializeComponent();
// Set external data after InitializeComponent()
this.MyLabel.Text = ExternalData;
// Source form. Here, prepare all data to send to destiny form
public partial class FormSource : Form
public FormSource()
InitializeComponent();
private void SenderButton_Click(object sender, EventArgs e)
// Instance of destiny form
FormDestiny destinyForm = new FormDestiny();
destinyForm.ExternalData = PrepareExternalData("someValueIfNeeded");
destinyForm.ShowDialog();
// Your business logic here
private string PrepareExternalData(string myparameters)
string result = "";
// Some beautiful and complex code...
return result;
Thank you sir I will give this a try.
– Demond
Nov 11 at 18:37
I have tried your suggestion but I am unsure how to get the data out of the list (allTransaction) and pass it to the method PrepareExternalData
– Demond
Nov 12 at 19:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251418%2fhow-do-i-get-a-label-in-a-form-to-display-the-values-of-a-property%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you need to send information between forms, the best thing you can do is create a property in the target form and assign the value you want to send before displaying the form; thus you will not need to change the default constructor of the form.
// Destiny form
public partial class FormDestiny : Form
// Property for receive data from other forms, you decide the datatype
public string ExternalData get; set;
public FormDestiny()
InitializeComponent();
// Set external data after InitializeComponent()
this.MyLabel.Text = ExternalData;
// Source form. Here, prepare all data to send to destiny form
public partial class FormSource : Form
public FormSource()
InitializeComponent();
private void SenderButton_Click(object sender, EventArgs e)
// Instance of destiny form
FormDestiny destinyForm = new FormDestiny();
destinyForm.ExternalData = PrepareExternalData("someValueIfNeeded");
destinyForm.ShowDialog();
// Your business logic here
private string PrepareExternalData(string myparameters)
string result = "";
// Some beautiful and complex code...
return result;
Thank you sir I will give this a try.
– Demond
Nov 11 at 18:37
I have tried your suggestion but I am unsure how to get the data out of the list (allTransaction) and pass it to the method PrepareExternalData
– Demond
Nov 12 at 19:42
add a comment |
If you need to send information between forms, the best thing you can do is create a property in the target form and assign the value you want to send before displaying the form; thus you will not need to change the default constructor of the form.
// Destiny form
public partial class FormDestiny : Form
// Property for receive data from other forms, you decide the datatype
public string ExternalData get; set;
public FormDestiny()
InitializeComponent();
// Set external data after InitializeComponent()
this.MyLabel.Text = ExternalData;
// Source form. Here, prepare all data to send to destiny form
public partial class FormSource : Form
public FormSource()
InitializeComponent();
private void SenderButton_Click(object sender, EventArgs e)
// Instance of destiny form
FormDestiny destinyForm = new FormDestiny();
destinyForm.ExternalData = PrepareExternalData("someValueIfNeeded");
destinyForm.ShowDialog();
// Your business logic here
private string PrepareExternalData(string myparameters)
string result = "";
// Some beautiful and complex code...
return result;
Thank you sir I will give this a try.
– Demond
Nov 11 at 18:37
I have tried your suggestion but I am unsure how to get the data out of the list (allTransaction) and pass it to the method PrepareExternalData
– Demond
Nov 12 at 19:42
add a comment |
If you need to send information between forms, the best thing you can do is create a property in the target form and assign the value you want to send before displaying the form; thus you will not need to change the default constructor of the form.
// Destiny form
public partial class FormDestiny : Form
// Property for receive data from other forms, you decide the datatype
public string ExternalData get; set;
public FormDestiny()
InitializeComponent();
// Set external data after InitializeComponent()
this.MyLabel.Text = ExternalData;
// Source form. Here, prepare all data to send to destiny form
public partial class FormSource : Form
public FormSource()
InitializeComponent();
private void SenderButton_Click(object sender, EventArgs e)
// Instance of destiny form
FormDestiny destinyForm = new FormDestiny();
destinyForm.ExternalData = PrepareExternalData("someValueIfNeeded");
destinyForm.ShowDialog();
// Your business logic here
private string PrepareExternalData(string myparameters)
string result = "";
// Some beautiful and complex code...
return result;
If you need to send information between forms, the best thing you can do is create a property in the target form and assign the value you want to send before displaying the form; thus you will not need to change the default constructor of the form.
// Destiny form
public partial class FormDestiny : Form
// Property for receive data from other forms, you decide the datatype
public string ExternalData get; set;
public FormDestiny()
InitializeComponent();
// Set external data after InitializeComponent()
this.MyLabel.Text = ExternalData;
// Source form. Here, prepare all data to send to destiny form
public partial class FormSource : Form
public FormSource()
InitializeComponent();
private void SenderButton_Click(object sender, EventArgs e)
// Instance of destiny form
FormDestiny destinyForm = new FormDestiny();
destinyForm.ExternalData = PrepareExternalData("someValueIfNeeded");
destinyForm.ShowDialog();
// Your business logic here
private string PrepareExternalData(string myparameters)
string result = "";
// Some beautiful and complex code...
return result;
answered Nov 11 at 18:08
batressc
8061221
8061221
Thank you sir I will give this a try.
– Demond
Nov 11 at 18:37
I have tried your suggestion but I am unsure how to get the data out of the list (allTransaction) and pass it to the method PrepareExternalData
– Demond
Nov 12 at 19:42
add a comment |
Thank you sir I will give this a try.
– Demond
Nov 11 at 18:37
I have tried your suggestion but I am unsure how to get the data out of the list (allTransaction) and pass it to the method PrepareExternalData
– Demond
Nov 12 at 19:42
Thank you sir I will give this a try.
– Demond
Nov 11 at 18:37
Thank you sir I will give this a try.
– Demond
Nov 11 at 18:37
I have tried your suggestion but I am unsure how to get the data out of the list (allTransaction) and pass it to the method PrepareExternalData
– Demond
Nov 12 at 19:42
I have tried your suggestion but I am unsure how to get the data out of the list (allTransaction) and pass it to the method PrepareExternalData
– Demond
Nov 12 at 19:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251418%2fhow-do-i-get-a-label-in-a-form-to-display-the-values-of-a-property%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown