Message Box issues in C# - c#

MessageBox.Show ("About Developer"+ "Mandelbrot by Milan." + Environment.NewLine +
"Email: xyz#abc.com" + Environment.NewLine +
"Contact No: +977123456789" + Environment.NewLine);
I want About Developer as title. I searched but I didn't get suitable solution to my problem.

There are a bunch of overloads on MessageBox.Show. The one you want is the one where you call it with 2 strings like this:
MessageBox.Show ("Mandelbrot by Milan." + Environment.NewLine +
"Email: xyz#abc.com" + Environment.NewLine +
"Contact No: +977123456789" + Environment.NewLine,
"About Developer");

Related

Ident Tabs for Multiple New Line String Variable in Net Core

How do I ident a set of lines when writing to a file, with a tabs? I need to go through each line in the variable and create 8 spaces or two tabs for each line, when writing to the new file.
If the string was one line, it would be easy, with " " + test, however this has multiple lines.
public static string testLine=
"Line1" + Environment.NewLine +
"Line2" + Environment.NewLine +
"Line3" + Environment.NewLine +
"Line4" + Environment.NewLine +
using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, true))
{
file.WriteLine(testLine);
String is composed of new line, line breaks enters, etc .
Is there any Microsoft Ident function library to support this?
Needs to handle multiple string variables in the future.
All you need to do is prefix the string with whitespace or a tab and replace all occurences off newlines with a newline and a suitable whitespace:
testLine = " " + testLine.Replace( Environment.NewLine, Environment.NewLine + " " );
You can explicitly handle an empty string to avoid indenting nothing:
testLine = String.IsNullOrEmpty(testLine) ? testLine : " " + testLine.Replace( Environment.NewLine, Environment.NewLine + " " );
Substitute "\t" for " " to insert a tab character.

Output showing System.Windows.Form.Label after every word

I am having a problem where the user enters his inputs into a text box (like a name). If the name is Jim Bob it will output like Jim System.Windows.Form.Label Bob System.Windows.Form.Label. I searched the properties tab and I am following along from the book but they do not have the same problem I have. I added some code below but I don't think it has anything to do with the problem.
string output;
output = textBoxPrefT.Text + ". " + textBoxFirstN + " " + textBoxMiddleN + " " + textBoxLastN;
labelOutput.Text = output;
You have to include .Text for all textboxes so it should look like this
string output;
output = textBoxPrefT.Text + ". " + textBoxFirstN.Text + " " + textBoxMiddleN.Text + " " + textBoxLastN.Text;
labelOutput.Text = output;

Conditional MessageBoxes

I'm currently making a script to display particular MessageBoxes if different conditions are fulfilled. I have 8 conditions to check for and each of them have to display different MessageBoxes if they are "0" or "1".
An shortened example of my code is as follows:
// Similar if(y[1] == "1") statements above with similar Messages but without the corresponding fruit(s)
if (y[2] == "1")
{ MessageBox.Show("Multiple goods required! Please get the following
items off the shelves" + Environment.NewLine +
"1. Apple" + Environment.NewLine + "2. Pear" +
Environment.NewLine + "3. Orange");
}
else if (y[2] == "0")
{ MessageBox.Show("Multiple goods required! Please get the following
items off the shelves" + Environment.NewLine +
"1. Apple" + Environment.NewLine + "2. Pear");
}
My knowledge of C# is quite basic, but I'm willing to learn! Please help!
I would make messages conditionally, and write the code for showing the message box once:
string msg = "Multiple goods required! Please get the following items off the shelves";
if(y[2] == "0" || y[2] == "1")
{
msg += Environment.NewLine + "1. Apple"
+ Environment.NewLine + "2. Pear";
if (y[2] == "1")
msg += Environment.NewLine + "3. Orange";
MessageBox.Show(msg);
}
I just made the above to be equivalent to your code, otherwise I think it could be written much better.
Also consider using String.Format and StringBuilder for creating the message, instead of concatenating small strings.
if your question is how to display the messageboxes easier it would be this way :
for(int i =0;i<y.length;i++){
if(y[i] == 0){
MessageBox.Show("Multiple goods required! Please get the following
items off the shelves" + Environment.NewLine +
"1. Apple" + Environment.NewLine + "2. Pear");
}
else if(y[i] == 1){
MessageBox.Show("Multiple goods required! Please get the following
items off the shelves" + Environment.NewLine +
"1. Apple" + Environment.NewLine + "2. Pear" +
Environment.NewLine + "3. Orange");
}
}
if this was not your question let me know i will come back and try to help

Get only name from Save File Dialog

How do I get file name only by using Save File Dialog?
MessageBox.Show("File was created with name: " + SOME CODE HERE +
Environment.NewLine + Environment.NewLine +
"You can find it at: " + Environment.NewLine + sfdNewFile.FileName);
See
System.IO.Path.GetFileName;
You can call it with the parameter sfdNewFile.FileName
Use:
System.IO.Path.GetFileName(sfdNewFile.FileName);
Example:
MessageBox.Show("File was created with name: " + SOME CODE HERE +
Environment.NewLine + Environment.NewLine +
"You can find it at: " + Environment.NewLine + System.IO.Path.GetFileName(sfdNewFile.FileName));

Getting values of all controls

i am trying to get the values of my controls like this:
function ConfirmWithUser()
{
var nodeText = '';
$('.mytreeview input[#type=checkbox]:checked').each(function() {
nodeText += $(this).next('a').text() + '\r';
});
var confirmationMessage;
confirmationMessage = "Please review the data before submitting:" + "\r"
+ "Sample Received Date: " + document.getElementById(received_dateTextbox).Value + "\r"
+ "Site of Ocurrence: " + document.getElementById(site_of_occurrenceTextBox).Value + "\r"
+ "Occurrence Date: " + document.getElementById(occurrence_dateTextBox).Value + "\r"
+ "Report Date: " + document.getElementById(report_byTextBox).Value + "\r"
+ "Specimen ID: " + document.getElementById(spec_idTextBox).Value + "\r"
+ "Batch ID: " + document.getElementById(batch_idTextBox).Value + "\r\n"
+ "Report Initiated By: " + document.getElementById(report_byTextBox).Value + "\r\n"
+ "Problem Identified By: " + $("input[#name=RadioButtonList1]:checked").val() + "\r\n"
+ "Problem List: " + nodeText;
HiddenFieldConfirmation.Value = confirmationMessage;
if (confirm(document.getElementById('HiddenFieldConfirmation').value) == true)
{ return true; }
else
{ return false; }
}
and the CONFIRM box is not firing at all! i do not get any pop up.
i tried to debug using firefox, and as soon as it go to this line:
confirmationMessage = "Please review the data before submitting:" + "\r"
+ "Sample Received Date: " + document.getElementById(re.......
it escapes out of the function
what am i doing wrong? how can i get the values of all the controls?
You need to use a lowercase "v" for value and quote your element ids. Eg:
document.getElementById("received_dateTextbox").value
Since it appears you are already using jQuery, you can make your code a little more concise. So document.getElementById("received_dateTextbox").value becomes:
$("#received_dateTextbox").val()
There is no variable named spec_idTextBox.
You probably want to pass a string literal.
Once you fix that, you need to use .value in lowercase
If you are using dynamic client ids, you have to render the ids inline or pass them to your function:
confirmationMessage = "Please review the data before submitting:" + "\r"
+ "Sample Received Date: " + document.getElementById('<% = received_dateTextbox.ClientID %>').value + "\r"
+ "Site of Ocurrence: " + document.getElementById('<% = site_of_occurrenceTextBox.ClientID %>').value + "\r"
+ "Occurrence Date: " + document.getElementById('<% = occurrence_dateTextBox.ClientID %>').value + "\r"
+ "Report Date: " + document.getElementById('<% = report_byTextBox.ClientID %>').value + "\r"
+ "Specimen ID: " + document.getElementById('<% = spec_idTextBox.ClientID %>').value + "\r"
+ "Batch ID: " + document.getElementById('<% = batch_idTextBox.ClientID %>').value + "\r\n"
+ "Report Initiated By: " + document.getElementById('<% = report_byTextBox.ClientID %>').value + "\r\n"
+ "Problem Identified By: " + $("input[#name=RadioButtonList1]:checked").val() + "\r\n"
+ "Problem List: " + nodeText;

Categories

Resources