|
There is only problem which is about the input string was not in the correct format. I use a textbox1 which is for me to type a number in the string format as I store the string in a variable knn. Then I try to convert it to Int32 and store it in another variable wup. However, after I tried to run the program, the error of input string popped up and I really run out of idea on what to do next.
public void find() {
int a = 0;
int h = 0;
Int32 t = 1;
int f = 130;
int d = 230;
string knn;
Int32 wup = 0;
knn = textBox1.Text;
wup = Convert.ToInt32(knn);
int [,] yes=new int[10,10];
for(a=0 ;a<=7 ; a++) {
for (h = 0; h <= 7; h++)
{
if (a == 0)
{
if( t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 0 && h == 7)
{
f = 130;
d = d + 20;
}
if (a == 1)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 1 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 2)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index"+ Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
textBox4.Text = textBox4.Text + Environment.NewLine + "y= " + (Convert.ToString(h));
}
f = f + 20;
}
if (a == 2 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 3)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text = "Index" + Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
}
f = f + 20;
}
if (a == 3 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 4)
{
if (t == wup){
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 4 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 5)
{
if (t == wup){
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index"+ Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
}
f = f + 20;
}
yes[a, h] = t;
t++;
if (a == 5 && h == 7)
{
break;
}
}
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
}
}
modified 25-Jun-15 11:55am.
|
|
|
|
|
If you enter a none-integer value in your TextBox, Convert.ToInt32 is going to fail. In cases of parsing values, you really should use the appropriate TryParse instead, so you would expect this to be something like
int value;
if (!int.TryParse(myStringValue, out value))
{
return;
}
|
|
|
|
|
I am still unsure about what you commented. So I just need to insert this chunk into my code? In addition, int value represents which variable of mine? I am actually quite new to programming so please help me.
|
|
|
|
|
Remove the lines
knn = textBox1.Text;
wup = Convert.ToInt32(knn); and replace with
if (!int.TryParse(textBox1.Text, out wup))
{
MessageBox.Show("Please enter an integer value");
return;
}
Some other points ... instead of using
textBox2.Text = "Index = " + Convert.ToString(t); you can use the built-in ToString() method e.g.
textBox2.Text = "Index = " + t.ToString(); or possibly even better
textBox2.Text = String.Format("Index = {0}", t); There is more tidying up you could do but I'll leave it there
|
|
|
|
|
hi
Does anyone experienced in the text-to-speech in C# WinForm ?
Is it possible to get a clue or direction ?
thanks
|
|
|
|
|
Have you tried searching the articles[^] or even Google. They will give you a clue and an example you can work through.
The forums are for asking specific question or starting a discussion use the articles for research.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
goldsoft wrote: Is it possible to get a clue "MS Agent"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am trying to make and Android app with ASP.NET WebService. In WebService, if I want to return values from a single table I know what to do :
public DataTable GetUserDetails(string userName)
{
....
return userDetailsTable;
}
But I don't know what to do if I want to return values from different tables (a more complex data). Should I use
List<DataTable> or something else? If I use
List<DataTable> , how should I handle it in Android side? Thanks.
|
|
|
|
|
Returning things like DataTable is generally a bad idea, especially if your client needs to be lean and use minimal data resources. When you return a DataTable you get a lot of stuff returned, when you are normally just interested in the data.
What people normally do is define a class object that represents the bits of data you want to return. So if you want to return a Customer table you'll create a Customer class with properties like ID, FirstName, Surname etc, then in your web method you create a List<customer> and for each row of your datatable you'll create a Custom object, populate the properties from the fields, add it to the List<customer> and then return the List. This will greatly reduce the amount of data sent to your app, and your app now just sees a simply collection with just the data it needs.
|
|
|
|
|
Thank you very much for your reply. Can you tell me how I should make Android could handle List< Customer >? A sample code would be great. Moreover is it a good idea to send List< Customer > and List< Order > at the same time?
Thanks a lot.
|
|
|
|
|
No idea TBH, this is a c# forum, I don't know anything about Android apps. Although you are return a List, .net will convert that to json so your Android app should see something like
[{ID:1, FirstName: "John", LastName: "Doe"}, {ID=2, FirstName: "Dave", LastName: "Smith"}]
whatever framework Android has for calling web services will know how to parse that.
|
|
|
|
|
How to store the result into a byte[] with this declaration:
private static T Get<T>(string resource, out string jsonResponse) where T : class
Thanks
|
|
|
|
|
Are you talking about the value in jsonResponse here, or the value from your return statement? If it's the jsonResponse, you can use
Encoding.ASCII.GetBytes(jsonResponse);
|
|
|
|
|
That's very helpful. Thanks very much.
|
|
|
|
|
I have developed win form application. I have MDI form and I have created many child forms. When I click ribbon control tab child forms rendering not properly. when it's showing some shaking and blurring appeared after its showing properly. It is take some time.
I have using TableLayout panel within form
|
|
|
|
|
Not enough information. We have no idea what you mean by "When I click ribbon control tab child forms rendering not properly "when it's showing some shaking and blurring appeared after its showing properly. It is take some time."
We also have no idea what you're code looks like and what its doing.
|
|
|
|
|
Hi,
Can any body help me for developing email solution for local network with mail server and own mail domain(mdccb.com) in C#
|
|
|
|
|
|
Hi,
This example retrieves a pdf document.
How can I save the data as a pdf file to disk?
Thanks
string jsonResponse ;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(string uri);
webRequest.Method = "GET";
webRequest.Accept = "application/pdf";
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
{
jsonResponse = reader.ReadToEnd();
}
}
|
|
|
|
|
You will receive the PDF in "plain binary", not JSON, so you can simply copy the stream contents into a file (-stream):
string uri = "some pdf uri";
string filename = "some filepath";
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
webRequest.Method = "GET";
webRequest.Accept = "application/pdf";
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
using (Stream responseStream = webResponse.GetResponseStream())
{
using (FileStream fileStream = File.Create(filename))
{
responseStream.CopyTo(fileStream);
}
}
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
Working around a puzzle slider game, using picturebox and tag properties. After the form has reshuffled the images, I set a function void IsWin() using if statement to check the arrangement upon completion and display an output. but after arranging the scrabbled images the message box in the if statement doesn't pop up.
I will be glad if some anyone can help me identify what i am doing wrong. Thank you
Code for the shuffled images
private void Form1_Load(object sender, EventArgs e)
{
Image p1 = pic1.Image;
string tag1 = pic1.Tag.ToString();
pic1.Tag = pic8.Tag;
pic8.Tag = tag1;
pic1.Tag = pic8.Tag;
pic1.Image = pic8.Image;
pic8.Image = p1;
Image p2 = pic4.Image;
string tag2 = pic4.Tag.ToString();
pic4.Tag = pic12.Tag;
pic12.Tag = tag2;
pic4.Image = pic12.Image;
pic12.Image = p2;
Image p3 = pic3.Image;
string tag3 = pic3.Tag.ToString();
pic3.Tag = pic10.Tag;
pic10.Tag = tag3;
pic3.Image = pic10.Image;
pic10.Image = p3;
Image p4 = pic2.Image;
string tag4 = pic2.Tag.ToString();
pic2.Tag = pic11.Tag;
pic11.Tag = tag4;
pic2.Image = pic11.Image;
pic11.Image = p4;
Image p5 = pic5.Image;
string tag5 = pic5.Tag.ToString();
pic5.Tag = pic13.Tag;
pic13.Tag = tag5;
pic5.Image = pic13.Image;
pic13.Image = p5;
Image p6 = pic6.Image;
string tag6 = pic6.Tag.ToString();
pic6.Tag = pic14.Tag;
pic14.Tag = tag6;
pic6.Image = pic14.Image;
pic14.Image = p6;
Image p7 = pic7.Image;
string tag7 = pic7.Tag.ToString();
pic7.Tag = pic16.Tag;
pic16.Tag = tag7;
pic7.Image = pic16.Image;
pic16.Image = p7;
}
code for the function Void IsWin()
public void IsWin()
{
if ((string)pic1.Tag == "1" && (string)pic2.Tag == "2" &&
(string)pic3.Tag == "3" && (string)pic4.Tag == "4" &&
(string)pic5.Tag == "5" && (string)pic6.Tag == "6" &&
(string)pic7.Tag == "7" && (string)pic8.Tag == "8" &&
((string)pic9.Tag == "9" && (string)pic10.Tag == "10" &&
(string)pic11.Tag == "11" && (string)pic12.Tag == "12" &&
(string)pic14.Tag == "14" && (string)pic13.Tag == "13" &&
(string)pic15.Tag == "15" && (string)pic16.Tag == "Blank"))
{
MessageBox.Show("You Win with " +move+" Moves.");
won.Play();
this.Close();
}
}
|
|
|
|
|
I assume your initialization code is faulty but I'm not quite sure because it's a bit unclear what you're actually trying to do.
1) For instance, what is your intention here?
Image p1 = pic1.Image;
string tag1 = pic1.Tag.ToString();
pic1.Tag = pic8.Tag;
pic8.Tag = tag1;
pic1.Tag = pic8.Tag;
pic1.Image = pic8.Image;
pic8.Image = p1;
2) Is pic1.Tag at that point already initialized?
3) Do some of the tiles have identical images?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
1. My intention here, is to swap the images from the beginning when that form is invoked. so image p1 which initialized by pic1.image. string conversation is applied
2. yes, pic1.tag is already initialized as 1
3. nope, all tiles have a different tag number.
will it be possible to schedule a skype setting so i can share screens and we could go through. Im a beginner , and want to cross this hurdle before stepping into another world.
Thanks for the help
|
|
|
|
|
Member 11470100 wrote: My intention here, is to swap the images Ah.. alright, I guess I could've seen that
You have a small mistake in that first "block" (and maybe also in others, please check):
Image p1 = pic1.Image;
string tag1 = pic1.Tag.ToString();
pic1.Tag = pic8.Tag;
pic8.Tag = tag1;
pic1.Tag = pic8.Tag;
pic1.Image = pic8.Image;
pic8.Image = p1;
The marked line is too many: You set pic1.Tag = pic8.Tag and pic8.Tag has been set to tag1 before, so both pic1.Tag and pic8.Tag are set to tag1 .
Suggestions: pic1.Tag is a string anyway, right? Then just either cast it to a string (to satisfy the compiler), like so:
string tag1 = (string)pic1.Tag;
..or declare tag1 as object. A String is an Object, so doing this doesn't actually change anything but clears up the code:
object tag1 = pic1.Tag;
For swapping you could use a generic method[^], which also clears up the code and explains automatically what your intention is:
public static class MyUtility
{
public static void Swap<T>(ref T left, ref T right)
{
T temp;
temp = left;
left = right;
right = temp;
}
}
Then the whole code from above would look like this:
MyUtility.Swap(ref pic1.Image, ref pic8.Image);
MyUtility.Swap(ref pic1.Tag, ref pic8.Tag);
Member 11470100 wrote: will it be possible to schedule a skype setting so i can share screens and we could go through We prefer to keep it in the forums here - if needed you could upload images to e.g. imgur.com and put the link into your message.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|