|
Hi my Friends
how can i convert text in the text box to the int value or somthing esle?
or in general how can chage datatypes text--> int int--->text or ...
Thans`s for Thire Regard .
|
|
|
|
|
you have two ways to do that:
first way is CASTING: e.g.
string str = "123";
int i = (int)str;
or using the following function
int i = Convert.ToInt(str);
string str = Convert.ToString(i);
hope that help...
|
|
|
|
|
int i = (int)str; won't compile and the function
Convert.ToInt()
doesn't exist. The Convert functions all have the number of bits in the name of the function for converting to ints (like Convert.ToInt32 ). Also, Convert.ToIntXX throws an exception if the string is formatted badly; alternatively int.TryParse will return a bool indicating success/failure.
|
|
|
|
|
|
It's possible to do this using the TryParse method. Here's a sample:
public int GetValue(string value)
{
int returnValue = 0;
if (!int.TryParse(value, out returnValue))
{
throw new ArgumentException("value");
}
return returnValue;
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Right, use Parse or TryParse, don't even bother with Convert.
|
|
|
|
|
I've noticed that the Dispose method's in the foo.Designer.cs file. Does that mean that as I port my app from the 1.1 to 3.5 framework that if I move the method into the new proper location I need to move the cleanup/shutdown code (thread termination) to a different location to keep it safe, and if so where?
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
AFAIK the code generator does not touch Dispose after it is first created. It is placed outside the autogenerated region.
The MSDN documentation gives this:
protected override void Dispose(bool disposing)
{
if (disposing)
{
}
base.Dispose(disposing);
}
I know that sometimes MS doesn't do what it says, but I think it's OK to believe them here.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I am adding images in imagelist also in listview as "thumbnails" like that..
listView1.Items.Clear();
this.listView1.View = View.LargeIcon;
this.imageList1.ImageSize = new Size(60, 60);
this.listView1.LargeImageList = this.imageList1;
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
Bitmap slika = new Bitmap(open.FileName);
velikost(slika);
FileInfo fi = new FileInfo(open.FileName);
imena[i] = fi.Name;
this.imageList1.Images.Add(Image.FromFile(open.FileName));
i++;
}
When i click on image thumbnail in listview i do this:
private void listView1_SelectedIndexChanged_1(object sender, EventArgs e)
{
int index = 0;
if (this.listView1.SelectedItems.Count > 0)
index = this.listView1.SelectedIndices[0];
Bitmap nova = new Bitmap(imageList2.Images[index]);
picture.Image = nova;
}
But the size is 60,60 as i specified before.If i want to put height and weight argument in Bitmap..it resizes from 60,60 and normally at size 500,500 is blurrred and f*****.. Can you help me out plz?
|
|
|
|
|
Keep two image lists, one for the the smaller thumbnails and one for the full size images.
|
|
|
|
|
This is my code for deleting multiple items from listview.. how can now i delete with same function also images from imagelist with multiple selected indexes..
private void button2_Click(object sender, EventArgs e)
{
foreach (System.Windows.Forms.ListViewItem eachItem in
this.listView1.SelectedItems)
{
this.listView1.Items.Remove(eachItem);
}
}
|
|
|
|
|
Do the indices of the items in listView1.Items correspond to the indices of the items in imageList1 ? They should, so something like this should work: imageList1.Images.RemoveAt(eachItem.Index);
If they don't then I'd store either the index or the key of the image from imageList1 in the Tag property of your ListViewItem s, that way you know how to find the image later on.
|
|
|
|
|
How shold this line look like:
foreach (System.Windows.Forms.ListViewItem eachItem in
this.listView1.SelectedItems)
One more thing...why everytime i call function the last text in richbox is still in...and it is duplicating..why? The code is here:
private void podatki()
{
string prazno = "";
rich.AppendText(prazno);
int index = 0;
if (this.listView1.SelectedItems.Count > 0)
index = this.listView1.SelectedIndices[0];
FileInfo fi = new FileInfo(poti[index]);
Bitmap nova = new Bitmap(poti[index]);
string dolzina;
string visina;
string ime;
string format;
string velikost;
string datum;
dolzina = nova.Width.ToString();
visina = nova.Height.ToString();
ime = fi.Name;
datum = fi.CreationTime.ToLongTimeString();
velikost = fi.Length.ToString();
dolzina = "Širina: " + dolzina;
visina = "Višina: " + visina;
ime = "Ime: " + ime;
velikost ="Velikost: "+ velikost + "Bytes";
string skupaj = ime + "\n" + dolzina + "\n" + visina + "\n" + velikost + "\n";
rich.AppendText(skupaj);
}
|
|
|
|
|
foreach looks fine
your other question isn't clear. Are you asking why it isn't replacing the text in the text box? use rich.Text = skupaj; to do that.
|
|
|
|
|
richbox works fine now.. how should look in this forreach code for getting indexes for imagelist..can someone edit it plz
private void button2_Click(object sender, EventArgs e)
{
foreach (System.Windows.Forms.ListViewItem eachItem in
this.listView1.SelectedItems)
{
this.listView1.Items.Remove(eachItem);
this.imageList1.Images.RemoveAt(-->INDEX?<--);
}
|
|
|
|
|
Asked and answered.
I think I've helped you enough for one day. It's time for you to help yourself.
|
|
|
|
|
eachitem.index doesn't work..tryed also eachitem.imageindex..also error..about that tag option idk how to use it..
|
|
|
|
|
|
Good People,
Greetings.
I am trying to figure out which casting method I should use for my application.
1)
double average = (double)value;
or
2)
double average = value as double;
I thought that since objects of type "double" are not nullable; the cast would throw an exception if "as" returned null. What do you think?
Thanks for any advice or information you can provide.
Blitz
|
|
|
|
|
Surely this won't compile???
double average = value as double;
If value could be null, and you need a double you can do the following:
double = (double?)value ?? 0d;
Replacing 0 with your prefered default.
10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011
|
|
|
|
|
Neither. TryParse is a much better way to do this (and it works on types such as int, bool, etc).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
Should be a double coming in.
Thanks,
Blitz
|
|
|
|
|
Then why are you trying to cast at all?
|
|
|
|
|
Attaching to a service "Unable to attach to the process. A debugger is already attached"...
how do i know which debugger is assigned
|
|
|
|